systemd resource accounting is a feature that allows you to monitor and control the usage of system resources, such as CPU and memory, by individual services and processes.

One of the most common types of resource accounting is CPU accounting, which allows you to measure the amount of CPU time used by a specific service or process. This is accomplished by using the CPUAccounting=true option in the service’s systemd unit file.

For example, to enable CPU accounting for the Apache web server, you would add the following line to the /etc/systemd/system/httpd.service file:

[Service]
CPUAccounting=true

Another type of resource accounting is Memory accounting, which allows you to measure the amount of memory used by a specific service or process. This is accomplished by using the MemoryAccounting=true option in the service’s systemd unit file.

For example, to enable Memory accounting for the Apache web server, you would add the following line to the /etc/systemd/system/httpd.service file:

[Service]
MemoryAccounting=true

You can also enable it systemwide by adding the following to /etc/systemd/system.conf:

DefaultCPUAccounting=yes
DefaultMemoryAccounting=yes

You can use the systemd-cgtop command to display the usage of system resources in real-time. This command shows the usage of CPU, memory, and I/O by all services and processes on the system.

It’s important to note that the resource accounting feature is not enabled by default, and it’s necessary to configure it explicitly in the unit files. Additionally, resource accounting can consume additional resources and may have an impact on the performance of the system.