网站建设资讯

NEWS

网站建设资讯

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

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


分享题目:如何使用vbs监测windows主机网络接口利用率
文章链接:http://cdweb.net/article/jhciig.html