Solved

How can I get performance metrics similar to WMI on Windows 2000?  I have a script that works in 2k3, but not 2000

Posted on 2011-02-24
5
746 Views
Last Modified: 2012-05-11
Hello,

I am trying to report performance metrics to my OM database from my windows machines.  I have a script which was written for Windows Server 2003/08 which works beautifully, but relys on WbemScripting.Swbemrefresher to work, and that object is not available on Windows Server 2000.  Is there an easy change I can make to the attached script to make it work in Win2k?  The failing line is 25.  Thanks.

ED7
'Read GUID from supporting file
'dim filesys, readfile, contents
set filesys = CreateObject("Scripting.FileSystemObject")
set readfile = filesys.OpenTextFile("c:\om_guid.txt", 1, false)
GUID = readfile.ReadLine
readfile.close

'Setup Date / Time variable for om
NewDate = FormatDate(DatePart("yyyy",Date)  & "-" & DatePart("m",Date) & "-" & DatePart("d",Date) , Time)

Function FormatDate (dt,tm)
  TheDate = cDate(dt)
  TheTime = cDate(tm)
  TheDate = Year(dt) & "-" & Right("0" & Month(dt),2) & "-" & Right("0" & Day(dt), 2)
  TheTime = Right("0" & Hour(tm),2) & ":" & Right("0" & Minute (tm), 2) & ":" & Right("0" & Second(tm), 2)
  FormatDate = TheDate & " " & TheTime
End Function

'Open winmgmt service and setup Refresher and device objects
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
  & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.Swbemrefresher")
Set objMemory = objRefresher.AddEnum _
  (objWMIService, "Win32_PerfFormattedData_PerfOS_Memory").objectSet
Set colDiskDrives = objWMIService.ExecQuery _
    ("Select * from Win32_PerfFormattedData_PerfDisk_LogicalDisk where " _
        & "Name <> '_Total'")
Set objProcessor = objRefresher.AddEnum _
    (objWMIService, "Win32_PerfFormattedData_PerfOS_Processor").objectSet

Set colNICs = objRefresher.AddEnum _
    (objWMIService, "Win32_PerfFormattedData_TCPIP_NetworkInterface"). objectSet

Set colComputerSystem = objWMIService.ExecQuery _ 
	("Select * From Win32_ComputerSystem")

objRefresher.Refresh

'Get values for each object and report to OM

'Computer Name
For Each objItem in colComputerSystem
    Machine_Name = objItem.Name
Next

'Available Memory
i=0
Dim symAvailMem(), meaAvailMem()
For each intAvailableBytes in objMemory
  ReDim Preserve symAvailMem(i), meaAvailMem(i)
  symAvailMem(i) = "Available_Memory"
  meaAvailMem(i) = Int(intAvailableBytes.AvailableMBytes)
  'Wscript.Echo symAvailMem(i)&": "& meaAvailMem(i) &"MB"
  i=i+1
Next

'Disk Free Space
i=0
Dim symDiskName(), meaDiskName()
For Each objDiskDrive in colDiskDrives
	ReDim Preserve symDiskName(i), meaDiskName(i)
	symDiskName(i) = objDiskDrive.Name
	meaDiskName(i) = objDiskDrive.FreeMegabytes
	'Wscript.Echo symDiskName(i) &" "& meaDiskName(i) &"MB Free"
	i=i+1
Next

'Network Traffic
i=0
Dim symNIC(), meaNIC()
For Each objItem in colNICs
	ReDim Preserve symNIC(i), meaNIC(i)
	symNIC(i) = objItem.Name
	meaNIC(i) = objItem.BytesTotalPerSec
	'Wscript.Echo symNIC(i) & ": " & meaNIC(i) &" Bps"
	i=i+1
Next 


'Processor Utilization
count = 0
For i = 1 to 10
	For each intProcessorUse in objProcessor
		count = count + 1
		ttlProcessorUse = Int(ttlProcessorUse) + Int(intProcessorUse.PercentProcessorTime)
	Next
	Wscript.Sleep 1000
	objRefresher.Refresh
Next

symProcessor = "Average_Processor_Use"
meaProcessor = Round(ttlProcessorUse/count,2)
'Wscript.Echo "Average Processor Use: " & Round(ttlProcessorUse/count,2) & "%"

'Setup OM reporting address
om_addr = "http://10.1.11.12/sample.asp?device_name="&Machine_Name&"&globalid="&GUID&"&collection_date="&NewDate

For i = 0 To UBound(symAvailMem)
	om_addr = om_addr & "&"&symAvailMem(i)&"="&meaAvailMem(i)
Next

For i = 0 To UBound(symDiskName)
	om_addr = om_addr & "&"&Replace(symDiskName(i)," ","_")&"="&meaDiskName(i)
Next

For i = 0 To UBound(symNIC)
	om_addr = om_addr & "&"&Replace(symNIC(i)," ","_")&"="&meaNIC(i)
Next

om_addr = om_addr & "&"&symProcessor&"="&meaProcessor



'Write om_addr for debugging purposes

if 0=1 then
	Dim objFSO, objFolder, objShell, objFile
	Dim strDirectory, strFile
	strDirectory = "c:\logs"
	strFile = "\om_log.txt"

	' Create the File System Object
	Set objFSO = CreateObject("Scripting.FileSystemObject")

	' Check that the strDirectory folder exists
	If objFSO.FolderExists(strDirectory) Then
	   Set objFolder = objFSO.GetFolder(strDirectory)
	Else
	Set objFolder = objFSO.CreateFolder(strDirectory)
	End If

	If objFSO.FileExists(strDirectory & strFile) Then
	Set objFolder = objFSO.GetFolder(strDirectory)
	Else
	Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
	End If 

	Set objTextStream = objFSO.OpenTextFile(strDirectory & strFile, ForAppending)
	objTextStream.WriteLine om_addr
	objTextStream.Close
	Set objTextStream = Nothing
	set objFolder = nothing
	set objFile = nothing

end if
 




'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'	Execute wget of om_addr address
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET", om_addr, false
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
 'Get call was successful
 wscript.echo "Success"
Else
 wscript.echo "Failed to get " & om_addr&"  Error was "& objXMLHTTP.Status
 'Get call failed
End if
Set objXMLHTTP = Nothing

Open in new window

0
Comment
Question by:electricd7
  • 2
  • 2
5 Comments
 

Author Comment

by:electricd7
ID: 34973688
OK so it seems I should be able to use Win32_PerfRawData instead of Win32_PerfFormattedData for windows 2000 machines.  I am not sure however, how I would query those because in those cases above I use objRefresher (WbemScripting.Swbemrefresher) to query them, and that is not available in Windows 2000.  Can anyone help?
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 34976070
Hi, instead of using the Refresher object, just put your WMI queries inside the For i = 1 to 10 loop, and execute them there 10 times.

Regards,

Rob.
0
 

Author Comment

by:electricd7
ID: 34976113
Can you perhaps post an example?  I am not sure how to change my queries to accommodate that difference?
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 34976150
OK, I haven't tested it, but maybe like this.

Regards,

Rob.
'Read GUID from supporting file
'dim filesys, readfile, contents
set filesys = CreateObject("Scripting.FileSystemObject")
set readfile = filesys.OpenTextFile("c:\om_guid.txt", 1, false)
GUID = readfile.ReadLine
readfile.close

'Setup Date / Time variable for om
NewDate = FormatDate(DatePart("yyyy",Date)  & "-" & DatePart("m",Date) & "-" & DatePart("d",Date) , Time)

Function FormatDate (dt,tm)
  TheDate = cDate(dt)
  TheTime = cDate(tm)
  TheDate = Year(dt) & "-" & Right("0" & Month(dt),2) & "-" & Right("0" & Day(dt), 2)
  TheTime = Right("0" & Hour(tm),2) & ":" & Right("0" & Minute (tm), 2) & ":" & Right("0" & Second(tm), 2)
  FormatDate = TheDate & " " & TheTime
End Function

'Open winmgmt service and setup Refresher and device objects
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colDiskDrives = objWMIService.ExecQuery("Select * From Win32_PerfFormattedData_PerfDisk_LogicalDisk where Name <> '_Total'")

Set colNICs = objWMIService.ExecQuery("Select * From Win32_PerfFormattedData_TCPIP_NetworkInterface")

Set colComputerSystem = objWMIService.ExecQuery("Select * From Win32_ComputerSystem")

'Get values for each object and report to OM

'Computer Name
For Each objItem in colComputerSystem
    Machine_Name = objItem.Name
Next

