If you need to monitor your CPU and Ram use... well, you should use ServerSuit! That's why we're here! If you wanted a more granular look on your own system though, we don't want to leave you hanging. Here's our article for the tools you can use for monitoring individual processes.
2020 update (Linux/procfs-only). Returning to the problem of process analysis frequently enough and not being satisfied with the solutions I described below originally, I decided to write my own. It's a pure-Python CLI package including its couple of dependencies (no heavy Matplotlib), can potentially plot many metrics from procfs, JSONPath queries to the process tree, has basic decimation/aggregation (Ramer-Douglas-Peucker and moving average), filtering by time ranges and PIDs, and a couple of other things.
pip3 install --user procpath
Here's an example with Firefox. This records all processes with "firefox" in their
cmdline (query by a PID would look like
'$..children[?(@.stat.pid == 42)]') 120 times one time per second.
procpath record -i 1 -r 120 -d ff.sqlite '$..children[?("firefox" in @.cmdline)]'
Plotting RSS and CPU usage of a single process (or several) out of all recorded would look like:
procpath plot -d ff.sqlite -q cpu -p 123 -f cpu.svg procpath plot -d ff.sqlite -q rss -p 123 -f rss.svg
Charts look like this (they are actually interactive Pygal SVGs):
The following addresses history graph of some sort. Python
psrecord package does exactly this.
pip install psrecord # local user install sudo apt-get install python-matplotlib python-tk # for plotting; or via pip
For single process it's the following (stopped by Ctrl+C):
psrecord $(pgrep proc-name1) --interval 1 --plot plot1.png
For several processes the following script is helpful to synchronise the charts:
#!/bin/bash psrecord $(pgrep proc-name1) --interval 1 --duration 60 --plot plot1.png & P1=$! psrecord $(pgrep proc-name2) --interval 1 --duration 60 --plot plot2.png & P2=$! wait $P1 $P2 echo 'Done'
The package provides RSS-only sampling (plus some Python-specific options). It can also record process with its children processes (see
pip install memory_profiler mprof run /path/to/executable mprof plot
By default this pops up a Tkinter-based (
python-tk may be needed) chart explorer which can be exported:
It may seem an overkill for a simple one-off test, but for something like a several-day debugging it's, for sure, reasonable. A handy all-in-one
raintank/graphite-stack (from Grafana's authors) image and
procmon.py provides an implementation.
$ docker run --rm -p 8080:3000 -p 8125:8125/udp raintank/graphite-stack
Then in another terminal, after starting target process:
$ sudo apt-get install python-statsd python-psutil # or via pip $ python procmon.py -s localhost -f chromium -r 'chromium.*'
Then opening Grafana at http://localhost:8080, authentication as
admin:admin, setting up datasource https://localhost, you can plot a chart like:
Instead of Python script sending the metrics to Statsd,
procstat input plugin) can be used to send the metrics to Graphite directly.
telegraf configuration looks like:
[agent] interval = "1s" [[outputs.graphite]] servers = ["localhost:2003"] prefix = "testprfx" [[inputs.procstat]] pid_file = "/path/to/file/with.pid"
Then run line
telegraf --config minconf.conf. Grafana part is the same, except metrics names.
pidstat (part of
sysstat package) can produce output that can be easily parsed. It's useful in case when you need extra metrics from the process(es), e.g. most useful 3 groups (CPU, memory and disk) contain: