Merging NMON files and the new nmonchart

I frequently have to review performance data for customers while doing performance troubleshooting and capacity planning. Kudos to Nigel Griffiths for his excellent NMON tool and associated programs. NMON makes collecting performance data on AIX and Linux a breeze.

Analyzing that data is fairly simple. There are a variety of tools, and I have typically used the Excel based NMON Analyzer [1]. I feel that the graphs are quite good and because it is in Excel it's easy for me to annotate and share with customers. It has the option to merge data files, unfortunately due to Excel's constraints it is limited to about five days of data.

Recently I was learning about Nigel's new efforts with JSON and web based graphing, and came across his nmonchart [2] tool. This new tool has dynamically zooming graphs via javascript directly in your browser from a single file! I had to try it, and I'm very impressed.

Running it against a single file was trivial and the resulting HTML loaded into a browser without issues to view the data. However when I wanted to view several days of data in separate files there wasn't an option.

A few minutes later and some awk magic result an awk script to combine data files for reading into nmonchart.

nmonmerge.sh (Source)

#!/bin/sh

################################################################################
# Copyright 2019, Russell Adams <Russell.Adams@AdamsSystems.nl>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

######################################################################################
# Merges multiple NMON files into a single NMON file for use with tools like nmonchart
# Prints the new file to STDOUT, be sure to redirect the output
# Uses the headers from the first file ONLY, disk names and adapters might not match


# Print first file headers, stop at the first timestamp
awk 'BEGIN {p=1} ; /^ZZZZ/ {p=0} ; p {print $0}' "$1"

# Process all files, dynamically replacing all the timestamps into a new series
awk 'BEGIN {FS=OFS="," ; curr=0} ;
     $1 == "ZZZZ" {curr+=1} ;
     $2 ~ "^T[0-9]{4}" {print $1, sprintf("T%04d",curr), substr($0, index($0,$3))}' \
    "$@"

Executing this script against a series of nmon files prints a combined data stream, so make sure to redirect it to a new file. Then I can run nmonchart on it!

 % ls -l tsm_*.nmon
-rw-r--r-- 1 adamsrl adamsrl 1016001 Nov 28 13:55 tsm_130901_0000.nmon
-rw-r--r-- 1 adamsrl adamsrl 1015298 Nov 28 13:47 tsm_130902_0000.nmon
-rw-r--r-- 1 adamsrl adamsrl 1023251 Nov 28 13:47 tsm_130903_0000.nmon
-rw-r--r-- 1 adamsrl adamsrl 1022257 Nov 28 13:47 tsm_130904_0000.nmon
-rw-r--r-- 1 adamsrl adamsrl 1023189 Nov 28 13:47 tsm_130905_0000.nmon
-rw-r--r-- 1 adamsrl adamsrl 1018528 Nov 28 13:47 tsm_130906_0000.nmon
-rw-r--r-- 1 adamsrl adamsrl 1016016 Nov 28 13:47 tsm_130907_0000.nmon
-rw-r--r-- 1 adamsrl adamsrl 1014277 Nov 28 13:47 tsm_130908_0000.nmon
-rw-r--r-- 1 adamsrl adamsrl 1011618 Nov 28 13:47 tsm_130909_0000.nmon
-rw-r--r-- 1 adamsrl adamsrl  540731 Nov 28 13:47 tsm_130910_0000.nmon

% ~/scripts/nmonmerge.sh tsm_1309*.nmon > tsm_all.nmon

% nmonchart tsm_all.nmon

% ls -l tsm_all*
-rw-r--r-- 1 adamsrl adamsrl 4370035 Nov 28 14:09 tsm_all.html
-rw-r--r-- 1 adamsrl adamsrl 8073319 Nov 28 14:08 tsm_all.nmon

The resulting file loaded fine into Firefox on Linux and after allowing Google in ublock Origin for the file, the charts are lovely.

I've uploaded the combined file as an example: tsm_all.html