lxc-top
Monitor LXC container resource usage
TLDR
Start lxc-top
Adjust update interval
Sort by [n]ame, [c]pu use, [b]lock I/O, [m]emory, or [k]ernel memory
SYNOPSIS
lxc-top [OPTIONS]
PARAMETERS
-h, --help
Displays a help message and exits.
-V, --version
Shows version information and exits.
-p, --processes
Displays a detailed view showing individual processes running within selected containers, along with their resource consumption.
-d
Sets the delay in seconds between screen updates. The default is typically 3 seconds.
-i
An alias for the --delay option, specifying the refresh interval.
-m
Specifies the unit for displaying memory usage. Possible values include M (megabytes) or G (gigabytes).
-n
Specifies the unit for displaying network I/O. Possible values include K (kilobytes), M (megabytes), or G (gigabytes).
-s
Defines the column by which the container list should be sorted. Common sort keys include cpu, mem, net_rx, net_tx, or name.
-c, --show-cpu-percent
Ensures CPU usage is displayed as a percentage, rather than raw jiffies. This is often the default behavior.
DESCRIPTION
lxc-top provides a real-time, interactive display of resource usage for Linux Containers (LXC) running on the host system. Similar to the top command for processes, lxc-top focuses specifically on containers, showing their CPU, memory, network I/O, and process counts. It leverages cgroups (control groups) to aggregate resource consumption at the container level. Users can view a summary of all running containers, sort them by various metrics, and even drill down to see individual processes within a selected container, offering a comprehensive overview of container performance and resource utilization. This tool is essential for system administrators and developers managing LXC environments, helping them identify resource-intensive containers and optimize system performance.
CAVEATS
lxc-top relies heavily on the kernel's cgroup subsystem for accurate resource data. Inaccurate or incomplete data may be displayed if cgroups are not properly configured or if LXC containers operate in a non-standard environment.
It typically requires root privileges or sufficient capabilities (like CAP_SYS_ADMIN) to access the necessary cgroupfs information.
INTERACTIVE COMMANDS
While running, lxc-top supports several interactive keyboard commands to control its display:
q: Quit the application.
r: Reverse the current sort order.
s: Change the column used for sorting (prompts for new key).
d: Change the update delay (prompts for new delay in seconds).
m: Toggle or select the memory unit.
n: Toggle or select the network I/O unit.
p: Toggle the detailed process view within containers (if not already enabled via command-line option).
DEPENDENCIES AND PERMISSIONS
lxc-top requires the lxc user space tools to be installed. It critically depends on the cgroup filesystem, so a Linux kernel with cgroup support enabled and mounted is essential. For proper operation and access to all resource metrics, it generally requires root privileges or processes running with the CAP_SYS_ADMIN capability.
HISTORY
lxc-top is an integral part of the LXC (Linux Containers) project, which began development around 2008-2009. As LXC emerged as a lightweight virtualization solution, the need for dedicated container monitoring tools became evident. lxc-top was developed to provide a top-like interface specifically tailored for LXC, leveraging the kernel's cgroup subsystem to aggregate and present resource usage per container. Its development has closely tracked the LXC project's releases, reflecting updates in cgroup v1/v2 support and general LXC lifecycle management. It remains a specialized utility for users deeply embedded in the LXC ecosystem.