How to see memory usage of a service with systemctl?
How to see memory usage of a service with systemctl?
Run systemctl with the 'show' subcommand and select the MemoryCurrent property, followed by the service.
systemctl show --property=MemoryCurrent nginx.serviceThe systemctl command has multiple options to show the memory usage. With the status subcommand followed by the service, it will show the basics, including memory usage.
To retrieve the information that easier to parse, then use show followed by --property=MemoryCurrent and the service name.
Usage
The status output will include memory usage.
systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/nginx.service.d
└─override.conf
Active: active (running) since Mon 2024-06-17 17:59:45 UTC; 3h 54min ago
Docs: man:nginx(8)
Main PID: 36971 (nginx)
Tasks: 2 (limit: 1012)
Memory: 2.6M
CPU: 26ms
CGroup: /system.slice/nginx.service
├─36971 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
└─36972 "nginx: worker process" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""
For pulling in the information that can be parsed or scripted, consider retrieving the actual property from a running service.
# systemctl show --property=MemoryCurrent nginx.service | awk -F= '{print $2}'
2752512