Reputation: 3888
Is there an easy way (via a script perhaps) to get the cumulative bytes sent and received from a NIC on Windows Server 2008?
For example, the NIC currently shows around 18 MB of sent data and 765 MB of received data.
Since my server provider does not provide an easy way to see the monthly bandwidth usage, getting the NIC data seems to be the most reliable one.
I know I can use PRTG to get the current usage data via SNMP, but it will only be an average since the sensor checks every 60 seconds.
Upvotes: 2
Views: 10161
Reputation: 767
Just a brief note:
The following works perfectly for me - a heads up that the number wraps negative and you will need to build in some logic for that. I'm operating in a mixed environment and do not have PowerShell available on everything, so my solution is to use WMIC:
wmic Win32_PerfRawData_Tcpip_NetworkInterface Get BytesReceivedPersec,BytesSentPersec,BytesTotalPersec
Upvotes: 0
Reputation:
In PowerShell (CTP2v3), the commands below will help. (I have three interfaces). However, once the NIC was restarted, this information will zero out.
$computer = "LocalHost";
$namespace = "root\CIMV2";
$Tcpip_NI = Get-WmiObject -class Win32_PerfRawData_Tcpip_NetworkInterface -computername $computer -namespace $namespace;
$Tcpip_NI | Select BytesReceivedPersec, BytesSentPersec, BytesTotalPersec;
$netsh_interface_stats = netsh interface ip show interface;
$netsh_interface_stats | Select-string "In Octets";
$netsh_interface_stats | Select-string "Out Octets";
Upvotes: 7
Reputation: 3888
I found an existing solution for my own problem, PRTG Network Monitor version 7.
It has sensors to interface with WMI and get the network card data. Very nice :)
Upvotes: -1
Reputation: 30699
You could use an IronRuby or IronPython script and use the System.Net.NetworkInformation namespace although it would probably be easier to whip up a quick C# or VB.NET console application.
You probably need the class IPv4InterfaceStatistics.
Upvotes: 1
Reputation: 354346
Does netstat -e
help? It doesn't seem to distinguish between NICs, though you may get your maintenance interface traffic mixed into that as well.
Otherwise this sounds like something for WMI and PowerShell.
Upvotes: 2