HOWTO: Monitor **specific* process activity using collectd

This is a brief guide on collecting info on specific processes, e.g if you suspect a specific binary is causing too much battery drain.
The info was scattered around the forum a bit, so I thought I’d consolidate it.

Introduction

We are going to use collectd.

For details about what collectd does, how to configure it, and what capabilitis there are, please see https://collectd.org/. Here we are concentrating on only one feature: gathering process statistics.

To install this, the easiest way is to install SystemDataScope from Chum, which gives nice graphs of the data collected.
If you like you can also just install collectd alone.

Configuration

collectd ships with its config file under /etc/collectd.conf. It is best you leave this file alone (even if some other guide or AI tells you to.).

What you can do instead is place configuration snippets in /etc/collectd.d/. There is an example file /etc/collectd.d/processes.conf.example which you can copy.

After changing or adding a file, do

systemctl --user restart collectd

so the daemon picks up the new configuration,

This is the example file that is currently shipping:


#
# example config for process monitoring
#
<Plugin processes>
        # monitor exact process name
        #
        #Process "lipstick"
        #Process "systemd-journald"
        #Process "systemd-logind"
        #Process "systemd-udevd"

        # monitor matching processes
        # use for anything launched through Sailjail, as those apps will have multiple processes
        # also, allows you to give a pretty name for the collection
        #
        #ProcessMatch "Systemdatascope"         "systemdatascope"
        #ProcessMatch "Fernschreiber"           "harbour-fernschreiber"
        #
        #ProcessMatch "systemd_all"             "systemd-.*"
        #ProcessMatch "fpd"                     "(sailfish|encsfa)-fpd"
        #
        # Android support: monitor most android system processes
        #ProcessMatch "com.android"             "com.android.*"
</Plugin>

Pretty self-explanatory, eh?
(As usual, lines beginning with # are comments and are ignored. So this file does nothing per default)

Duplicate this file, giving it a name of your choosing, but take care to have the name end in .config, otherwise collectd will ignore it.
Then edit the file to your liking.

Some notes:

It appears the “Process” directive does not pick up those processes (I suspect) whose names appear multiple times in the process list. This affects e.g. GUI apps which are launched through sailjail, sailfish-qml or invoker.

For those, use ProcessMatch instead of Process.

Example ps output:

nemo      2830  7111  0 08:17 ?        00:00:07 /usr/bin/sailfish-browser
nemo      7111  6486  0 Apr23 ?        00:00:03 /usr/libexec/mapplauncherd/booster-browser --systemd
nemo     14568  6486  0 09:15 ?        00:00:00 invoker -s --type=browser -G /usr/bin/sailfish-browser
nemo     14573  7111 11 09:15 ?        00:00:01 booster [browser]

So this won’t work:

 Process "sailfish-browser"

but this does:

ProcessMatch "sailfish-browser"         "sailfish-browser"

The second parameter is an regular expression to specify the match. Other examples:

 ProcessMatch "android.hw"               "android\.hardware\."
 ProcessMatch "fpd"                      "(sailfish|encsfa)-fpd"

Using the results

The easiest way to visualize the results is to use SystemDataScope.

Setting this up is beyond the scope of this small guide,

But once you have it up and running, the results of the collectd process monitoring appear in two places:

  1. Under the “Processes Overview” section
  2. Under the “Memory Overview” section

Note that after changing the collects snippet config, it is necessary to

  1. restart collectd
  2. let it run for a couple of monites so it can collect some data
  3. after this, go into the SystemDataScope settings, and execute the “Generate definitions” action.

Accessing the raw data

Data is saved as round-robin database (RRD) files.

If you would like to use other tools to process this data you can copy these files off the device from these locations:

  • collect will save its data under /tmp/collectd/$HOSTNAME while running
  • and store it at rest under /home/nemo/.local/share/collectd/$HOSTNAME.
20 Likes

Pro Tip:

If you don’t want to switch to root every time you change this, you can drop a snippet that includes more snippets from your home:

Make a file /etc/collectd.d/include-user-dir.conf

# Include user drop-ins
<Include "/home/nemo/.config/collectd/conf.d">
    Filter "*.conf"
</Include>

… and put your configs as a user into ~/.config/collectd/conf.d.

4 Likes