System Monitoring Fundamentals

Level: Intermediate Module: Monitoring & High Availability 8 min read Lesson 61 of 66

Overview

  • What you’ll learn: The fundamentals of system monitoring on Linux, including CPU, memory, disk, and network metrics, and how to use essential monitoring utilities such as top, vmstat, iostat, and sar.
  • Prerequisites: Linux Fundamentals (Module 1), basic command-line proficiency
  • Estimated reading time: 18 minutes

Introduction

System monitoring is the practice of continuously observing the health and performance of a computing system. In production Linux environments, monitoring is not optional — it is the foundation on which incident response, capacity planning, and performance tuning are built. Without monitoring, administrators are essentially flying blind, reacting to outages instead of preventing them.

Effective monitoring begins with understanding what to measure. The four golden signals of system health are CPU utilization, memory consumption, disk I/O throughput, and network bandwidth. Each of these metrics tells a story about how the system is performing and where bottlenecks may be forming.

In this lesson, we will explore the theory behind system monitoring, learn to read key metrics from the Linux kernel’s virtual filesystems, and practice using the most important command-line monitoring tools available on Ubuntu Server. By the end, you will be able to diagnose common performance issues and establish a baseline for normal system behavior.

Why Monitoring Matters

Monitoring serves several critical purposes in a production environment:

  • Early warning: Detecting anomalies before they escalate into outages.
  • Capacity planning: Understanding resource trends so you can scale infrastructure proactively.
  • Root cause analysis: Providing historical data that helps pinpoint the cause of incidents.
  • SLA compliance: Proving that systems meet agreed-upon uptime and performance targets.

The cost of downtime in enterprise environments can range from thousands to millions of dollars per hour. Investing in monitoring infrastructure pays for itself many times over by reducing mean time to detection (MTTD) and mean time to recovery (MTTR).

The Four Golden Metrics

CPU Utilization

CPU utilization measures the percentage of time the processor spends executing tasks rather than sitting idle. On Linux, CPU time is divided into several categories: user time (running application code), system time (running kernel code), I/O wait (blocked waiting for disk), and idle time.

# View real-time CPU usage with top
$ top -bn1 | head -5
top - 14:23:01 up 45 days,  3:12,  2 users,  load average: 0.42, 0.38, 0.35
Tasks: 187 total,   1 running, 186 sleeping,   0 stopped,   0 zombie
%Cpu(s):  5.2 us,  2.1 sy,  0.0 ni, 91.8 id,  0.7 wa,  0.0 hi,  0.2 si,  0.0 st

# View per-CPU breakdown
$ mpstat -P ALL 1 1
Linux 5.15.0-91-generic (ubuntu-server)   03/02/2026  _x86_64_

02:23:01 PM  CPU  %usr  %nice  %sys  %iowait  %irq  %soft  %steal  %idle
02:23:02 PM  all  5.20   0.00  2.10     0.70  0.00   0.20    0.00  91.80
02:23:02 PM    0  6.00   0.00  3.00     1.00  0.00   0.00    0.00  90.00
02:23:02 PM    1  4.00   0.00  1.00     0.00  0.00   1.00    0.00  94.00

Memory Consumption

Linux memory management is nuanced. The kernel aggressively caches disk data in RAM, so “used” memory often includes cache that can be reclaimed. The key metric is available memory — the amount that can be allocated to new processes without swapping.

# View memory summary
$ free -h
              total   used   free   shared  buff/cache  available
Mem:           15Gi   4.2Gi  1.8Gi   256Mi      9.2Gi     10.5Gi
Swap:         2.0Gi     0B   2.0Gi

# Detailed memory info from /proc
$ cat /proc/meminfo | head -10
MemTotal:       16384000 kB
MemFree:         1884160 kB
MemAvailable:   11059200 kB
Buffers:          524288 kB
Cached:          8921088 kB
SwapTotal:       2097152 kB
SwapFree:        2097152 kB

