Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS SQL

Posted Nov 2, 2005

Monitor CPU Usage of All Running Processes - Part I

By Muthusamy Anantha Kumar aka The MAK

This article illustrates how to monitor CPU usage on different running process on one machine and on multiple machines. In many organizations, the SQL Server Database administrator and System administrators have the responsibility of trouble shooting and identifying the cause of high CPU usage during certain periods in a day on a machine.

This article demonstrates how to keep track of the CPU load history on each running process that is running on a machine. This article also discusses how to find new processes that are being run and any old process that are being killed, etc.

This article uses "Win32_PerfFormattedData_PerfProc_Process" WMI class to get the information from the performance counters of a machine.

Method 1

Method 1 illustrates how to query all the running process and their CPU usage on the local machine.

Pre-requisite

a.  Machine and the login used should be capable of accessing Windows management instrumentation.

b. Operating System on that machine should be above windows 2000.

Steps

a.  Create the Folder C:\monitorprocess. [Refer Fig 1.0]


[Fig 1.0]

b.  Create the file C:\monitorprocess\ListProcess.vbs and copy and paste the below code. [Refer Fig 1.1]. Download the code from listprocess.VBS_



'Objective: To Find the CPU usage of each running process that are running on the local machine
'Created by : MAK
'Created Date: Oct 27, 2005
strComputer ="."
Set objWMIService = GetObject("winmgmts:\\" > strComputer > "\root\cimv2")
Set colProcess = objWMIService.ExecQuery("Select * from Win32_PerfFormattedData_PerfProc_Process",,48)
        wscript.echo "Computer Name",> "," > "Process Name" > ","> "CPU Usage"
For Each objItem in colProcess
if objItem.Name <> "Idle"  and objItem.Name <> "_Total" then 
        wscript.echo strcomputer > "," > objItem.Name > ","> objItem.PercentProcessorTime
end if
Next

c.  Execute the listprocess.vbs code using the command below. [Refer Fig 1.2]

cscript Listprocess.vbs


[Fig 1.2]

When this VBScript is executed, it displays all the processes that are running on a current machine and their CPU usage. [Refer Fig 1.3]


[Fig 1.3]

Computer Name,Process Name,CPU Usage
.,System, 0
.,smss, 0
.,csrss, 0
.,winlogon, 0
.,services, 0
.,lsass, 0
.,svchost, 0
.,svchost, 0
.,svchost, 0
.,svchost, 0
.,spoolsv, 0
.,residentAgent, 0
.,cpqalert, 0
.,DWRCS, 0
.,pmsvc, 0
.,LocalSch, 0
.,tmcsvc, 0
.,LCRMS, 0
.,FrameworkService, 0
.,Mcshield, 0
.,VsTskMgr, 0
.,mdm, 0
.,mgabg, 0
.,tcpsvcs, 0
.,snmp, 0
.,Win32sl, 0
.,wuser32, 0
.,cpqdmi, 0
.,naPrdMgr, 0
.,SoftMon, 0
.,explorer, 0
.,chkadmin, 0
.,UpdaterUI, 0
.,shstat, 0
.,ctfmon, 0
.,svchost, 0
.,notepad, 0
.,notepad, 0
.,notepad, 0

d. The output can be stored to a CSV file by executing the command below. [Refer Fig 1.4]

C:\monitorprocess>cscript/nologo  Listprocess.vbs > LocalProcess.csv


[Fig 1.4]

When executed, it is stored in a CSV format file that can be opened and viewed using MS-EXCEL. [Refer Fig 1.5]


[Fig 1.5]



MS SQL Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
MS SQL Forum
Topic By Replies Updated
SQL 2005: SSIS: Error using SQL Server credentials poverty 3 August 17th, 07:43 AM
Need help changing table contents nkawtg 1 August 17th, 03:02 AM
SQL Server Memory confifuration bhosalenarayan 2 August 14th, 05:33 AM
SQL Server Primary Key and a Unique Key katty.jonh 2 July 25th, 10:36 AM


















Thanks for your registration, follow us on our social networks to keep up-to-date