您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關如何使用vbs監測windows主機網絡接口利用率,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
btlwchk_netinterface.vbs
'程序名稱: btlwchk_netinterface.vbs'版權信息: Copyright (c) 2011 guangzhou bluetech technology Incorporated.All rights reserved'程序用途: 監測windows主機網絡接口利用率'創建日期: 2011-09-1'作者信息: zhangkai'運行環境: vbs'處理參數MonSubject="NetInterface"Set Args=WScript.ArgumentsIf (Args.Count<1) ThenWscript.Echo MonSubject & " -1:command line error"WScript.Quit(3)End Ifstrcid=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 = nothingend subincludeFile 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=0For Each objItem in colItemsName1(n) = objItem.NameBytesTotalPersec1(n) = objItem.BytesTotalPersecBytesReceivedPerSec1(n) = objItem.BytesReceivedPerSecBytesSentPerSec1(n) = objItem.BytesSentPerSecPacketsReceivedPerSec1(n) = objItem.PacketsReceivedPerSecPacketsSentPerSec1(n) = objItem.PacketsSentPerSecTimeValue1(n) = objItem.Timestamp_PerfTimeCurrentBandwidth(n) = objItem.CurrentBandwidthTimeBase = objItem.Frequency_PerfTimen=n+1Next'第2次采樣WScript.Sleep 1000Set 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=0For Each objItem in colItemsName2(k) = objItem.Name BytesTotalPersec2(k) = objItem.BytesTotalPersecBytesReceivedPerSec2(k) = objItem.BytesReceivedPerSecBytesSentPerSec2(k) = objItem.BytesSentPerSecPacketsReceivedPerSec2(k) = objItem.PacketsReceivedPerSecPacketsSentPerSec2(k) = objItem.PacketsSentPerSecTimeValue2(k) = objItem.Timestamp_PerfTimek=k+1Nextj=0For i=0 to n-1If TimeValue2(j) - TimeValue1(j) = 0 Thenstrnetwork = "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)'計算BytesReceivedPerSecBytesReceivedPerSec(j) = (BytesReceivedPerSec2(j) - BytesReceivedPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)/1024BytesReceivedPerSec(j) = round(BytesReceivedPerSec(j),2)'計算BytesSentPerSecBytesSentPerSec(j) = (BytesSentPerSec2(j) - BytesSentPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)/1024BytesSentPerSec(j) = round(BytesSentPerSec(j),2)'計算PacketsReceivedPerSecPacketsReceivedPerSec(j) = (PacketsReceivedPerSec2(j) - PacketsReceivedPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)PacketsReceivedPerSec(j) = round(PacketsReceivedPerSec(j),2)'計算PacketsSentPerSecPacketsSentPerSec(j) = (PacketsSentPerSec2(j) - PacketsSentPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)PacketsSentPerSec(j) = round(PacketsSentPerSec(j),2)'計算CurrentBandwidthCurrentBandwidth(j) = CInt(CurrentBandwidth(j)/1000/1000)End IfIf j = 0 ThenWscript.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=" & PercentNetworkj=j+1Next
關于“如何使用vbs監測windows主機網絡接口利用率”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。