Disk I/O

Disk I/O performance is measured in terms of throughput (MB/s), IOPS (I/O operations per second), and latency (time per operation). High I/O wait in the CPU metrics often indicates a disk bottleneck.

# Monitor disk I/O with iostat
$ iostat -xz 1 1
Device  r/s    w/s    rkB/s   wkB/s  rrqm/s  wrqm/s  %rrqm  %wrqm  r_await  w_await  aqu-sz  rareq-sz  wareq-sz  svctm  %util
sda     12.50  35.20  200.00  560.00  0.50    8.30    3.85   19.09  1.20     2.50     0.08   16.00     15.91     0.45   2.14

# Check disk space usage
$ df -h
Filesystem      Size  Used  Avail  Use%  Mounted on
/dev/sda1        50G   22G    26G   46%  /
/dev/sda2       200G   85G   105G   45%  /data

Network Bandwidth

Network monitoring tracks the volume and rate of data transmitted and received across network interfaces. Saturated network links cause latency spikes and packet loss.

# View network interface statistics
$ ip -s link show eth0
2: eth0:  mtu 1500 qdisc fq_codel state UP
    link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped
    8543210    65432    0       0
    TX: bytes  packets  errors  dropped
    3210987    43210    0       0

# Real-time bandwidth monitoring with nload
$ sudo apt install nload
$ nload eth0

Essential Monitoring Tools

top and htop

The top utility provides a real-time, dynamic view of running processes sorted by resource consumption. Its enhanced counterpart htop offers a more user-friendly interface with color coding, mouse support, and easier process management.

# Install htop
$ sudo apt install htop

# Run htop with tree view
$ htop --tree

# Key shortcuts in htop:
# F5 — tree view
# F6 — sort by column
# F9 — send signal to process
# F10 — quit

vmstat

The vmstat (virtual memory statistics) command reports information about processes, memory, paging, block I/O, traps, and CPU activity. It is particularly useful for spotting memory pressure and swapping.

# Report every 2 seconds, 5 iterations
$ vmstat 2 5
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0      0 1884160 524288 8396800  0    0    12    35  250  480  5  2 92  1  0
 0  0      0 1883904 524288 8396800  0    0     0    28  230  450  3  1 95  1  0

sar (System Activity Reporter)

The sar command, part of the sysstat package, collects and reports system activity data. Unlike top and vmstat, sar stores historical data, making it invaluable for trend analysis and post-incident investigation.

# Install sysstat and enable data collection
$ sudo apt install sysstat
$ sudo systemctl enable --now sysstat

# View CPU usage for today
$ sar -u
Linux 5.15.0-91-generic (ubuntu-server)   03/02/2026

12:00:01 AM  CPU  %user  %nice  %system  %iowait  %steal  %idle
12:10:01 AM  all   4.52   0.00    1.87     0.63    0.00   92.98
12:20:01 AM  all   3.98   0.00    1.56     0.45    0.00   94.01

# View memory usage history
$ sar -r

# View disk I/O history
$ sar -d

# View network throughput history
$ sar -n DEV

dstat

The dstat command combines the functionality of vmstat, iostat, and netstat into a single, color-coded display that updates in real time.

# Install dstat
$ sudo apt install dstat

# Show CPU, disk, net, and memory in one view
$ dstat -cdnm 5
----total-cpu-usage---- -dsk/total- -net/total- ------memory-usage-----
usr sys idl wai stl| read  writ| recv  send| used  free  buff  cach
  5   2  92   1   0| 200k  560k|  45k  32k| 4.2G 1.8G  512M 8.2G

Reading /proc and /sys

The Linux kernel exposes real-time system information through two virtual filesystems. The /proc filesystem provides process and kernel information, while /sys exposes device and driver data. Monitoring tools read from these filesystems internally, but understanding them directly gives you deeper diagnostic capabilities.

