Board logo

标题: [问题求助] 监测windows主机网络接口利用率的VBS缺参数? [打印本页]

作者: chimeimo    时间: 2013-7-17 21:51     标题: 监测windows主机网络接口利用率的VBS缺参数?

注:这部分代码是在网站查到的。属转载他人。
这个脚本在运行时会报这一段错误,-1:command line error
看起来是缺少参数,谁能看出来参数是什么.
本人VBS脚本只停留在对文本操作的阶段..实在看不出来。
  1. '程序名称: btlwchk_netinterface.vbs
  2. '程序用途: 监测windows主机网络接口利用率
  3. '创建日期: 2011-09-1
  4. '作者信息: zhangkai
  5. '运行环境: vbs
  6. '处理参数
  7. MonSubject="NetInterface"
  8. Set Args=WScript.Arguments
  9. If (Args.Count<1) Then
  10. Wscript.Echo MonSubject & " -1:command line error"
  11. WScript.Quit(3)
  12. End If
  13. strcid=Args(0)
  14. '获取工作目录
  15. tmparr=Split(Wscript.ScriptFullName,"\",-1)
  16. g_strworkdir=tmparr(0)
  17. narr=UBound(tmparr,1)
  18. For i=1 to narr-3
  19. g_strworkdir=g_strworkdir & "\" & tmparr(i)
  20. Next
  21. '装载公共库
  22. set g_fileSys = createObject ("Scripting.FileSystemObject")
  23. Sub includeFile (fSpec)
  24. dim file, fileData
  25. set file = g_fileSys.openTextFile (fSpec)
  26. fileData = file.readAll ()
  27. file.close
  28. executeGlobal fileData
  29. set file = nothing
  30. end sub
  31. includeFile g_strworkdir & "\nagios\libexec\libcomm.vbs"
  32. '输出版本和帮助信息
  33. getverhelp strcid,"v1.00"," <cid>"
  34. strComputer = "."
  35. Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  36. '第1次采样
  37. Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface",,48)
  38. Dim BytesTotalPersec1(20),TimeValue1(20),Name1(20),CurrentBandwidth(20),BytesReceivedPerSec1(20),BytesSentPerSec1(20),PacketsReceivedPerSec1(20),PacketsSentPerSec1(20),_
  39. BytesTotalPersec(20),PercentNetwork(20),BytesReceivedPerSec(20),BytesSentPerSec(20),PacketsReceivedPerSec(20),PacketsSentPerSec(20)
  40. n=0
  41. For Each objItem in colItems
  42. Name1(n) = objItem.Name
  43. BytesTotalPersec1(n) = objItem.BytesTotalPersec
  44. BytesReceivedPerSec1(n) = objItem.BytesReceivedPerSec
  45. BytesSentPerSec1(n) = objItem.BytesSentPerSec
  46. PacketsReceivedPerSec1(n) = objItem.PacketsReceivedPerSec
  47. PacketsSentPerSec1(n) = objItem.PacketsSentPerSec
  48. TimeValue1(n) = objItem.Timestamp_PerfTime
  49. CurrentBandwidth(n) = objItem.CurrentBandwidth
  50. TimeBase = objItem.Frequency_PerfTime
  51. n=n+1
  52. Next
  53. '第2次采样
  54. WScript.Sleep 1000
  55. Set colItems = objWMIService.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface",,48)
  56. Dim BytesTotalPersec2(20),TimeValue2(20),Name2(20),BytesReceivedPerSec2(20),BytesSentPerSec2(20),PacketsReceivedPerSec2(20),PacketsSentPerSec2(20)
  57. k=0
  58. For Each objItem in colItems
  59. Name2(k) = objItem.Name
  60. BytesTotalPersec2(k) = objItem.BytesTotalPersec
  61. BytesReceivedPerSec2(k) = objItem.BytesReceivedPerSec
  62. BytesSentPerSec2(k) = objItem.BytesSentPerSec
  63. PacketsReceivedPerSec2(k) = objItem.PacketsReceivedPerSec
  64. PacketsSentPerSec2(k) = objItem.PacketsSentPerSec
  65. TimeValue2(k) = objItem.Timestamp_PerfTime
  66. k=k+1
  67. Next
  68. j=0
  69. For i=0 to n-1
  70. If TimeValue2(j) - TimeValue1(j) = 0 Then
  71. strnetwork = "BytesTotalPersec=0"
  72. Else
  73. '带宽利用率= (BytesReceivedPerSec + BytesSentPerSec)*8*100/ CurrentBandwidth
  74. '计算利用率
  75. BytesTotalPersec(j) = (BytesTotalPersec2(j) - BytesTotalPersec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)
  76. PercentNetwork(j) = BytesTotalPersec(j)*8*100 / CurrentBandwidth(j)
  77. PercentNetwork(j) = round(PercentNetwork(j),2)
  78. '计算BytesReceivedPerSec
  79. BytesReceivedPerSec(j) = (BytesReceivedPerSec2(j) - BytesReceivedPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)/1024
  80. BytesReceivedPerSec(j) = round(BytesReceivedPerSec(j),2)
  81. '计算BytesSentPerSec
  82. BytesSentPerSec(j) = (BytesSentPerSec2(j) - BytesSentPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)/1024
  83. BytesSentPerSec(j) = round(BytesSentPerSec(j),2)
  84. '计算PacketsReceivedPerSec
  85. PacketsReceivedPerSec(j) = (PacketsReceivedPerSec2(j) - PacketsReceivedPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)
  86. PacketsReceivedPerSec(j) = round(PacketsReceivedPerSec(j),2)
  87. '计算PacketsSentPerSec
  88. PacketsSentPerSec(j) = (PacketsSentPerSec2(j) - PacketsSentPerSec1(j)) / ((TimeValue2(j) - TimeValue1(j)) / TimeBase)
  89. PacketsSentPerSec(j) = round(PacketsSentPerSec(j),2)
  90. '计算CurrentBandwidth
  91. CurrentBandwidth(j) = CInt(CurrentBandwidth(j)/1000/1000)
  92. End If
  93. If j = 0 Then
  94. Wscript.Echo MonSubject & " 0:OK|Name=" & Name1(j) & ",PercentNetwork=" & PercentNetwork(j) & ",BytesReceivedPerSec=" & BytesReceivedPerSec(j) & ",BytesSentPerSec=" & BytesSentPerSec(j) _
  95. & ",PacketsReceivedPerSec=" & PacketsReceivedPerSec(j) & ",PacketsSentPerSec=" & PacketsSentPerSec(j) & ",CurrentBandwidth=" & CurrentBandwidth(j)
  96. End If
  97. 'Wscript.Echo MonSubject & " 0:OK|" & Name1(j) & ",PercentNetwork=" & PercentNetwork
  98. j=j+1
  99. Next
复制代码

作者: CrLf    时间: 2013-7-18 00:48

getverhelp 是从库里引用来的,把 libcomm.vbs 也发上来看下
作者: lxzzr    时间: 2013-7-18 16:11

Win32_PerfRawData_Tcpip_NetworkInterface,不一定准确。。
作者: chimeimo    时间: 2013-7-18 23:20

回复 2# CrLf


    很抱歉,只有这一个脚本.那开起来这个脚本是用不了了.感谢帮忙~~
作者: chimeimo    时间: 2013-7-18 23:23

Win32_PerfRawData_Tcpip_NetworkInterface,不一定准确。。
lxzzr 发表于 2013-7-18 16:11



    这个参数要用在什么地方呢?
Cscript  脚本名.VBS  /Win32_PerfRawData_Tcpip_NetworkInterface 这样吗?
作者: lxzzr    时间: 2013-7-19 00:24

回复 5# chimeimo


    不是的。

libcomm.vbs 这个文件在哪?代码32行那

顺便吐槽下原作者的代码风格,,,,,
作者: chimeimo    时间: 2013-7-19 20:24

回复  chimeimo


    不是的。

libcomm.vbs 这个文件在哪?代码32行那

顺便吐槽下原作者的代码风 ...
lxzzr 发表于 2013-7-19 00:24

我知道你要的那个文件.。但是..。坏消息是这个文件我也没有...




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2