網(wǎng)絡接口利用率監(jiān)控VBS腳本代碼(Windows)
來源:易賢網(wǎng) 閱讀:1412 次 日期:2016-07-05 14:39:17
溫馨提示:易賢網(wǎng)小編為您整理了“網(wǎng)絡接口利用率監(jiān)控VBS腳本代碼(Windows)”,方便廣大網(wǎng)友查閱!

監(jiān)測windows主機網(wǎng)絡接口利用率的vbs代碼,需要的朋友可以參考下。

代碼如下:

'程序名稱: btlwchk_netinterface.vbs

'程序用途: 監(jiān)測windows主機網(wǎng)絡接口利用率

'創(chuàng)建日期: 2011-09-1

'作者信息: zhangkai

'運行環(huán)境: vbs

'處理參數(shù)

MonSubject="NetInterface"

Set Args=WScript.Arguments

If (Args.Count<1) Then

Wscript.Echo MonSubject & " -1:command line error"

WScript.Quit(3)

End If

strcid=Args(0)

'獲取工作目錄

tmparr=Split(Wscript.ScriptFullName,"\",-1)

g_strworkdir=tmparr(0)

narr=UBound(tmparr,1)

For i=1 to narr-3

g_strworkdir=g_strworkdir & "\" & tmparr(i)

Next

'裝載公共庫

set g_fileSys = createObject ("Scripting.FileSystemObject")

Sub includeFile (fSpec)

dim file, fileData

set file = g_fileSys.openTextFile (fSpec)

fileData = file.readAll ()

file.close

executeGlobal fileData

set file = nothing

end sub

includeFile g_strworkdir & "\nagios\libexec\libcomm.vbs"

'輸出版本和幫助信息

getverhelp strcid,"v1.00"," <cid>"

strComputer = "."

Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

'第1次采樣

Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface",,48)

Dim BytesTotalPersec1(20),TimeValue1(20),Name1(20),CurrentBandwidth(20),BytesReceivedPerSec1(20),BytesSentPerSec1(20),PacketsReceivedPerSec1(20),PacketsSentPerSec1(20),_

BytesTotalPersec(20),PercentNetwork(20),BytesReceivedPerSec(20),BytesSentPerSec(20),PacketsReceivedPerSec(20),PacketsSentPerSec(20)

n=0

For Each objItem in colItems

Name1(n) = objItem.Name

BytesTotalPersec1(n) = objItem.BytesTotalPersec

BytesReceivedPerSec1(n) = objItem.BytesReceivedPerSec

BytesSentPerSec1(n) = objItem.BytesSentPerSec

PacketsReceivedPerSec1(n) = objItem.PacketsReceivedPerSec

PacketsSentPerSec1(n) = objItem.PacketsSentPerSec

TimeValue1(n) = objItem.Timestamp_PerfTime

CurrentBandwidth(n) = objItem.CurrentBandwidth

TimeBase = objItem.Frequency_PerfTime

n=n+1

Next

'第2次采樣

WScript.Sleep 1000

Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface",,48)

Dim BytesTotalPersec2(20),TimeValue2(20),Name2(20),BytesReceivedPerSec2(20),BytesSentPerSec2(20),PacketsReceivedPerSec2(20),PacketsSentPerSec2(20)

k=0

For Each objItem in colItems

Name2(k) = objItem.Name

BytesTotalPersec2(k) = objItem.BytesTotalPersec

BytesReceivedPerSec2(k) = objItem.BytesReceivedPerSec

BytesSentPerSec2(k) = objItem.BytesSentPerSec

PacketsReceivedPerSec2(k) = objItem.PacketsReceivedPerSec

PacketsSentPerSec2(k) = objItem.PacketsSentPerSec

TimeValue2(k) = objItem.Timestamp_PerfTime

k=k+1

Next

j=0

For i=0 to n-1

If TimeValue2(j) - TimeValue1(j) = 0 Then

strnetwork = "BytesTotalPersec=0"

Else

'帶寬利用率= (BytesReceivedPerSec + BytesSentPerSec)*8*100/ CurrentBandwidth

'計算利用率

BytesTotalPersec(j) = (BytesTotalPersec2(j) - BytesTotalPersec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)

PercentNetwork(j) = BytesTotalPersec(j)*8*100 / CurrentBandwidth(j)

PercentNetwork(j) = round(PercentNetwork(j),2)

'計算BytesReceivedPerSec

BytesReceivedPerSec(j) = (BytesReceivedPerSec2(j) - BytesReceivedPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)/1024

BytesReceivedPerSec(j) = round(BytesReceivedPerSec(j),2)

'計算BytesSentPerSec

BytesSentPerSec(j) = (BytesSentPerSec2(j) - BytesSentPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)/1024

BytesSentPerSec(j) = round(BytesSentPerSec(j),2)

'計算PacketsReceivedPerSec

PacketsReceivedPerSec(j) = (PacketsReceivedPerSec2(j) - PacketsReceivedPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)

PacketsReceivedPerSec(j) = round(PacketsReceivedPerSec(j),2)

'計算PacketsSentPerSec

PacketsSentPerSec(j) = (PacketsSentPerSec2(j) - PacketsSentPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)

PacketsSentPerSec(j) = round(PacketsSentPerSec(j),2)

'計算CurrentBandwidth

CurrentBandwidth(j) = CInt(CurrentBandwidth(j)/1000/1000)

End If

If j = 0 Then

Wscript.Echo MonSubject & " 0:OK|Name=" & Name1(j) & ",PercentNetwork=" & PercentNetwork(j) & ",BytesReceivedPerSec=" & BytesReceivedPerSec(j) & ",BytesSentPerSec=" & BytesSentPerSec(j) _

& ",PacketsReceivedPerSec=" & PacketsReceivedPerSec(j) & ",PacketsSentPerSec=" & PacketsSentPerSec(j) & ",CurrentBandwidth=" & CurrentBandwidth(j)

End If

'Wscript.Echo MonSubject & " 0:OK|" & Name1(j) & ",PercentNetwork=" & PercentNetwork

j=j+1

Next

更多信息請查看腳本欄目

2025國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 加入群交流 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:526150442(9:00—18:00)版權所有:易賢網(wǎng)