Graphing system activity with SAG

By Sandra Henry-Stocker  2 comments

In today's column, we're going to look at a script that turns sar data into useful little performance graphs using sag, the system activity grapher. The sag utility reads data from sar's binary files and, provided with a graphical terminal, creates a line chart showing CPU usage or some other sar data.

To use this script, graciously provided by Andrew Hay ("Sandwich Maker" to me), I started an X client on my laptop, logged in to one of my servers and invoked the script. A few seconds later, a graph of today's CPU usage opened on my screen.

Both sar and sag go a lot further back than I had suspected. While I began using sar in some release of SunOS 2.x, the commands may date back as far as AT&T System V.

#!/usr/bin/ksh -p
# xsag - graph sar data on screen
# 20041001 adh@an.bradford.ma.us

[ -n "$1" ] &&
{
       typeset -Z2 DAY=$(($(date +%d) - $1))
       (( DAY < 1 )) &&
       {
               for LASTDAY in 31 30 29 28
               do
                       [ -f /var/adm/sa/sa$LASTDAY ] &&
                       {
                               #DAY=$((LASTDAY+DAY))
                               DAY=$LASTDAY
                               break
                       }
               done
       }
       SAGFILE="-f /var/adm/sa/sa${DAY}"
}

cd /tmp

at now <<--
toolwait xterm -t -n "SAG day $DAY" -T "System Activity Graph \
 ${DAY:+- day $DAY }" -e sh -c "sag -T tek -s 00:00 -e 24:00 $SAGFILE; \
 PS1=''; export PS1; biff n 2>`tty` \
 stty 0:1805:f003f:0:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff:ff; \
 exec nice -19 sh -n"

Cut and paste the script into a file and make it executable. Much of the text in the xterm line is there to null out the tty and shell control characters while the final sh holds the xterm open after sag has completed its work so that you have a chance to look at the graph.

I also had to make sure that biff (/usr/ucb/biff) was on my search path.

Thanks to Sandwich Maker for sharing his script.

2 comments

    Anonymous 3 years ago
    PatagoniaBarilocheHello!I was wondering if first to run the script sar had to be run to colect statistics from the linux and if it is so. How do I do it?thakns for your help
    Anonymous 3 years ago
    What versions of Solaris do you run this on? It appears that toolwait is no longer supported, at least on Solaris 10.

      Add a comment

      Post a comment using one of these accounts
      Or join now
      At least 6 characters

      Note: Comment will appear soon after you have activated your account.
      Obscene/spam comments will be removed and accounts suspended.
      The information you submit is subject to our Privacy Policy and Terms of Service.

      ITworld LIVE

      Open SourceWhite Papers & Webcasts

      White Paper

      Consolidating SAP Applications to Linux on Power by IDC

      IDC studied a group of enterprises that had deployed SAP applications on IBM Power Systems servers running Linux server operating environments and had been working with those systems for several years. Learn about the results...

      White Paper

      An Interactive eGuide: Open Source

      By now, enterprises are well aware of the benefits of open-source software, which boasts a clean design, reliability, and maintainability, as well as support for standards and community values. But perhaps the biggest benefit is quality; since open-source software users have access to source code, bug fixes and enhancements come from multiple sources, often resulting in superior software.

      See more White Papers | Webcasts

      Ask a question

      Ask a Question