0

I wish to determine the CPU/ RAM being used currently in a Windows based virtual machine or Server- for the machine itself, as well as for a specific app/web-app running on that machine.

I have with me the details of the app/web app that is being executed on that Windows machine.

The app will typically be a web app, and it can be in one of the following languages--> php/java/ruby/python/.net/node.js/perl.

Ideally I would prefer if a single command could be used to determine the pid for a app/web app that uses any of the above languages, however if a single command could be used (for all/each of the above languages) that would be ideal for me.

Another question--> how do I do something like the above, when the machine is a Windows machine? I.e.

(1) What command to use in Windows OS based machine to determine process ID (2) What command to use to use in Windows OS based machine to determine CPU/RAM used by a app/web app running in Windows based Machine. (3) Command to determine overall usage of CPU/RAM by the system (not any specific process).

Arvind
  • 6,404
  • 20
  • 94
  • 143

2 Answers2

1

Look at tasklist to find the process ID of a process.

Look at WMIC for CPU usage for the system and specific apps.

Combined with find or findstr, should give you all the info you need.

Community
  • 1
  • 1
Bali C
  • 30,582
  • 35
  • 123
  • 152
1

CPU and RAM Usage of an application or process can be fetched from a Windows OS using WMI Commands in Perl/Python/Java/VB Script

We need to execute 2 WMI Select Queries and apply CPU% utilization formula

1. To retrieve the total number of logical process

select NumberOfLogicalProcessors from Win32_ComputerSystem

2. To retrieve the values of PercentProcessorTime, TimeStamp_Sys100NS ( CPU utilization formula has be applied get the actual utilization percentage)and WorkingSetPrivate ( RAM ) minimum of 2 times with a sleep interval of 1 second

select * from Win32_PerfRawData_PerfProc_Process where IDProcess=1234

3. Apply CPU% utilization formula

CPU%= ((p2-p1)/(t2-t1)*100)/NumberOfLogicalProcessors

p2 indicated PercentProcessorTime retrieved for the second time, and p1 indicateds the PercentProcessorTime retrieved for the first time, t2 and t1 is for TimeStamp_Sys100NS.

A sample Perl code for this can be found in the link http://www.craftedforeveryone.com/cpu-and-ram-utilization-of-an-application-using-perl-via-wmi/

This logic applies for all programming language which supports WMI queries

Kaarthikeyan
  • 500
  • 5
  • 12