Monitoring the Load in Linux
uptimeIf you'd like quick information about the amount of work your system is doing, look no further than
uptime. This handy little program displays the current time, system uptime, number of current users, and load averages over the last 1, 5, and 15 minutes.
Everything is pretty strait forward, except for load averages. A load average is the average number of processes that are using the CPU or waiting for something such as IO or even the processor itself, among other things.
Here's an example of uptime in action:
$ uptime
14:14:38 up 4:13, 2 users, load average: 0.30, 0.44, 0.44Here, the time was 2:14pm. My system has been up (running) for 4 hours and 13 minutes. There are currently two users logged in, and for about a third of the past 1, 5, and 15 minutes, one process on average has been using my CPU or waiting for something else.
topWhile
uptime specifies the amount of work one's system is doing,
top describes just what work is being done. Here's an example session of
top, exited with q for quit:
top - 11:16:42 up 1:34, 3 users, load average: 0.63, 0.65, 0.40
Tasks: 108 total, 3 running, 105 sleeping, 0 stopped, 0 zombie
Cpu(s): 15.2%us, 1.7%sy, 0.0%ni, 82.9%id, 0.0%wa, 0.0%hi, 0.2%si, 0.0%st
Mem: 450816k total, 443132k used, 7684k free, 28236k buffers
Swap: 497972k total, 34704k used, 463268k free, 99940k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
6176 samuel 16 0 266m 96m 27m R 10.2 21.9 5:22.29 firefox-bin
6310 samuel 15 0 135m 35m 19m S 3.6 8.1 1:22.64 rhythmbox
5187 root 15 0 212m 51m 7560 R 1.7 11.6 2:56.52 Xorg
6206 samuel 15 0 81316 20m 11m S 0.2 4.6 0:03.92 gnome-terminal
6426 samuel 15 0 2368 1156 884 R 0.2 0.3 0:00.04 top
1 root 18 0 2948 1852 532 S 0.0 0.4 0:01.21 initNotice the first line is the output of
uptime? The column headings a little way down, starting at the left, describe the Process ID of a given process, the USER who appears to own the process, it's priority, nice value (modifyable priority), amount of VIRTual memory in use, physical ram RESources in use, SHaRed ram in use, process State, percent of the CPU in use, percent of ram MEMory in use, minutes:seconds.hundredths of seconds that the process has used the processor for, and the name of the process itself. To learn more about what top can do for you be sure to press h while it's running to get a list of hotkeys. If you make any changes, you may wish to use the W hotkey to save them for next time.
dstatdstat provides handware usage statistics for a variety of systems as one can see in the following example:
$ dstat
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read writ| recv send| in out | int csw
24 6 68 2 0 0 | 95k 27k| 0 0 | 0 10k| 422 1091Regarding the CPU, we can see usage based on the user, system, and the amount of the processor that isn't being used at all. We can see disk, network, paging, and system access as well.
freeIf you just want to know how much ram is free and swap space (the overflow of ram that is stored on disk),
free is the command to use! The only extra switch I recommand is
-m which displays the output in megabytes instead of the kilobytes which is the default.
total used free shared buffers cached
Mem: 440 432 8 0 24 167
-/+ buffers/cache: 240 199
Swap: 486 0 486In case you're wondering the shared column is obsolete. Buffers just refers to the memory in use by the Linux kernel itself.
pstreepstree is a great little command that displays a tree of the child processes created by each parent process. Here's an example:
init─┬─NetworkManager───3*[{NetworkManager}]
├─NetworkManagerD
├─acpid
...