Introduction to System Monitoring
What is System Monitoring?
System monitoring refers to the process of continuously observing a computer system's performance, resources, and overall health. It involves tracking various metrics such as CPU usage, memory consumption, disk space, network activity, and system errors to ensure that systems operate efficiently and without interruption.
Why is System Monitoring Important?
System monitoring is crucial for several reasons:
- Ensures system reliability and availability.
- Helps in identifying and resolving issues before they affect users.
- Assists in capacity planning and resource allocation.
- Provides insights for performance tuning and optimization.
- Enhances security by detecting unusual activities.
Common System Monitoring Tools
There are numerous tools available for system monitoring, including:
- top: A command-line tool that provides a dynamic, real-time view of the system's processes.
- htop: An interactive process viewer for Unix systems.
- vmstat: Reports information about processes, memory, paging, block IO, traps, and CPU activity.
- iostat: Provides detailed I/O statistics for devices and partitions.
- sar: Collects, reports, or saves system activity information.
Using the top
Command
The top
command is one of the most commonly used tools for system monitoring. It provides a real-time overview of the system’s performance.
To start top
, simply open your terminal and type:
top - 15:29:12 up 1:23, 2 users, load average: 0.58, 0.60, 0.54 Tasks: 167 total, 1 running, 166 sleeping, 0 stopped, 0 zombie %Cpu(s): 3.5 us, 1.2 sy, 0.0 ni, 95.1 id, 0.2 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 8175508 total, 3124040 free, 2192612 used, 2858856 buff/cache KiB Swap: 2097148 total, 2097148 free, 0 used. 5558056 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 2167 user 20 0 535116 41336 27800 S 0.7 0.5 0:02.12 gnome-terminal- 2102 user 20 0 1312804 84440 65636 S 0.3 1.0 0:05.47 gnome-shell 1 root 20 0 225848 9140 6840 S 0.0 0.1 0:01.40 systemd 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root 20 0 0 0 0 S 0.0 0.0 0:00.00 ksoftirqd/0 4 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0
The top
command displays system summary information as well as a list of tasks currently being managed by the kernel. Key statistics include:
- PID: Process ID.
- USER: User who owns the process.
- PR: Priority of the process.
- NI: Nice value of the process.
- VIRT: Virtual memory used by the process.
- RES: Resident memory used by the process.
- SHR: Shared memory used by the process.
- S: State of the process (e.g., running, sleeping).
- %CPU: CPU usage by the process.
- %MEM: Memory usage by the process.
- TIME+: Total CPU time used by the process.
- COMMAND: Name of the command that started the process.
Using the htop
Command
htop
is an interactive process viewer for Unix systems. It provides a more user-friendly interface compared to top
.
To install htop
, use the following command:
To start htop
, simply open your terminal and type:
1 [||||| 5.4%] Tasks: 67, 125 thr; 1 running 2 [ 0.0%] Load average: 0.27 0.26 0.14 Mem[||||||||||||||||||||||| 1.36G/3.84G] Uptime: 01:22:35 Swp[ 0K/2.00G] PID USER PRI NI VIRT RES SHR S CPU% MEM% TIME+ Command 1745 user 20 0 506M 102M 8228 S 0.0 2.6 0:03.21 /usr/bin/gnome-shell 1624 user 20 0 162M 11M 9448 S 0.0 0.3 0:01.01 /usr/lib/systemd/systemd --user 1749 user 20 0 130M 16M 12M S 0.0 0.4 0:01.10 /usr/lib/systemd/systemd --user 1755 user 20 0 125M 7388 5440 S 0.0 0.2 0:00.30 /usr/lib/systemd/systemd --user 1802 user 20 0 121M 10M 7420 S 0.0 0.3 0:00.40 /usr/lib/systemd/systemd --user
Using the vmstat
Command
The vmstat
command reports information about processes, memory, paging, block IO, traps, and CPU activity.
To use vmstat
, open your terminal and type:
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 1353924 34456 268456 0 0 12 14 23 45 2 1 97 0 0
Key fields in the vmstat
output include:
- procs: Process statistics.
- memory: Memory statistics.
- swap: Swap statistics.
- io: IO statistics.
- system: System statistics.
- cpu: CPU statistics.
Using the iostat
Command
The iostat
command provides detailed I/O statistics for devices and partitions.
To use iostat
, open your terminal and type:
Linux 4.15.0-20-generic (hostname) 03/17/2019 _x86_64_ (4 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 4.35 0.00 1.30 0.10 0.00 94.24 Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn sda 1.03 5.60 29.97 194483 1040081
Using the sar
Command
The sar
command is used to collect, report, or save system activity information.
To use sar
, open your terminal and type:
Linux 4.15.0-20-generic (hostname) 03/17/2019 _x86_64_ (4 CPU) 12:00:01 AM CPU %user %nice %system %iowait %steal %idle 12:10:01 AM all 2.34 0.00 1.00 0.10 0.00 96.56