我正在制作一种系统监视器,我在努力获取网络吞吐量,它必须是我的系统监视器的模块。目前,我能够获得发送的数据包数量和接收的数量,但是我不确定它是否代表网络吞吐量,这是我的代码。
NetworkThroughput::NetworkThroughput( void ) {
void *oldp[1024];
size_t oldlen = sizeof(struct ipstat), newlen = 0;
void * newp = NULL;
std::stringstream ss;
sysctlbyname("net.inet.ip.stats", oldp, &oldlen, newp, newlen);
struct ipstat * g = (struct ipstat *) oldp;
ss << "IPS RECEIVED = " << std::to_string(g->ips_total) << std::endl << "IPS GENERATED = "
<< std::to_string(g->ips_localout) << std::endl;
_network = ss.str();
}
谢谢。