Up time stats?

  • Thread starter Thread starter Troy Bruder
  • Start date Start date
T

Troy Bruder

Hello,

Is there an accurate way to generate ACCURATE "up time" statistics for Win2k
servers if we clear our event logs every month??

Thanks,
Troy
 
If the site isn't prone to stop/starting the workstation or server service,
the command *net statistics server* should give a good indication.
 
Thanks, I'll work with that!

neo said:
If the site isn't prone to stop/starting the workstation or server service,
the command *net statistics server* should give a good indication.
 
Can it be run against remote machines? I have a script I use to collect "up
times" for a stack of servers and would hate to loose that functionality...
 
neo said:
Nope. For remote stuff, I would use WMI to pull the information.

This link has a WSH/VBScript file that can be modified to possible suit your
needs.
http://groups.google.com/[email protected]
Hi

In the script in the link above I didn't handle the time zone information
correctly, here is an updated version that should work better:


strComputer = "." ' "." for local computer

On Error Resume Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer _
& "\root\cimv2")

If Err.Number = 0 Then
On Error Goto 0
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOS in colOperatingSystems
dtmLastBootUpTime = ConvWMIDateTime(objOS.LastBootUpTime, "ISO8601")
dtmSystemUptimeInHours = DateDiff("h", dtmLastBootUpTime, Now)
dtmSystemUptimeInDays = DateDiff("d", dtmLastBootUpTime, Now)
Wscript.Echo "Computer: " & strComputer _
& " started at " & dtmLastBootUpTime
Wscript.Echo "Uptime in hours: " & dtmSystemUptimeInHours
Wscript.Echo "Uptime in days: " & dtmSystemUptimeInDays & vbCrlf
Next

Else
Wscript.Echo "Could not connect to computer with WMI: " _
& strComputer
End If


Function ConvWMIDateTime(sDMTFformat, iNamedFormat)

' Author: Torgeir Bakken
' Modified: 2004-01-16
'
' Converts WMI Date and Time Format to standard date/time
'
' WMI Date and Time Format is documented here:
' http://msdn.microsoft.com/library/en-us/wmisdk/wmi/date_and_time_format.asp
'
' Arguments ----->

' DMTFformat: Date string in WMI Date and Time Format
'
' iNamedFormat: Optional. Numeric value that indicates the date/time
' format used. If omitted, ISO 8601 is used.

' -1 (and anything <> 0-4) Display in International Date Format ISO8601
' YYYY-MM-DD hh:nn:ss e.g. 2004-01-15 23:50:44
'
' vbGeneralDate 0 Display a date and/or time. If there is a date part,
' display it as a short date. If there is a time part,
' display it as a long time. If present, both parts are
' displayed.
'
' vbLongDate 1 Display a date using the long date format specified in
' your computer's regional settings.
'
' vbShortDate 2 Display a date using the short date format specified in
' your computer's regional settings.
'
' vbLongTime 3 Display a time using the time format specified in your
' computer's regional settings.
'
' vbShortTime 4 Display a time using the 24-hour format (hh:mm).

Dim sYear, sMonth, sDay, sHour, sMinutes, sSeconds
sYear = mid(sDMTFformat, 1, 4)
sMonth = mid(sDMTFformat, 5, 2)
sDay = mid(sDMTFformat, 7, 2)
sHour = mid(sDMTFformat, 9, 2)
sMinutes = mid(sDMTFformat, 11, 2)
sSeconds = mid(sDMTFformat, 13, 2)

' YYYY-MM-DD hh:nn:ss
ConvWMIDateTime = sYear & "-" & sMonth & "-" & sDay & " " _
& sHour & ":" & sMinutes & ":" & sSeconds

If IsNumeric(iNamedFormat) Then
If iNamedFormat >= 0 And iNamedFormat <= 4 Then
' FormatDateTime will set date format to specified format
ConvWMIDateTime = FormatDateTime(ConvWMIDateTime, iNamedFormat)
End If
End If
End Function
 
Even better. Thanks!!

Any ideas why sometimes the line objOS.LastBootUpTime returns a NULL value?

Troy
 
Troy said:
Even better. Thanks!!

Any ideas why sometimes the line objOS.LastBootUpTime returns a NULL value?
Hi

This is an known issue. One person has stated that this update
fixes this (you need to call Microsoft to obtain the update):

http://support.microsoft.com/default.aspx?id=825666


Using SystemUpTime from Win32_PerfRawData_PerfOS_System is
supposedly a workaround:

http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_perfrawdata_perfos_system.asp


Please try this version that uses raw data counter version of SystemUpTime:


'--------------------8<----------------------
strComputer = "." ' "." for local computer

On Error Resume Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer _
& "\root\cimv2")

If Err.Number = 0 Then
On Error Goto 0
strQuery = "select * from Win32_PerfRawData_PerfOS_System"
Set colObjects = objWMIService.ExecQuery(strQuery)

For Each objWmiObject In colObjects
intPerfTimeStamp = objWmiObject.Timestamp_Object
intPerfTimeFreq = objWmiObject.Frequency_Object
intCounter = objWmiObject.SystemUpTime
Next

' Calculation in seconds:
'Calculations for Raw Counter Data:PERF_ELAPSED_TIME
'http://msdn.microsoft.com/library/en-us/perfmon/base/perf_elapsed_time.asp
iUptimeInSec = (intPerfTimeStamp - intCounter)/intPerfTimeFreq
WScript.Echo "Uptime in seconds: " & iUptimeInSec \ 1

' convert the seconds
sUptime = ConvertTime(iUptimeInSec)
WScript.Echo "Uptime: " & sUptime

Else
Wscript.Echo "Could not connect to computer with WMI: " _
& strComputer
End If


Function ConvertTime(seconds)
ConvSec = seconds Mod 60
ConvMin = (seconds Mod 3600) \ 60
ConvHour = (seconds Mod (3600 * 24)) \ 3600
ConvDays = seconds \ (3600 * 24)
ConvertTime = ConvDays & " days " & ConvHour & " hours " _
& ConvMin & " minutes " & ConvSec & " seconds "
End Function
'--------------------8<----------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top