Ploticus on Unix

- Visualised Performance Data out of sar: Daily Performance -

Daily sarThe following describes my approach to get actual pictures like this out of sar data.
In this case, we ask for a specific day out of the (default) 30-day history sar has. See an example of a standard sar file sadd, where dd represents a date:
12:34:02       3       7       2      89
12:35:02       2       6       0      92
12:36:02       2       6       1      90
12:37:02       3       5       0      92
If you are interested in another approach to sar data, see [link] this example.
The production of such pictures based on original sar files is triggered by an [link] html form, inoked out of a web browser connected to our Intranet. Our Webserver runs on one central server in our N/W. This server has the authorisation via .rhosts to execute remote commands as root and as web admin on all other servers. All graphs are produced on this central server so we have only one ploticus installed.
This script named invoked by [link] sarform.htm looks alike (comments are in red):


# This script prints tables out of AIX System Activity Reporting (sar).
# As option, the /var/adm/sa/xxstat files can be printed additionally.
# version 0.1 by Andreas Schmidt, 29MAY1998

echo "Content-type: text/html\n"

#Directory for Ploticus files
PLOT=/usr/local/httpd/ploticus must be adopted for your needs
OUT=/usr/local/httpd/htdocs/plots should be accessible by the web daemon

#QUERY_STRING contains:system=x&special=rep&start=#&end=#&day=#&i=#&opt=n
SYSTEM_special=`echo $QUERY_STRING|awk '{split($1,arr,"=");print arr[2]}'`
SYSTEM=`echo $SYSTEM_special|awk '{split($1,arr,"&");print arr[1]}'`
SPECIAL_start=`echo $QUERY_STRING|awk '{split($1,arr,"=");print arr[3]}'`
SPECIAL=`echo $SPECIAL_start|awk '{split($1,arr,"&");print arr[1]}'`
START_end=`echo $QUERY_STRING|awk '{split($1,arr,"=");print arr[4]}'`
START=`echo $START_end|awk '{split($1,arr,"&");print arr[1]}'`
END_day=`echo $QUERY_STRING|awk '{split($1,arr,"=");print arr[5]}'`
END=`echo $END_day|awk '{split($1,arr,"&");print arr[1]}'`
DAY_i=`echo $QUERY_STRING|awk '{split($1,arr,"=");print arr[6]}'`
DAY=`echo $DAY_i|awk '{split($1,arr,"&");print arr[1]}'`
I_opt=`echo $QUERY_STRING|awk '{split($1,arr,"=");print arr[7]}'`
I=`echo $I_opt|awk '{split($1,arr,"&");print arr[1]}'`
OPT=`echo $QUERY_STRING|awk '{split($1,arr,"=");print arr[8]}'|cut -c1`


if [ $SYSTEM = "all" ]
        SYSTEM_QUERY="a list of your servers, e.g."

echo "<html><head><meta http-equiv=expires content=0></head>"

   if [ $SPECIAL != "none" ]
        echo "<CENTER><H2>Latest <I>/var/adm/sa/$SPECIAL</I> file content on <I>$SYS</I></H2></CENTER><PRE>"
        remsh $SYS -l root cat /var/adm/sa/$SPECIAL
        case $OPT in only the system wide statistics produces graphs!
             u) sed s/%SYSTEM/$SYS/g $PLOT/sar.ptpl|\ follow the link to see the template
                sed s/%START/$START/g|sed s/%END/$END/g|sed s/%DAY/$DAY/g|\
                sed s/%I/$I/g > $PLOT/sar.p; the final inputfile for ploticus
                $PLOT/pl $PLOT/sar.p -gif ;
                STAMP=`date "+%y%m%d%H%M%S"`;
                mv $PLOT/sar.gif $OUT/sar_$SYS$STAMP.gif;
                echo "<p><a href=/plots/sar_$SYS$STAMP.gif target=_blank>\
                <img src=/plots/sar_$SYS$STAMP.gif align=right width=380 height=200></a>";;
                a small picture is displayed, with a link to the great picture in a new window
        case $OPT in
             a) OPT_TEXT="file access system routines";;
             b) OPT_TEXT="buffer activity for transfers, accesses, cache hit";;
             c) OPT_TEXT="system calls";;
             k) OPT_TEXT="kernel process activity";;
             m) OPT_TEXT="message (send/receive) and semaphore (create, use, destroy) activities";;
             q) OPT_TEXT="average number of kernel threads in run queue";;
             r) OPT_TEXT="paging statistics";;
             u) OPT_TEXT="system-wide statistics (default)";;
             v) OPT_TEXT="status of process, kernel-thread, i-node, file tables";;
             w) OPT_TEXT="system switching activity";;
             y) OPT_TEXT="tty device activity per second";;

        echo "<H2>SAR Report on <I>$SYS</I>:<BR>$OPT_TEXT</H2><PRE>" the raw sar numbers will be displayed
        remsh $SYS -l root /usr/sbin/sar -s $START:00 -e $END:01 -f /var/adm/sa/sa$DAY -i $I -$OPT
   echo "</pre><br clear=all><HR></P><p>"

The basic template sar.ptpl contains placeholders for the selected parameters. All the rest is "pure" ploticus:

#proc getdata
command: remsh %SYSTEM -l root -n sar -f /var/adm/sa/sa%DAY -s %START:00 -e %END:00 -i %I | grep -v Average |grep -v AIX |grep -v idle
        ##declare US
        ##set US = $arith(@@2+@@3)
        ##declare USW
        ##set USW = $arith(@@2+@@3+@@4)
        @@1 @@2 @@US @@USW

#proc areadef
   title: %CPU Utilization: %SYSTEM [Day: %DAY] [Avg: %I sec]
   titledetails: size=14  align=C
   rectangle: 1 1 8 4
   xscaletype: time hh:mm:ss
   xrange: 00:00:00 23:59:59
   yrange: 0 100

#proc xaxis
   stubs: inc 2 hours
   minorticinc: 30 minutes
   stubformat: hhA

#proc yaxis
   stubs: inc 10
   gridskip: min
   ticincrement: 100 1000

#proc lineplot
   xfield: 1
   yfield: 4
   linedetails: color=blue width=.5
   legendlabel: wio
   fill: blue

#proc lineplot
   xfield: 1
   yfield: 3
   linedetails: color=red width=.5
   legendlabel: sys
   fill: red

#proc lineplot
   xfield: 1
   yfield: 2
   linedetails: color=green width=.5
   legendlabel: usr
   fill: green

#proc legend
   location: max-1 max
   seglen: 0.2

The final file sar.p looks very similiar - with small changes in the beginning (in red):
#proc getdata
command: remsh -l root -n sar -f /var/adm/sa/sa14 -s 6:00 -e 21:00 -i 600 | grep -v Average |grep -v AIX |grep -v idle
        ##declare US
        ##set US = $arith(@@2+@@3)
        ##declare USW
        ##set USW = $arith(@@2+@@3+@@4)
        @@1 @@2 @@US @@USW

#proc areadef
   title: %CPU Utilization: [Day: 14] [Avg: 600 sec]
   titledetails: size=14  align=C
   rectangle: 1 1 8 4
   xscaletype: time hh:mm:ss
   xrange: 00:00:00 23:59:59
   yrange: 0 100


Now this execution file is used for ploticus, invoked by
$PLOT/pl $PLOT/sar.p -gif
The next steps move the graph to the right place with an unique name. A minimized graph is displayed together with the raw numbers, as link picture to the original picture.
See [link] this original page produced with this form and script.
That's it!
last changed: 30.07.2003
© 2003 Andreas Schmidt