Plesk-cgroups Plugin

This plugin reports memory, disk I/O and CPU usage for each Linux user, based on the user's systemd cgroup (user-<uid>.slice). It is useful on shared hosting and Plesk servers, where you want to know which user or subscription is using the resources, and it shows the same numbers that cgroup-based resource limits are applied to.

Reported Metrics

The plugin reports one entry for each user slice, under /sys/fs/cgroup/.../user.slice/user-<uid>.slice. Each entry contains:

MetricDescription
uidNumeric user ID.
usernameUser name. Missing if the user ID has no name.

On servers with cgroup v2 (most current distributions):

MetricDescription
memory.currentMemory used by the user's processes, in bytes.
io.statDisk I/O per device (major:minor, for example 8:0), per second: rbytes and wbytes (bytes read and written), rios and wios (read and write operations), dbytes and dios (discards).
cpu.statCPU use per second: usage_usec, user_usec and system_usec (microseconds of CPU time per second), plus the throttling counters if CPU limits are set (nr_periods, nr_throttled, throttled_usec).

On servers with cgroup v1, the equivalent values are reported:

MetricDescription
memory.usage_in_bytesMemory used by the user's processes, in bytes.
blkio.throttle.io_service_bytesDisk I/O per device, in bytes per second, split into Read, Write, Sync, Async and Total.
cpuacct.statCPU time per second in the user and system modes, in clock ticks.

Memory is the current value. I/O and CPU values are rates per second, calculated from the change since the previous run, so the first value after the agent starts is 0. If a counter resets, for example after a user's slice is recreated, the rate is calculated from zero.

Requirements

  • Linux with systemd and the cgroup file system mounted at /sys/fs/cgroup.
  • Python 3 for the agent.
  • The cgroup controllers for what you want to see (memory, I/O, CPU) enabled for the user slices. If a controller is off, its metric is missing. The plugin doesn't turn controllers on.
  • A user only has a slice while they have a session or running processes. Users without one don't appear.

The plugin only reads files under /sys/fs/cgroup, so it doesn't need root or a sudoers rule.

Configure the plugin

Add the following lines to the /etc/agent360-custom.ini file:

[plesk-cgroups]
enabled = yes
interval = 60
OptionDefaultDescription
enablednoSet to yes to turn the plugin on.
interval60How often the plugin runs, in seconds. A shorter interval gives more detailed I/O and CPU rates.

There are no other options. The plugin monitors all user slices on the server.

Test the plugin

Run the following command:

sudo -u agent360 agent360 test plesk-cgroups

The output should list the user slices with their metrics. Because I/O and CPU values are rates, run the test twice, a minute apart, to see non-zero values. Then restart the agent for the change to take effect:

service agent360 restart

Troubleshooting

  • The output is empty. There are no user slices. Check ls -d /sys/fs/cgroup/user.slice/user-*.slice on cgroup v2, or /sys/fs/cgroup/systemd/user.slice/user-*.slice on cgroup v1. Slices only exist for users with active sessions or processes, and only on systems that use systemd.
  • A metric is missing. The matching cgroup controller isn't enabled for the user slice. Check cat /sys/fs/cgroup/user.slice/cgroup.controllers and enable the memory, io or cpu controller in systemd (for example with MemoryAccounting=yes, IOAccounting=yes and CPUAccounting=yes).
  • I/O and CPU values are 0. These values are calculated from the previous run. Wait for the next interval.
  • The plugin does not start. The plugin needs Python 3. Check the Python version the agent uses.
  • No data in the dashboard. Make sure the [plesk-cgroups] section is in /etc/agent360-custom.ini, enabled = yes, and that you restarted the agent.

Did this page help you?