Systemd allows you to check how much CPU and Memory is used by a service and how many tasks are running by the service.
To enable accounting for Nginx on Ubuntu 18.04.
sudo mkdir -p /etc/systemd/system/nginx.service.d/
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
sudo systemctl daemon-reload
NOTE: There is no need to restart Nginx.
systemctl status nginx
NOTE: This should show Tasks, Memory and CPU information.