Open Source

Graphing system activity with SAG

2 comments | 14I like it!
June 19, 2008, 09:09 AM — 

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.

Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world

I like it!
Comments

What versions of Solaris do

What versions of Solaris do you run this on? It appears that toolwait is no longer supported, at least on Solaris 10.
| reply

Patagonia Bariloche Hello! I

Patagonia
Bariloche


Hello!
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
| reply
peer-to-peer

jfruh
Apple syncing patent can't come soon enough

pasmith
New Twitter features borrow from 3rd party clients

Esther Schindler
Open Source Changes the Software Acquisition Process

mikelgan
How to set up continuous podcast play on the new iTunes

David Strom
Five important Windows 7 mobility features

sjvn
Guard your Wi-Fi for your own sake                        

Sandra Henry-Stocker
Grepping on Whole Words

 

Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325

Join the conversation here

The Daily Tip

The Daily TipQuick, practical advice for IT pros. Made fresh daily.

Hot tips:

Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.

Newsletters

Subscribe to ITWORLD TODAY and receive the latest IT news and analysis.

I would like to receive offers via email from ITworld partners.
By clicking submit you agree to the terms and conditions outlined in ITworld's privacy policy.
Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

Marketplace