Mastering 'systemd-cgtop' (with examples)
- Linux
- December 17, 2024
The systemd-cgtop
command is a powerful performance monitoring tool available on Linux systems equipped with systemd. It provides a dynamic real-time view of control groups’ resource usage, such as CPU, memory, and I/O operations. By using systemd-cgtop
, administrators can efficiently monitor and manage system resources to ensure optimal performance and identify potential bottlenecks. Here, we explore the various use cases of this command, providing insights into its practical applications.
Use case 1: Starting an interactive view
Code:
systemd-cgtop
Motivation:
Starting the interactive view helps system administrators quickly assess the current performance of various control groups without any configuration changes. This allows for a broad overview of system resource consumption and is particularly useful for troubleshooting or routine checks.
Explanation:
Running systemd-cgtop
with no additional arguments launches the tool in its default interactive mode. This mode provides a constantly updated display of system resource usage, ranked by control groups.
Example Output:
Control Group Tasks %CPU Memory Input/s Output/s
/ 104 14.9 250M -- --
/user.slice 12 4.5 100M -- --
/system.slice 10 10.4 150M -- --
Use case 2: Changing the sort order
Code:
systemd-cgtop --order=cpu
Motivation:
By changing the sort order, users can focus on a specific type of resource usage. If high CPU usage is suspected to be the cause of system slowdowns, this command sorts control groups by CPU consumption, allowing administrators to target and mitigate the most resource-intensive processes.
Explanation:
The --order=cpu
argument specifies that control groups should be organized based on their CPU usage. Alternatives like memory
, path
, tasks
, or io
can also be specified to sort by those criteria.
Example Output:
Control Group Tasks %CPU Memory Input/s Output/s
/system.slice 10 10.4 150M -- --
/user.slice 12 4.5 100M -- --
/ 104 0.0 250M -- --
Use case 3: Showing CPU usage by time instead of percentage
Code:
systemd-cgtop --cpu=time
Motivation:
Switching to time-based CPU usage can provide a more granular understanding of how frequently CPUs are used over certain periods. This is helpful when trying to gauge resource efficiency or understand the time distribution of workloads.
Explanation:
The --cpu=time
argument instructs systemd-cgtop
to display CPU usage in terms of time (e.g., seconds used) instead of percentages. This offers a different perspective on how CPU resources are being consumed over time.
Example Output:
Control Group Tasks CPU Time Memory Input/s Output/s
/system.slice 10 50s 150M -- --
/user.slice 12 20s 100M -- --
Use case 4: Changing the update interval
Code:
systemd-cgtop --delay=5s
Motivation:
Modifying the update interval allows users to control how frequently the displayed data refreshes. A faster interval is beneficial for real-time monitoring during performance testing, whereas a slower interval reduces system overhead during prolonged observation.
Explanation:
The --delay=5s
argument sets the update interval to 5 seconds. Users can choose different time units such as ms
for milliseconds or min
for minutes to customize how often the statistics are updated.
Example Output:
Control Group Tasks %CPU Memory Input/s Output/s
/system.slice 10 6.0 150M -- --
/user.slice 12 2.0 100M -- --
Use case 5: Counting only userspace processes
Code:
systemd-cgtop -P
Motivation:
Excluding kernel threads from the displayed statistics helps in analyzing resources consumed purely by userspace applications. This can be important for scenarios focused strictly on understanding user-initiated loads versus system-internal operations.
Explanation:
The -P
option limits the counting to processes running in userspace, effectively ignoring kernel threads. This enables users to zero in on those processes which are directly instantiated by user commands or applications.
Example Output:
Control Group Tasks %CPU Memory Input/s Output/s
/user.slice 10 2.5 70M -- --
Conclusion:
The systemd-cgtop
tool is an indispensable command for Linux system administrators looking to monitor and manage system resource usage effectively. Through various options and configurations, it offers deep insights into control groups, helping identify and address performance issues promptly. By understanding and manipulating its outputs using the examples and use cases demonstrated above, users can enhance their system monitoring and troubleshooting efficiency.