监测windows主机网络接口利用率的vbs代码
来源:本站原创|时间:2020-01-10|栏目:vb|点击: 次
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.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
这篇文章就介绍到这了
您可能感兴趣的文章
- 01-10远程启动终端服务的windows脚本ROTS.vbs
- 01-10远程开启/关闭目标telnet服务的windows脚本RTCS.vbs
- 01-10vbs实用软件自造——Windows脚本应用实例
- 01-10一个可以更换windows xp or 2003的序列号的vbs脚本
- 01-10什么是 WSH(脚本宿主)的详细解释
- 01-10windows.vbs.FSO.文件操作信息.磁盘驱动信息.文件夹操作信息全集
- 01-10修复Windows上面的WScript的脚本(.vbs)不能执行了
- 01-10windows.关于设置脚本的一些基本方法原则
- 01-10WINDOWS脚本实践:为SAP补丁制作的VBS脚本代码
- 01-10用vbs实现在启动 Windows 资源管理器时打开特定文件夹
阅读排行
本栏相关
- 01-10下载文件到本地运行的vbs
- 01-10飘叶千夫指源代码,又称qq刷屏器
- 01-10SendKeys参考文档
- 01-10什么是一个高效的软件
- 01-10VBS中的正则表达式的用法大全 &l
- 01-10exe2swf 工具(Adodb.Stream版)
- 01-10VBS中SendKeys的基本应用
- 01-10用VBSCRIPT控制ONSUBMIT事件
- 01-10VBScript教程 第十一课深入VBScript
- 01-10VBScript语法速查及实例说明
随机阅读
- 01-10C#中split用法实例总结
- 01-11ajax实现页面的局部加载
- 08-05dedecms(织梦)副栏目数量限制代码修改
- 04-02jquery与jsp,用jquery
- 08-05织梦dedecms什么时候用栏目交叉功能?
- 01-11Mac OSX 打开原生自带读写NTFS功能(图文
- 01-10delphi制作wav文件的方法
- 08-05DEDE织梦data目录下的sessions文件夹有什
- 01-10使用C语言求解扑克牌的顺子及n个骰子
- 01-10SublimeText编译C开发环境设置