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 - Page 2

By Muthusamy Anantha Kumar aka The MAK

Method 2

Method 2 illustrates how to query all the running process and their CPU usage on a remote machine.

Pre-requisite

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

b.  Operating System on the local machine and remote machine should be above windows 2000.

Steps

a.  Create the file C:\monitorprocess\ Listremoteprocess.vbs and copy and paste the code below into it. [Refer Fig 1.6]. Download Listremoteprocess.vbs_

'Objective: To Find the CPU usage of each process 
'that are running on a remote machine
'Created by : MAK
'Created Date: Oct 27, 2005
'Syntax: cscript Listremoteprocess.vbs machinename
'Example: cscript Listremoteprocess.vbs MyMachine
Set objArgs = WScript.Arguments
strComputer =objArgs(0)
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




[Fig 1.6]

b.  Execute the VBScript as shown below. [Refer Fig 1.7]

cscript listremoteprocess.vbs imlnode1


[Fig 1.7]

When this VBScript is executed, it displays all of the processes that are running on a remote machine and their CPU usage.

Computer Name,Process Name,CPU Usage
imlnode1, System, 0
imlnode1, smss, 0
imlnode1, csrss, 0
imlnode1, winlogon, 0
imlnode1, services, 0
imlnode1, lsass, 0
imlnode1, svchost, 0
imlnode1, svchost, 0
imlnode1, svchost, 0
imlnode1, svchost, 0
imlnode1, svchost, 0
imlnode1, spoolsv, 0
imlnode1, cimntfy, 0
imlnode1, vcagent, 0
imlnode1, DWRCS, 0
imlnode1, ECCService_MasterAgent, 0
imlnode1, EmcPowSrv, 0
imlnode1, mstragent, 0
imlnode1, svchost, 0
imlnode1, LocalSch, 0
imlnode1, PDS, 0
imlnode1, QIPCLNT, 0
imlnode1, tmcsvc, 0
imlnode1, FrameworkService, 0
imlnode1, mstragent, 0
imlnode1, Mcshield, 0
imlnode1, VsTskMgr, 0
imlnode1, nsrexecd, 0
imlnode1, nsrpm, 0
imlnode1, portmap, 0
imlnode1, qlremote, 0
imlnode1, svchost, 0
imlnode1, snmp, 0
imlnode1, smhstart, 0
imlnode1, CpqRcmc, 0
imlnode1, cqmgserv, 0
imlnode1, cqmgstor, 0
imlnode1, mssearch, 0
imlnode1, naPrdMgr, 0
imlnode1, hpsmhd, 0
imlnode1, sysdown, 0
imlnode1, clussvc, 0
imlnode1, cpqnimgt, 0
imlnode1, wmiprvse, 0
imlnode1, cqmghost, 0
imlnode1, mnragent, 0
imlnode1, resrcmon, 0
imlnode1, hpsmhd, 0
imlnode1, svchost, 0
imlnode1, wmiprvse, 60
imlnode1, svchost, 0
imlnode1, msdtc, 0
imlnode1, sqlservr, 0
imlnode1, sqlagent, 37
imlnode1, logon.scr, 0

Here you can see that the SQL Agent process uses more CPU when running resource intensive schedule jobs in SQL Server. [Refer Fig 1.8]


[Fig 1.8]

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

cscript/nologo  listremoteprocess.vbs imlnode1 > remoteprocesscpu.csv


[Fig 1.9]

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


[Fig 2.0]

Conclusion

This article illustrated how to monitor CPU usage of running process on either a local machine or from a remote machine. Part II of this article will discuss how to monitor CPU usage of different running process on different machines and collect the information in a database.

» See All Articles by Columnist MAK



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