General discussion

Locked

CPU Utilization Script

By ask_anurag ·
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.

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by 3xp3rt In reply to CPU Utilization Script

For this kind of job you need some knowledge about Windows API.
For this see the following link http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getting_hardware_information.asp

Collapse -

by ask_anurag In reply to

Hi,

Thanks for your help.

Collapse -

by neilb@uk In reply to CPU Utilization Script

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

Collapse -

by ask_anurag In reply to CPU Utilization Script

This question was closed by the author

Back to Windows Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums