Page 1 of 1

Average CPU load on Windows?

Posted: Thu Jun 11, 2009 3:13 pm
by kaisellgren
Hi,

Does anyone have an idea how to get the average CPU load on Windows?

Re: Average CPU load on Windows?

Posted: Thu Jun 11, 2009 4:05 pm
by McInfo
I'm assuming you want a command-line tool that you can call from PHP? Tasklist provides some useful information on running processes and memory usage.

Code: Select all

<?php
header('Content-Type: text/plain');
echo system('tasklist /V');
?>
The ouput is too extensive to paste here.

For something shorter, this call filters the output for processes where the image name is "System Idle Process".

Code: Select all

tasklist /FI "IMAGENAME eq System Idle Process"
The output is something like

Code: Select all

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
System Idle Process              0 Services                   0         24 K
If the memory usage of the System Idle Process is low, the CPU load is low as well.

I'll keep looking for the proper command-line tool.

Edit: This post was recovered from search engine cache.

Re: Average CPU load on Windows?

Posted: Thu Jun 11, 2009 6:07 pm
by mikemike
I posted a C app to someone earlier. Let me find it...

Re: Average CPU load on Windows?

Posted: Thu Jun 11, 2009 6:08 pm
by mikemike

Re: Average CPU load on Windows?

Posted: Thu Jun 11, 2009 6:41 pm
by McInfo
Thanks, mikemike. Because of the code you posted, I was able to find information on the Performance Command Line Tools and discovered that the performance counters can be accessed using typeperf.

Command line:

Code: Select all

C:>typeperf -?
Output:

Code: Select all

Microsoft r TypePerf.exe (6.0.6000.16386)
 
Typeperf writes performance data to the command window or to a log file. To
stop Typeperf, press CTRL+C.
 
Usage:
typeperf { <counter [counter ...]>
                                | -cf <filename>
                                | -q [object]
                                | -qx [object]
                                } [options]
 
Parameters:
  <counter [counter ...]>       Performance counters to monitor.
 
Options:
  -?                            Displays context sensitive help.
  -f <CSV|TSV|BIN|SQL>          Output file format. Default is CSV.
  -cf <filename>                File containing performance counters to
                                monitor, one per line.
  -si <[[hh:]mm:]ss>            Time between samples. Default is 1 second.
  -o <filename>                 Path of output file or SQL database. Default
                                is STDOUT.
  -q [object]                   List installed counters (no instances). To
                                list counters for one object, include the
                                object name, such as Processor.
  -qx [object]                  List installed counters with instances. To
                                list counters for one object, include the
                                object name, such as Processor.
  -sc <samples>                 Number of samples to collect. Default is to
                                sample until CTRL+C.
  -config <filename>            Settings file containing command options.
  -s <computer_name>            Server to monitor if no server is specified
                                in the counter path.
  -y                            Answer yes to all questions without prompting.
 
Note:
  Counter is the full name of a performance counter in
  "\\<Computer>\<Object>(<Instance>)\<Counter>" format,
  such as "\\Server1\Processor(0)\% User Time".
 
Examples:
  typeperf "\Processor(_Total)\% Processor Time"
  typeperf -cf counters.txt -si 5 -sc 50 -f TSV -o domain2.tsv
  typeperf -qx PhysicalDisk -o counters.txt
Edit: This post was recovered from search engine cache.

Re: Average CPU load on Windows?

Posted: Thu Jun 11, 2009 9:17 pm
by McInfo
This script displays the % Processor Time for all processors in CSV format and appends an update every second until you hit the stop button in your browser.

Code: Select all

<?php
header('Content-Type: text/plain');
echo system('typeperf "\Processor(*)\% Processor Time"');
?>
Edit: This post was recovered from search engine cache.

Re: Average CPU load on Windows?

Posted: Fri Jun 12, 2009 5:54 am
by kaisellgren
Thank you. I knew this could be accomplished. :)

Re: Average CPU load on Windows?

Posted: Fri Jun 12, 2009 9:51 am
by mikemike
:)welcome

Re: Average CPU load on Windows?

Posted: Wed Jun 24, 2009 2:48 am
by madhuj1260
Is there any command for web application?

Re: Average CPU load on Windows?

Posted: Wed Jun 24, 2009 12:58 pm
by McInfo
The system() function makes command-line programs accessible through Web applications. If you are looking for a different answer, you need to be more specific.

Edit: This post was recovered from search engine cache.