'Available Memory
i=0
Dim symAvailMem(), meaAvailMem()
For each intAvailableBytes in objMemory
  ReDim Preserve symAvailMem(i), meaAvailMem(i)
  symAvailMem(i) = "Available_Memory"
  meaAvailMem(i) = Int(intAvailableBytes.AvailableMBytes)
  'Wscript.Echo symAvailMem(i)&": "& meaAvailMem(i) &"MB"
  i=i+1
Next

'Disk Free Space
i=0
Dim symDiskName(), meaDiskName()
For Each objDiskDrive in colDiskDrives
	ReDim Preserve symDiskName(i), meaDiskName(i)
	symDiskName(i) = objDiskDrive.Name
	meaDiskName(i) = objDiskDrive.FreeMegabytes
	'Wscript.Echo symDiskName(i) &" "& meaDiskName(i) &"MB Free"
	i=i+1
Next

'Network Traffic
i=0
Dim symNIC(), meaNIC()
For Each objItem in colNICs
	ReDim Preserve symNIC(i), meaNIC(i)
	symNIC(i) = objItem.Name
	meaNIC(i) = objItem.BytesTotalPerSec
	'Wscript.Echo symNIC(i) & ": " & meaNIC(i) &" Bps"
	i=i+1
Next 


'Processor Utilization
count = 0
For i = 1 to 10
	Set objProcessor = objWMIService.ExecQuery("Select * From Win32_PerfFormattedData_PerfOS_Processor")
	For each intProcessorUse in objProcessor
		count = count + 1
		ttlProcessorUse = Int(ttlProcessorUse) + Int(intProcessorUse.PercentProcessorTime)
	Next
	Wscript.Sleep 1000
Next

symProcessor = "Average_Processor_Use"
meaProcessor = Round(ttlProcessorUse/count,2)
'Wscript.Echo "Average Processor Use: " & Round(ttlProcessorUse/count,2) & "%"

'Setup OM reporting address
om_addr = "http://10.1.11.12/sample.asp?device_name="&Machine_Name&"&globalid="&GUID&"&collection_date="&NewDate

For i = 0 To UBound(symAvailMem)
	om_addr = om_addr & "&"&symAvailMem(i)&"="&meaAvailMem(i)
Next

For i = 0 To UBound(symDiskName)
	om_addr = om_addr & "&"&Replace(symDiskName(i)," ","_")&"="&meaDiskName(i)
Next

For i = 0 To UBound(symNIC)
	om_addr = om_addr & "&"&Replace(symNIC(i)," ","_")&"="&meaNIC(i)
Next

om_addr = om_addr & "&"&symProcessor&"="&meaProcessor



'Write om_addr for debugging purposes

if 0=1 then
	Dim objFSO, objFolder, objShell, objFile
	Dim strDirectory, strFile
	strDirectory = "c:\logs"
	strFile = "\om_log.txt"

	' Create the File System Object
	Set objFSO = CreateObject("Scripting.FileSystemObject")

	' Check that the strDirectory folder exists
	If objFSO.FolderExists(strDirectory) Then
	   Set objFolder = objFSO.GetFolder(strDirectory)
	Else
	Set objFolder = objFSO.CreateFolder(strDirectory)
	End If

	If objFSO.FileExists(strDirectory & strFile) Then
	Set objFolder = objFSO.GetFolder(strDirectory)
	Else
	Set objFile = objFSO.CreateTextFile(strDirectory & strFile)
	End If 

	Set objTextStream = objFSO.OpenTextFile(strDirectory & strFile, ForAppending)
	objTextStream.WriteLine om_addr
	objTextStream.Close
	Set objTextStream = Nothing
	set objFolder = nothing
	set objFile = nothing

end if
 




'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'	Execute wget of om_addr address
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Set objXMLHTTP = CreateObject("MSXML2.XMLHTTP")
objXMLHTTP.open "GET", om_addr, false
objXMLHTTP.send()

If objXMLHTTP.Status = 200 Then
 'Get call was successful
 wscript.echo "Success"
Else
 wscript.echo "Failed to get " & om_addr&"  Error was "& objXMLHTTP.Status
 'Get call failed
End if
Set objXMLHTTP = Nothing

Open in new window

0
 

Expert Comment

by:getazhar
ID: 36233134
Invalid to use Round at line 93,1 error
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
A procedure for exporting installed hotfix details of remote computers using powershell
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question