Discussion Locked

CPU Utilization Script

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi,

I need assistance to write a script for CPU Utilization which will records events in every 5 mins and transfer data in some text file.

Is there any kix or dos batch script which i can use.

Thanks and Regards.
Anurag.

4 replies

by Member 25348569

I use this smeggy little vbscript. Copy to a file called, say, CPU_Use.vbs or whatever and kick it off with the scheduler. It's set to Run Forever but doesn't load the CPU when sleeping so you can leave it running for days. The output file format is Date [Tab] Time [Tab] Total CPU use averaged over the period. The first iteration is always null.
------------------------------------
Const ForAppending = 8 'Contents not overwritten.

strComputer = "."
strLogFile = "c:\Processor.log" ' Your log file

Set objFSO=CreateObject("Scripting.FileSystemObject")

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
set objRefresher = CreateObject("WbemScripting.Swbemrefresher")
Set objProcessor = objRefresher.AddEnum _
(objWMIService, "Win32_PerfFormattedData_PerfOS_Processor").objectSet
objRefresher.Refresh

Do
For Each intProcessorUse in objProcessor
If intProcessorUse.Name = "_Total" Then
Set objLogfile = objFSO.OpenTextFile(strLogFile,ForAppending, true)
objLogFile.WriteLine FormatDateTime(Now,vbShortDate) & vbTab & _
FormatDateTime(Now,vbShortTime) & vbTab & _
intProcessorUse.PercentProcessorTime
objLogFile.Close
Set objLogFile = Nothing
End If
Next
Wscript.Sleep 300000 ' Sleep in mSec.
objRefresher.Refresh
Loop

This discussion is closed to new replies.