?
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
Medium Priority
?
767 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Need protection from advanced malware attacks?

Look no further than WatchGuard's Total Security Suite, providing defense in depth against today's most headlining attacks like Petya 2.0 and WannaCry. Keep your organization out of the news with protection from known and unknown threats.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Simple Linear Regression

770 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