# Load averages (1, 5, 15 minute)
$ cat /proc/loadavg
0.42 0.38 0.35 1/187 4523

# CPU information
$ cat /proc/cpuinfo | grep "model name" | head -1
model name	: Intel(R) Xeon(R) CPU E5-2680 v4 @ 2.40GHz

# Current disk I/O stats
$ cat /proc/diskstats | grep sda

# Network interface counters
$ cat /proc/net/dev

Building a Monitoring Baseline

A baseline is a record of normal system behavior collected over a representative period — typically one to four weeks. Without a baseline, it is impossible to distinguish abnormal behavior from normal fluctuations.

Steps to establish a baseline:

  1. Enable sysstat data collection (already done above).
  2. Let the system run through typical workload cycles (daily, weekly).
  3. Use sar to extract averages and peaks for CPU, memory, disk, and network.
  4. Document the results and set alert thresholds slightly above peak values.
# Generate a summary report for a specific day
$ sar -u -f /var/log/sysstat/sa01
$ sar -r -f /var/log/sysstat/sa01
$ sar -d -f /var/log/sysstat/sa01

# Export data to CSV for analysis
$ sadf -d /var/log/sysstat/sa01 -- -u > cpu_report.csv

Key Takeaways

  • The four golden metrics — CPU, memory, disk I/O, and network — form the foundation of system monitoring.
  • top/htop provide real-time process-level views; vmstat and iostat give system-level summaries.
  • sar from the sysstat package records historical data essential for trend analysis and post-incident investigation.
  • Linux exposes all metrics through /proc and /sys virtual filesystems; monitoring tools are wrappers around these.
  • Always establish a performance baseline before setting alert thresholds.
  • The “available” field in free -h is the correct metric for usable memory, not “free”.

What’s Next

In the next lesson, we will explore Nagios Core Monitoring — a comprehensive open-source monitoring framework that builds on these fundamentals to provide centralized, automated monitoring with alerting and visualization for entire infrastructure environments.

繁體中文

概述

  • 您將學到:Linux 系統監控的基礎知識,包括 CPU、記憶體、磁碟和網路指標,以及如何使用 top、vmstat、iostat 和 sar 等基本監控工具。
  • 先決條件:Linux 基礎(模組 1)、基本命令列操作能力
  • 預計閱讀時間:18 分鐘

介紹

系統監控是持續觀察計算系統健康狀況和效能的實踐。在生產環境的 Linux 系統中,監控不是可選的——它是事件回應、容量規劃和效能調整的基礎。沒有監控,管理員基本上是盲目飛行,只能對故障做出反應而無法預防。

有效的監控始於了解要測量什麼。系統健康的四個黃金指標是 CPU 使用率、記憶體消耗、磁碟 I/O 吞吐量和網路頻寬。這些指標中的每一個都講述了系統效能及潛在瓶頸的故事。

在本課程中,我們將探討系統監控背後的理論,學習從 Linux 核心的虛擬檔案系統讀取關鍵指標,並練習使用 Ubuntu Server 上最重要的命令列監控工具。

為什麼監控很重要

監控在生產環境中有幾個關鍵用途:

  • 預警:在異常升級為故障之前檢測到它們。
  • 容量規劃:了解資源趨勢以便主動擴展基礎設施。
  • 根因分析:提供有助於確定事件原因的歷史數據。
  • SLA 合規:證明系統滿足約定的正常運行時間和效能目標。

四大黃金指標

CPU 使用率

CPU 使用率衡量處理器執行任務而非閒置的時間百分比。在 Linux 上,CPU 時間分為幾個類別:使用者時間(執行應用程式碼)、系統時間(執行核心碼)、I/O 等待(等待磁碟)和閒置時間。

# 使用 top 查看即時 CPU 使用率
$ top -bn1 | head -5

# 查看每個 CPU 的分解
$ mpstat -P ALL 1 1

記憶體消耗

