您好,登錄后才能下訂單哦!
這篇文章將為大家詳細(xì)講解有關(guān)如何使用vbs監(jiān)測(cè)windows主機(jī)網(wǎng)絡(luò)接口利用率,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
btlwchk_netinterface.vbs
'程序名稱: btlwchk_netinterface.vbs'版權(quán)信息: Copyright (c) 2011 guangzhou bluetech technology Incorporated.All rights reserved'程序用途: 監(jiān)測(cè)windows主機(jī)網(wǎng)絡(luò)接口利用率'創(chuàng)建日期: 2011-09-1'作者信息: zhangkai'運(yùn)行環(huán)境: vbs'處理參數(shù)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'計(jì)算利用率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)'計(jì)算BytesReceivedPerSecBytesReceivedPerSec(j) = (BytesReceivedPerSec2(j) - BytesReceivedPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)/1024BytesReceivedPerSec(j) = round(BytesReceivedPerSec(j),2)'計(jì)算BytesSentPerSecBytesSentPerSec(j) = (BytesSentPerSec2(j) - BytesSentPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)/1024BytesSentPerSec(j) = round(BytesSentPerSec(j),2)'計(jì)算PacketsReceivedPerSecPacketsReceivedPerSec(j) = (PacketsReceivedPerSec2(j) - PacketsReceivedPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)PacketsReceivedPerSec(j) = round(PacketsReceivedPerSec(j),2)'計(jì)算PacketsSentPerSecPacketsSentPerSec(j) = (PacketsSentPerSec2(j) - PacketsSentPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)PacketsSentPerSec(j) = round(PacketsSentPerSec(j),2)'計(jì)算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
關(guān)于“如何使用vbs監(jiān)測(cè)windows主機(jī)網(wǎng)絡(luò)接口利用率”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。