Resource Monitoring Tools

Red Hat Linux comes with a variety of resource monitoring tools. While there are more than those listed here, these tools are representative in terms of functionality. The tools we will look at are:

Let us look at each one in more detail.

free

The free command displays memory utilization data. Here is an example of its output:

             total       used       free     shared    buffers     cached
Mem:        255508     240268      15240          0       7592      86188
-/+ buffers/cache:     146488     109020
Swap:       530136      26268     503868

The Mem: row displays physical memory utilization, while the Swap: row displays the utilization of the system swap space, while the -/+ buffers/cache: row displays the amount of physical memory currently devoted to system buffers.

Since free by default only displays memory utilization information once, it is only useful for very short-term monitoring. Although free has the ability to repetitively display memory utilization figures via its -s option, the output simply scrolls, making it difficult to easily see changes in memory utilization.

TipTip
 

A better solution would be to run free using the watch command. For example, to display memory utilization every two seconds, use this command:

watch free

You can control the delay between updates by using the -n option, and can cause any changes between updates to be highlighted by using the -d option, as in the following command:

watch -n 1 -d free

For more information, see the watch man page.

The watch command will run until interrupted with [Ctrl]-[C]. Make sure you remember watch; it can come in handy in many situations.

top

While free displays only memory-related information, the top command does a little bit of everything. CPU utilization, process statistics, memory utilization — top does it all. In addition, unlike the free command, top's default behavior is to run continuously; no need for the watch command here. Here is a sample display:

11:13am  up 1 day, 31 min,  5 users,  load average: 0.00, 0.05, 0.07
89 processes: 85 sleeping, 3 running, 1 zombie, 0 stopped
CPU states:  0.5% user,  0.7% system,  0.0% nice, 98.6% idle
Mem:  255508K av, 241204K used,  14304K free,    0K shrd,   16604K buff
Swap: 530136K av,  56964K used, 473172K free                64724K cached

  PID USER   PRI  NI  SIZE  RSS SHARE STAT %CPU %MEM   TIME COMMAND
 8532 ed      16   0  1156 1156   912 R     0.5  0.4   0:11 top
 1520 ed      15   0  4084 3524  2752 S     0.3  1.3   0:00 gnome-terminal
 1481 ed      15   0  3716 3280  2736 R     0.1  1.2   0:01 gnome-terminal
 1560 ed      15   0 11216  10M  4256 S     0.1  4.2   0:18 emacs
    1 root    15   0   472  432   416 S     0.0  0.1   0:04 init
    2 root    15   0     0    0     0 SW    0.0  0.0   0:00 keventd
    3 root    15   0     0    0     0 SW    0.0  0.0   0:00 kapmd
    4 root    34  19     0    0     0 SWN   0.0  0.0   0:00 ksoftirqd_CPU0
    5 root    15   0     0    0     0 SW    0.0  0.0   0:00 kswapd
    6 root    25   0     0    0     0 SW    0.0  0.0   0:00 bdflush
    7 root    15   0     0    0     0 SW    0.0  0.0   0:00 kupdated
    8 root    25   0     0    0     0 SW    0.0  0.0   0:00 mdrecoveryd
   12 root    15   0     0    0     0 SW    0.0  0.0   0:00 kjournald
   91 root    16   0     0    0     0 SW    0.0  0.0   0:00 khubd
  185 root    15   0     0    0     0 SW    0.0  0.0   0:00 kjournald
  186 root    15   0     0    0     0 SW    0.0  0.0   0:00 kjournald
  576 root    15   0   712  632   612 S     0.0  0.2   0:00 dhcpcd

The display is separated into two main parts. The top section contains information related to overall system status, process counts, along with memory and swap utilization. The lower section displays process-level statistics, the exact nature of which can be controlled while top is running.

For more information on top, refer to the top man page.

WarningWarning
 

Although top looks like a simple display-only program, this is not the case. If you are logged in as root, it is possible to change the priority and even kill any process on your system.

Therefore, make sure you read the top man page before using it.

gnome-system-monitor — A Graphical top

If you are more comfortable with graphical user interfaces, gnome-system-monitor may be more to your liking. Like top, gnome-system-monitor displays information related to overall system status, process counts, memory and swap utilization, and process-level statistics.

However, gnome-system-monitor goes a step further by including displays disk space utilization — something that top does not do at all.

The sysstat Suite of Resource Monitoring Tools

While the previous tools may be helpful for gaining more insight into system performance over very short time frames, they are of little use beyond providing a snapshot of system resource utilization. In addition, there are aspects of system performance that cannot be easily monitored using such simplistic tools.

Therefore, a more sophisticated tool is necessary. sysstat is such a tool.

sysstat contains the following commands related to collecting I/O and CPU statistics:

iostat

Displays I/O statistics for one or more disk drives. The statistics returned can include read and write rates per second, average wait, service, and CPU utilization, and more.

mpstat

Displays CPU statistics.

However, the most versatile and sophisticated tools that are part of sysstat are those related to the sar command. Collectively these tools:

The tools that perform these tasks are:

sadc

sadc is known as the system activity data collector. It collects system resource utilization information and writes it to files in the /var/log/sa/ directory. The files are named sa<dd>, where <dd> is the current day's two-digit date.

sa1

sa1 is a script that runs sadc to perform the actual data collection, and is run by cron at regular intervals throughout the day.

sar

sar produces reports from the files created by sadc. The report files written to /var/log/sa/, and are named sar<dd>, where <dd> is the two-digit representations of the previous day's date.

sa2

sa2 is a script that uses sar to write a daily system resource utilization report. sa2 is run by cron once at the end of each day.

isag

isag graphically displays data collected by sadc.

sa

Summarizes system accounting information.

The sysstat tools should be part of every system administrator's resource monitoring tool bag.