Linux 記憶體管理很精細。核心會積極地將磁碟數據快取在 RAM 中,因此「已使用」的記憶體通常包括可回收的快取。關鍵指標是可用記憶體。

# 查看記憶體摘要
$ free -h

# 從 /proc 查看詳細記憶體資訊
$ cat /proc/meminfo | head -10

磁碟 I/O

磁碟 I/O 效能以吞吐量(MB/s)、IOPS(每秒 I/O 操作數)和延遲(每次操作時間)來衡量。

# 使用 iostat 監控磁碟 I/O
$ iostat -xz 1 1

# 檢查磁碟空間使用率
$ df -h

網路頻寬

網路監控追蹤在網路介面上傳輸和接收的數據量和速率。

# 查看網路介面統計
$ ip -s link show eth0

基本監控工具

top 和 htop

top 工具提供按資源消耗排序的即時動態進程視圖。其增強版 htop 提供更友好的介面。

$ sudo apt install htop
$ htop --tree

vmstat

vmstat(虛擬記憶體統計)命令報告進程、記憶體、分頁、區塊 I/O、陷阱和 CPU 活動的資訊。

$ vmstat 2 5

sar(系統活動報告器)

sar 命令是 sysstat 套件的一部分,收集和報告系統活動數據。與 topvmstat 不同,sar 儲存歷史數據,對趨勢分析和事後調查非常寶貴。

$ sudo apt install sysstat
$ sudo systemctl enable --now sysstat
$ sar -u
$ sar -r
$ sar -n DEV

讀取 /proc 和 /sys

Linux 核心通過兩個虛擬檔案系統暴露即時系統資訊。/proc 提供進程和核心資訊,/sys 暴露裝置和驅動程式數據。

$ cat /proc/loadavg
$ cat /proc/cpuinfo | grep "model name" | head -1
$ cat /proc/net/dev

建立監控基線

基線是在代表性時期(通常為一到四週)內收集的正常系統行為記錄。沒有基線,就無法區分異常行為和正常波動。

重點總結

  • 四大黃金指標——CPU、記憶體、磁碟 I/O 和網路——構成系統監控的基礎。
  • top/htop 提供即時進程級視圖;vmstatiostat 提供系統級摘要。
  • sysstat 套件中的 sar 記錄對趨勢分析和事後調查至關重要的歷史數據。
  • Linux 通過 /proc/sys 虛擬檔案系統暴露所有指標。
  • 在設定警報閾值之前,務必建立效能基線。
  • free -h 中的「available」欄位是可用記憶體的正確指標,而非「free」。

下一步

在下一課中,我們將探討 Nagios Core 監控——一個全面的開源監控框架,建立在這些基礎之上,為整個基礎設施環境提供集中化、自動化的監控,包含警報和視覺化功能。

日本語

概要

  • 学習内容:Linux システム監視の基礎(CPU、メモリ、ディスク、ネットワークのメトリクス)と、top、vmstat、iostat、sar などの基本的な監視ツールの使用方法。
  • 前提条件:Linux 基礎(モジュール1)、基本的なコマンドライン操作能力
  • 推定読了時間:18分

はじめに

システム監視とは、コンピューティングシステムの健全性とパフォーマンスを継続的に観察する実践です。本番環境の Linux システムにおいて、監視はオプションではなく、インシデント対応、キャパシティプランニング、パフォーマンスチューニングの基盤です。監視がなければ、管理者は盲目飛行しているのと同じで、障害を予防するのではなく、障害に対応するだけになります。

効果的な監視は、何を測定するかを理解することから始まります。システム健全性の4つのゴールデンシグナルは、CPU 使用率、メモリ消費量、ディスク I/O スループット、ネットワーク帯域幅です。

このレッスンでは、システム監視の背景にある理論を探り、Linux カーネルの仮想ファイルシステムからキーメトリクスを読み取る方法を学び、Ubuntu Server で最も重要なコマンドライン監視ツールを使用する練習をします。

