Use this open-source tool to view from one screen all the stats about CPU utilization, disk and network I/O, kernel performance, and more!
The very handy nmon utility measures live system-performance statistics on Linux, as well as gathers system information and details. The nmon project was originally an internal IBM project for monitoring AIX systems but has since been released under the GPL open-source license. The tool's original project page can be browsed from IBM's Web site. This tip looks at nmon from the Linux angle.
The statistics that can be viewed include things such as CPU utilization, disk and network I/O, kernel performance, and much more. There are two options for displaying data with the tool: You can monitor one or more active counters in the same window under an interactive mode, or you can dump the statistical data to a file, where you can analyze the results.
Obtain the nmon Tool
Depending on the Linux distribution you're using, there are a few options for obtaining nmon. If you're running either Ubuntu or RHEL/CentOS systems, packages are available for both operating systems. Ubuntu's packages are through the native repositories, and RHEL/CentOS packages exist through the third-party package provider RPMForge. If you're running a different OS, check with your vendor's package handler to see if packages exist.
If you can't locate packages, you can download the binary form directly from the Sourceforge download page. Just unpack the files and read the README file. Since this should already be in binary format, you won't have to compile any software. It should be a matter of running the tool.
Running nmon in Interactive Mode
Once nmon is installed, running the utility is as simple as typing nmon. If you'd like to display the entire help file, type nmon –h at the command line. Once nmon is launched, an interactive screen with the various options will be displayed on the screen. These are all of the options available for viewing, along with the option to display the help screen within the utility itself.
Figure 1: The interactive nmon screen shows all your options. (Click images to enlarge.)
To start displaying data, simply type the key of the performance option you want to view. The first key stroke will turn the option on; the second keystroke will turn the option off. The nice feature of this utility is that it allows multiple statistics to be displayed at once, instead of just one a time. For instance, if you wanted to view CPU, memory, disks, network, and kernel data, simply type the letters out while nmon is running (c, m, d, n, and k). You should get a nice display of all the data at once.
Figure 2: Display multiple performance options in one display.
If at any time you want to turn off one of the statistic displays, type the corresponding letter of the option. For instance, if you want to no longer see the kernel data, type k; the kernel performance data will no longer be displayed on the screen. If at any point you want to view the help information, type the h key to turn on the help legend.
Writing nmon Data to Files
When you use nmon to capture data to a file, you have to specify a time frame of seconds and snapshots options. What this does is set the amount of data snapshots incremented by your time options. As nmon runs, it snapshots the data to a CSV file to work with later on. There are two options for filenames. The first is –f, which is the default of <hostname>_YYYYMMDD_HHMM.nmon. If you want to specify a custom filename, you can use the –F switch to specify your own.
# nmon –f –s 30 –c 20
This command will launch nmon in the background and take a snapshot every 30 seconds up to 20 times. This should equate to 10 minutes of data snapshots. More options are available from the help section in regards to using nmon in this manner.
Handling nmon File Data
After the data has been dumped into the file, there are a few items you might need to handle in regards to formatting before you can open the file. If you want to open the nmon file in a regular spreadsheet program, you should probably sort the file first, as the nmon help file suggests. To do so, run the following command to sort the data and then format it in a CSV format.
# sort <hostname>_YYYMMDD_HHMM.nmon > stats.csv
Once the file is sorted, you can open up the CSV file in your spreadsheet program to work with the raw data collected.
Using nmon Data in the nmon Analyser Excel Tool
The other option you have for handling collected data is to utilize the Excel nmon analyser tool. This macro-featured Excel spreadsheet, which can be downloaded from the nmon Analyser IBM page, allows you to feed the nmon data directly into the spreadsheet. This will create some nice graphs and reports for each section of statistical data represented in the nmon file.
Figure 3: This sample report page from the nmon Analyser Excel tool displays disk activity.
A Combined System Monitor
Many Linux monitoring and performance tools exist, such as ps, top, free, vmstat, iostat, sar, and iptraf. These individual tools probably produce more detailed and granular data for the specific service or subsystem you're trying to capture performance data on. But with nmon, you'll see a very nice single screen showing many aspects of a running Linux system. This is a really nice tool to amalgamate many different screens into one active window.