views:

348

answers:

4

Is there any easy way (via a script perhaps) to get the cumulative bytes sent and received from a NIC on Windows 2008 Server?

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.

A: 

Does netstat -e help? Doesn't seem to distinguish between NICs, though so you may get your maintenance interface traffic mixed into that as well.

Otherwise this sounds like something for WMI and Powershell.

Joey
A: 

You could use a IronRuby or IronPython script and utilise the System.Net.NetworkInformation namespace although it would prob be easier to whip up a quick C# or VB.Net console app.

Edit: The class you probably need is IPv4InterfaceStatistics.

sipwiz
A: 

I found an existing solution for my own problem, PRTG Network Monitor V7 (http://www.paessler.com/prtg).

It has sensors to interface with WMI and get the network card data. Very nice :)

smartins
+2  A: 

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" ;