温馨提示×

Debian Swap监控工具

小樊
45
2025-10-21 06:06:03
栏目: 智能运维

Common Command-Line Tools for Monitoring Swap in Debian

  • free: The most straightforward tool to view memory and swap usage. Run free -h to display totals, used/available space in a human-readable format (e.g., GB/MB). The output includes a dedicated “Swap” line showing key metrics.
  • top/htop:
    • top: A real-time system monitor that shows swap usage in the “KiB Swap” section (total, used, free). It updates dynamically and allows sorting processes by swap usage (press Shift + M).
    • htop: An enhanced version of top with a more intuitive interface (color-coded, scrollable). Install via sudo apt install htop, then run htop to view swap stats and process-level details.
  • vmstat: Reports virtual memory statistics, including swap operations. Use vmstat -s | grep swap to get total/used/free swap values, or vmstat 1 5 to refresh stats every second for 5 iterations.
  • swapon: Manages and displays enabled swap devices/files. Run sudo swapon --show to list active swap entries (name, type, size, used space, priority). Combine with -s (swapon -s) for a detailed table.
  • sar: Part of the sysstat package (install via sudo apt install sysstat). Collects historical/system activity data; use sudo sar -r 1 10 to report swap usage every second for 10 iterations (shows “kbmemfree”, “kbbuffers”, “kbcached”, etc.).
  • /proc/swaps: A virtual file containing real-time swap details. Run cat /proc/swaps to see active swap devices/files, their sizes, used space, and priority.

Graphical Tools for Swap Monitoring

  • gnome-system-monitor/kde-system-monitor: Built-in GUI tools for monitoring system resources. Install via sudo apt install gnome-system-monitor (Debian default) or sudo apt install kde-system-monitor (KDE users). They provide visual graphs for memory/swap usage and process lists.
  • conky: A lightweight, customizable desktop widget. Install via sudo apt install conky, then configure .conkyrc to display swap stats (e.g., Swap: ${swap}M / ${swap_total}M). It runs on the desktop and updates in real time.
  • netdata: A powerful, web-based monitoring tool. Install via sudo apt install netdata, then access http://localhost:19999 in a browser. It provides interactive dashboards for swap usage, memory trends, and process-level metrics.

0