ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Log CPU and memory usage

<< < (2/3) > >>

Shades:
PowerShell can do this. PowerShell comes with Windows Vista and Higher and can be downloaded from Microsoft for free for XP.

Creating some scripts is quite easy, especially when using a free IDE such as the one from Idera. (this one actually comes with example scripts that hardly need any modifying to do what you want. Run these scripts at the intervals you prefer and you should be done.

Curt:
... tools like Nagios be able ...-Ath (June 19, 2013, 10:09 AM)
--- End quote ---

http://www.nagios.com/products/nagiosxi/

old fashioned cool phone number:


Nagios XI will monitor up to seven (7) hosts/nodes with unlimited services free of charge! Just select the free license in the XI administration interface. Perfect for SOHO and personal use. Support services are not included when using a free license.
--- End quote ---

rgdot:
@worstje, There is a probably a good chance I won't get much useful information but it may also give me some idea too, especially about idle activity which according to various antivirus and antimalware software is not that kind of problem.

Thanks Ath, Shades, Curt. Will check the tools in the coming days.

Shades:
As a PowerShell beginner and with the help of a PowerShell IDE, I was able to conjure something rudimentary up.

The Mission
Find 5 running processes sorted on highest CPU load and their use of RAM (working set, not private memory):

The result
Get-Process | Sort -Property CPU -Descending | ? {$_.mainwindowtitle.length -ne 0} | Select Name, @{Label="Application"; Expression={$_.mainwindowtitle}}, @{Label="State"; Expression={"Running"}}, CPU, @{Label="Working Set"; Expression={"{0,12:n0} KB" -f ($_.WS/1kb)}} | Select -First 5
or send this data to file:
Get-Process | Sort -Property CPU -Descending | ? {$_.mainwindowtitle.length -ne 0} | Select Name, @{Label="Application"; Expression={$_.mainwindowtitle}}, @{Label="State"; Expression={"Running"}}, CPU, @{Label="Working Set"; Expression={"{0,12:n0} KB" -f ($_.WS/1kb)}} | Select -First 5 | Export-Csv -Path G:\Temp\log1.csv -NoTypeInformation


Both lines above show only a limited set of data (the requested data). If you want the standard output use the following line:
The screen layout looks like:
Handles:   NPM:   PM:   WS:   VM:   CPU:   ID:    ProcessName:
Get-Process | Where { $_.cpu -gt 0 } | Sort -Property CPU -Descending | Select -First 5
or send this data to file  (this file will show a boatload of information...be warned!):
Get-Process | Where { $_.cpu -gt 0 } | Sort -Property CPU -Descending | Select -First 5 | ConvertTo-Csv | Out-File -FilePath G:\Temp\log2.csv


Still-to-do
Filenames should contain the date-time when they are generated. Right now I'm overwriting files. Appending data could be a solution, but I did not find such an option yet in my travels.


Notes
Save the one you like into a text file with the extension .ps1 (for example: FileNameYouDesire.ps1) and use the Windows task scheduler to run this file at the desired interval. To my knowledge you can start a script in administrator mode with the Windows 7 Task scheduler (but I'll deny having said that in court ;) ).

You will get different results, depending the level of user you login with. The adminstrator account will show you everything, when using this on a limited user account you'll see the information from processes etc. associated with the current user only. That is the way how PowerShell works.

You see me use two different ways to write the data to file. The method 'Export-Csv' is not UTF8 friendly. Reading the file into LibreOffice at first showed garbage, but all data became visible after changing the characterset from 'UTF8' to 'Western-Europe (ASCII/US)'. The other method ConvertTo-Csv did not require this change when being read into LibreOffice.    

As the commands are basic, these will work on each version of PowerShell. I would upgrade the PowerShell on XP to the highest version available though. My computer at home is not (or will be) connected to the internet, so I didn't see a reason yet to upgrade to Win7 SP1. IIRC Win7 comes with PowerShell version 2, which is upgraded to version 3 after service pack 1. XP on the other hand cannot upgrade to more than version 2.

Another idea one could entertain is to write this data into the appropiate EventLogViewer from Windows itself and use that software to get an overview. Ok, I might fill my next Saturday afternoon with this puzzle.

4wd:
Still-to-do
Filenames should contain the date-time when they are generated. Right now I'm overwriting files. Appending data could be a solution, but I did not find such an option yet in my travels.-Shades (June 24, 2013, 02:20 PM)
--- End quote ---

$time = Get-Date -format yyyyMMdd-HHmm

Then add $time into your output filename, possibly:

Out-File -FilePath G:\Temp\$time.csv

I think I need to play around with PowerShell :)

Edit: Seems to work.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version