温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何使用vbs监测windows主机网络接口利用率

发布时间:2021-10-11 10:46:32 来源:亿速云 阅读:157 作者:小新 栏目:编程语言

这篇文章将为大家详细讲解有关如何使用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主机网络接口利用率”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

vbs
AI