なぜ監視が重要か

  • 早期警告:異常が障害に発展する前に検出する。
  • キャパシティプランニング:リソースの傾向を把握し、インフラを積極的にスケーリングする。
  • 根本原因分析:インシデントの原因特定に役立つ履歴データを提供する。
  • SLA 準拠:システムが合意された稼働時間とパフォーマンス目標を満たしていることを証明する。

4つのゴールデンメトリクス

CPU 使用率

CPU 使用率は、プロセッサがアイドル状態ではなくタスクを実行している時間の割合を測定します。Linux では、CPU 時間はユーザー時間、システム時間、I/O 待ち、アイドル時間に分類されます。

$ top -bn1 | head -5
$ mpstat -P ALL 1 1

メモリ消費量

Linux のメモリ管理は繊細です。カーネルはディスクデータを積極的に RAM にキャッシュするため、「使用済み」メモリにはしばしば回収可能なキャッシュが含まれます。重要なメトリクスは利用可能メモリです。

$ free -h
$ cat /proc/meminfo | head -10

ディスク I/O

ディスク I/O パフォーマンスは、スループット(MB/s)、IOPS(1秒あたりの I/O 操作数)、レイテンシ(操作あたりの時間)で測定されます。

$ iostat -xz 1 1
$ df -h

ネットワーク帯域幅

ネットワーク監視は、ネットワークインターフェースを通じて送受信されるデータの量と速度を追跡します。

$ ip -s link show eth0

基本的な監視ツール

top と htop

top はリソース消費量順にソートされたプロセスのリアルタイム動的ビューを提供します。強化版の htop はより使いやすいインターフェースを提供します。

$ sudo apt install htop
$ htop --tree

vmstat

vmstat(仮想メモリ統計)コマンドは、プロセス、メモリ、ページング、ブロック I/O、トラップ、CPU アクティビティに関する情報をレポートします。

$ vmstat 2 5

sar(システムアクティビティレポーター)

sar コマンドは sysstat パッケージの一部で、システムアクティビティデータを収集・レポートします。topvmstat と異なり、sar は履歴データを保存するため、傾向分析やインシデント後の調査に非常に有用です。

$ sudo apt install sysstat
$ sudo systemctl enable --now sysstat
$ sar -u
$ sar -r
$ sar -n DEV

/proc と /sys の読み取り

Linux カーネルは2つの仮想ファイルシステムを通じてリアルタイムのシステム情報を公開しています。/proc はプロセスとカーネルの情報を、/sys はデバイスとドライバーのデータを提供します。

$ cat /proc/loadavg
$ cat /proc/cpuinfo | grep "model name" | head -1
$ cat /proc/net/dev

監視ベースラインの構築

ベースラインとは、代表的な期間(通常1~4週間)にわたって収集された正常なシステム動作の記録です。ベースラインがなければ、異常な動作と正常な変動を区別することは不可能です。

重要ポイント

  • 4つのゴールデンメトリクス — CPU、メモリ、ディスク I/O、ネットワーク — がシステム監視の基盤を形成する。
  • top/htop はリアルタイムのプロセスレベルビューを提供し、vmstatiostat はシステムレベルのサマリーを提供する。
  • sysstat パッケージの sar は傾向分析とインシデント後調査に不可欠な履歴データを記録する。
  • Linux は /proc/sys 仮想ファイルシステムを通じてすべてのメトリクスを公開している。
  • アラートしきい値を設定する前に、必ずパフォーマンスベースラインを確立する。
  • free -h の「available」フィールドが使用可能メモリの正しいメトリクスであり、「free」ではない。

次のステップ

次のレッスンでは、Nagios Core 監視について学びます。これらの基礎の上に構築された包括的なオープンソース監視フレームワークで、インフラストラクチャ環境全体に対する集中化・自動化された監視、アラート、可視化を提供します。

You Missed