How can I get Windows data like CPU usage, physical memory, and network utilization and bandwidth, similar to what I see in Task Manager? I'm using C++.
How can I get Windows data like CPU usage, etc.?
You can get CPU usage using the performance data. If you want data for only one (or a few processes) it may be simpler to call GetProcessTimes
every few seconds.
It's generally difficult to pin down exactly what physical memory usage even means. Until you do, trying to describe how to measure it is pretty pointless.
You can get some information about network utilization with GetIpStatistics
.
You can get the rated bandwidths of the installed network adapters with GetIfTable
.
Yes, I get cpu usage by GetProcessTimes, get memory usage by GlobalMemoryStatusEx –
Ossetic
Can you explain how to get bandwidth with those functions. I tried. But I can't. Thanks –
Ossetic
GetIfTable
gives you some MIB_IFROW
structures. Each has a dwSpeed
member, which is the rated speed of that interface. –
Assiut It seem that dwSpeed is const (when I download something, it's not change value). It's not bit race of internet connection (Local Area Connection interface) –
Ossetic
My computer have some interface: Locale Area Connection, VMware Network Adapter VMnet1, VMware Network Adapter VMnet8, a VPN TAP-Win32 Adapter. I disable all excluded Locale Area Connection -> in Task Manager I just see information for Locale Area Connection. But when I run the example in GetIfTable's link, I got 26 interfaces -> How to determine which interface is for current connection to internet? Thanks a lot. –
Ossetic
@aviit: dwSpeed tells you the theoretical maximum bandwidth of the adapter. dwInOctets tells you how many bytes you've received, and dwOutOctets how many you've sent (you sample the latter at intervals to find how much you've sent/received per second). dwType will tell you what sort of interface you're looking at (you mostly care about Ethernet, WANPPP, 802.11, WANPPP2 and possibly PPP, but almost certainly not tunnels, ATM, FDDI, loopback, etc.) –
Assiut
@aviit: I should probably add: if you can restrict your code to Windows Vista (or newer), you might want to use GetIfTable2 instead. A MIB_IF_ROW2 includes quite a bit more information, including a member to specifically tell you whether an interface represents actual hardware. –
Assiut
Look Performance Counters in msdn
I saw that. But, it too difficult to understand and use. :). Thanks –
Ossetic
Though that's just what Process Explorer (and likely Task Manager) uses, too. :) –
Tramline
© 2022 - 2024 — McMap. All rights reserved.