Get the cumulative bytes sent and received from a NIC

南楼画角 提交于 2020-01-01 17:09:13

问题


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.


回答1:


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



回答2:


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.




回答3:


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.




回答4:


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




回答5:


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 :)



来源:https://stackoverflow.com/questions/718762/get-the-cumulative-bytes-sent-and-received-from-a-nic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!