Beginners Guide: Monitoring Linux System Command

Linux comes with many built-in commands to monitor the system. You can check your system performance with these tools — from CPU load, memory usage, network traffic, and more. From these monitoring tools you can find out what is causing the server to not perform normally.

Below are the tools to check your Linux system health:

1. top

top (table of processes) command will show you a dynamic real-time view of a running system, i.e. actual process activity. It updates every 5 seconds.

top hot keys:
t — Displays summary information on and off.
m — Displays memory information on and off.
A — Sorts the display by top consumers of various system resources. Useful for quick identification of performance-hungry tasks on a system.
f — Enters an interactive configuration screen for top. Helpful for setting up top for a specific task.
o — Enables you to interactively select the ordering within top.
r — Issues renice command.
k — Issues kill command.
z — Turn on or off color/mono

2. netstat

netstat command will show network statistics. You can find out total established connections, closing connections, SYN and FIN bits, and much more. You can also display summary statistics for each protocol using netstat.

You can find out if your server is under attack with netstat. See my previous post here.

3. vmstat

vmstat is a command for monitoring system activity, hardware, and system information.
To show processes, memory, paging, block IO, traps, and CPU activity reports:

vmstat

Sample output:

procs ------memory---------- --swap-- ---io-- --system-- ----cpu----
r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs    us sy id wa
3  0      0 2485120 621952 2415368  0    0     0     0    0       1 32  0 68  0

4. w

w is a command to show the real-time log activity for logged-in users.
Command:

w [username]

Sample:

w ivan

5. ps

ps is a command to display the running processes.
To show all processes:

ps -A
ps ax
ps axu

Show long format output:

ps -Al

Show threads:

ps -AlFH

See processes run by user:

ps -U [username] -u [username] u

Show the top 10 memory-consuming processes:

ps -auxf | sort -nr -k 4 | head -10

Show the top 10 CPU-consuming processes:

ps -auxf | sort -nr -k 3 | head -10

6. free

free is a command to show a memory report. It will show the total amount of free and used physical and swap memory in the system, as well as the buffers used by the kernel.
Usage:

free

7. iostat

iostat is a command to show CPU statistics and input/output statistics for devices, partitions, and network filesystems (NFS).
Usage:

iostat

8. mpstat

mpstat is a command to show multiprocessor usage.
To average CPU utilization per processor:

mpstat -P ALL

9. pmap

pmap is a command to show the memory map of a process.
Usage:

pmap -d PID

Sample to show memory information for process ID 14243:

pmap -d 14243

10. iptraf

iptraf is a command to show real-time network statistics with an interactive colorful text-based UI. What iptraf can provide:

  • Network traffic statistics by TCP connection
  • IP traffic statistics by network interface
  • Network traffic statistics by protocol
  • Network traffic statistics by TCP/UDP port and by packet size
  • Network traffic statistics by Layer 2 address

Sample:

iptraf2