Table of Contents

Ubuntu - SystemD - Accounting

Systemd allows you to check how much CPU and Memory is used by a service and how many tasks are running by the service.


Example

To enable accounting for Nginx on Ubuntu 18.04.

Create a directory to store the custom systemd configuration for this service

sudo mkdir -p /etc/systemd/system/nginx.service.d/

Create the custom config file under this directory

sudo vi /etc/systemd/system/nginx.service.d/custom.conf

NOTE: The filename extension must be .conf.

…add the following lines in this file.

[Service]
CPUAccounting=true
MemoryAccounting=true
TasksAccounting=true

Reload systemd

sudo systemctl daemon-reload

NOTE: There is no need to restart Nginx.


Check Nginx status

systemctl status nginx

NOTE: This should show Tasks, Memory and CPU information.