日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

性能计数器取网卡流量

發(fā)布時(shí)間:2025/4/5 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 性能计数器取网卡流量 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1.通過(guò)性能計(jì)數(shù)器取網(wǎng)卡流量

$public_interface = "Broadcom BCM5709C NetXtreme II GigE [NDIS VBD 客戶端]"$counter = New-Object Diagnostics.PerformanceCounter $counter.CategoryName = "Network Interface" $counter.InstanceName = $public_interface #$counter.CategoryName = "Processor Information(_Total)"#添加計(jì)數(shù)器屬性值,此處監(jiān)視可用內(nèi)存 $counter.CounterName = "Bytes Sent/sec" #$counter.CounterName = "Bytes Received/sec"#$counter.nextsample() #取樣本(RawValue),需要間隔1秒,取兩個(gè)sample做減法,才能得出每秒流量 #獲取當(dāng)前計(jì)數(shù)器的值 $value = $counter.NextValue() Start-Sleep -Seconds 1 $counter.NextValue()

?

2.通過(guò)get-counter取網(wǎng)卡流量(PS2.0)

#$networkcounter = get-counter -counter "\Network Interface(Broadcom BCM5709C NetXtreme II GigE [NDIS VBD 客戶端])\Bytes Sent/sec" #-continuous$networkcounter = get-counter -counter "\Network Interface($public_interface)\Bytes Sent/sec" #-continuous($networkcounter.CounterSamples|Select CookedValue).CookedValue

?

同時(shí)取網(wǎng)卡發(fā)送/接收流量

#檢查機(jī)器上配置IP的網(wǎng)卡數(shù)量,配置了gateway的網(wǎng)卡為Public,否則為Private [array]$netifs = gwmi Win32_NetworkAdapterConfiguration -Filter "IPEnabled='true'" If ($netifs.count -eq 1){$public_interface = $netifs[0].Description.replace("(","[").replace(")","]").replace("#","_")} If ($netifs.count -eq 2){$public_interface = ($netifs | ? {$_.DefaultIPGateway -ne $null}).Description.replace("(","[").replace(")","]").replace("#","_")$private_interface = ($netifs | ? {$_.DefaultIPGateway -eq $null}).Description.replace("(","[").replace(")","]").replace("#","_")}#定義函數(shù),通過(guò)性能計(jì)數(shù)器取網(wǎng)卡發(fā)送/接收流量 Function Netif_Sent_Received($interfacename,$send_member,$receiev_member) { $counter_Sent = New-Object Diagnostics.PerformanceCounter $counter_Receive = New-Object Diagnostics.PerformanceCounter $counter_Sent.CategoryName = "Network Interface" $counter_Receive.CategoryName = "Network Interface" $counter_Sent.InstanceName = $interfacename $counter_Receive.InstanceName = $interfacename $counter_Sent.CounterName = "Bytes Sent/sec" $counter_Receive.CounterName = "Bytes Received/sec" $value_Sent = $counter_Sent.NextValue() $value_Receive = $counter_Receive.NextValue() Start-Sleep -Seconds 1 $Sent = $counter_Sent.NextValue() $Receive = $counter_Receive.NextValue() $i_object | Add-Member -MemberType NoteProperty -name $send_member -value $sent $i_object | Add-Member -MemberType NoteProperty -name $receiev_member -value $receive }#將所有結(jié)果存放到$i_object對(duì)象中 $i_object = New-Object system.object If ($private_interface -ne $null){Netif_Sent_Received $private_interface Private_Send Private_Receive} If ($public_interface -ne $null) {Netif_Sent_Received $public_interface Public_Send Public_Receive}

?

轉(zhuǎn)載于:https://www.cnblogs.com/dreamer-fish/p/4710838.html

總結(jié)

以上是生活随笔為你收集整理的性能计数器取网卡流量的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。