简体   繁体   English

如何获取每秒接收和发送的网络字节数对于C ++ for Windows中的进程(输入:进程ID或句柄)?

[英]How to get Received & Sent Network Bytes per second For a process (input: process id or handle) in C++ for Windows?

I need to get network information per process just like in resource monitor. 我需要像资源监视器一样获取每个进程的网络信息。 I need to find the received bytes/s & sent bytes/s. 我需要找到收到的字节/秒和发送的字节/秒。

I tried to get it using Win32_PerfRawData_PerfProc_Process class. 我试图使用Win32_PerfRawData_PerfProc_Process类来获取它。 But it gives IO, file bytes in addition to network details. 但除了网络细节之外,它还提供IO,文件字节。

I tried to get details using Win32_PerfRawData_Tcpip_NetworkInterface class. 我试图使用Win32_PerfRawData_Tcpip_NetworkInterface类获取详细信息。 But it gives details per Network interface. 但它提供了每个网络接口的详细信息

Then I tried to use GetTcpStatistics function. 然后我尝试使用GetTcpStatistics函数。 For that MIB_IPSTATS has been used. 因为已经使用了MIB_IPSTATS。 MIB_IPSTATS shows cumulative results for entire process. MIB_IPSTATS显示整个过程的累积结果。

  1. Are there any other MIB Structures to show these details per process manner? 是否有其他MIB结构可以按流程方式显示这些详细信息?
  2. how to get Bytes/s thing per process just like in resource monitor which is shown in Win32_PerfRawData_Tcpip_NetworkInterface as cumulated data for entire processes 如何在资源监视器中获取每个进程的字节/事物,在Win32_PerfRawData_Tcpip_NetworkInterface中显示为整个进程的累积数据
  3. Can I calculate Bytes/s using Win32_PerfRawData_PerfProc_Process class based on other values? 我可以根据其他值使用Win32_PerfRawData_PerfProc_Process类来计算字节数/秒吗?
  4. Are there any methods like GetProcessMemoryInfo ( this method is to get process memory) to get received and sent bytes per sec? 有没有像GetProcessMemoryInfo这样的方法(这个方法是获取进程内存)来获取每秒接收和发送的字节数?
  5. Are there any other methods to calculate them? 有没有其他方法来计算它们?

You might try looking into Performance Counters. 您可以尝试查看性能计数器。

https://msdn.microsoft.com/en-us/library/windows/desktop/aa373083(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/aa373083(v=vs.85).aspx

Here is a code project example of getting network speed using performance counters. 这是使用性能计数器获取网络速度的代码项目示例。 It is in c# but you should be able to translate to c++. 它在c#中,但您应该能够转换为c ++。

http://www.codeproject.com/Articles/6259/Monitoring-network-speed ' http://www.codeproject.com/Articles/6259/Monitoring-network-speed '

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM