0

While I probably need some kind of monitoring tool like mon or sysstat or something. I am looking for a way to know which tasks take the most of my memory,CPU time etc.

While I understand that each workstation/desktop PC is unique, a typical workload on one of my desktops is something like this :

  • Single user (even though the choice is there to have multiple users)
  • games - Aisleriot, kshisen
  • torrent client - qbittorrent
  • mail client - thunderbird
  • messaging clients - empathy, telegram and quasselcore and client.
  • Browser - Firefox and sometimes tor
  • desktop - MATE
  • media player - mpv most of the time

it's usually a light workload most of the time but I still see the hdd sensor lighting up which means some background tasks is going intently even though no foreground tasks are happening. While I could use top to find what tasks take most of the CPU and memory cycles, it is only for the moment. I realize I need something which I could figure out over period of time (say a day), runs in the background and produces nice enough graphs to analyze, and most of all has the raw data in user-defined location, say in /home/shirish/mon or whatever directory name is there. It is ok if it is /var/log//logs is where it keeps.

I just need to know few things :

  • Which processes take memory and CPU over time, foreground and background.
  • Which background processes take most of the CPU and memory
  • The logging is tunable, taking snaps every 2-5 minutes.

I am sure there are tools and ways in which people have done it for servers etc. but has anybody done for the above scenario ? If yes, how they went about it ?

0
//List Processes
ps -la

//Display All Network Activity
nettop

A cron task will be your most direct method.
Redirect output to your desired env/path with pipes

0

As an example, you could use cron to run the following command every X minutes:

ps --no-headers -eo "uname fname %cpu %mem" | sed -e 's/ \+/,/g' | sed "s/^/$(date --iso-8601='minutes'),/g" >> /path/to/ps.csv

Adjusting the ps fields as needed.

Then you can use the output file to graph usage using spreadsheet software, gnuplot, or something similar.

How to add to crontab

  1. Create a script to place the above command in (e.g., $HOME/bin/pscsv.sh).
  2. chmod +x /path/to/pscsv.sh
  3. crontab -e and add a line similar to */5 * * * * /path/to/pscsv.sh adjusting the periodicity to your preference (this example will run every 5 minutes).
  • could you elaborate a bit how to a. add it in cron b. what the different sed flags have you shared. The command is cryptic to understand, please elaborate. – shirish Sep 8 '16 at 7:09
  • @shirish crontab -e Refer here for info on the syntax. The first sed replaces any spaces with commas (to get a CSV format). The second sed prepends each line with the date and time (and comma, see edit). – Paul Nordin Sep 8 '16 at 8:05
  • I get a bad minute error while trying the above - ps --no-headers -eo "uname fname %cpu %mem" | sed -e 's/ \+/,/g' | sed "s/^/$(date --iso-8601='minutes'),/g" >> /home/shirish/ps.csv # from unix.stackexchange.com/questions/308269/… – shirish Sep 8 '16 at 18:56
  • the error it shows is "/tmp/crontab.lKLK8b/crontab":22: bad minute errors in crontab file, can't install. – shirish Sep 8 '16 at 18:59
  • @shirish Can you post the exact line you added in crontab? – Paul Nordin Sep 8 '16 at 20:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.