#!/bin/csh

# showstats
# J. Van Stonecypher  Dec 11, 1995
# script to start a xsysstat process with certain configuration options
# for each machine in a list of machines, or on the host machine if
# no others specified.
# Modifications:  J. Van; Jan 17, 1995; Added -s and -w arguments

# Defaults for variables
set machines
set width = 1

# If no parameters given, assume monitor local host
if ( $#argv == 0 ) set machines = $HOST

@ n = 0
while ( $n < $#argv )
  @ n ++
  if ( "$argv[$n]" == "-help" || "$argv[$n]" == "-h" ) then
    echo " "
    echo "USAGE: showstats [-s[how]] [-w[idth] n] [ host1 [host2 ...] ]"
    echo "       If no host is specified, the local host is assumed."
    echo " "
    echo "   Showstats sets up a xsysstats command line and executes"
    echo "   it for the specified host[s].  Each host will have three"
    echo "   graphs:  (1) the 1, 5, and 15 minute load averages,"
    echo "   (2) the CPU percentage and disk usage, and (3) the"
    echo "   number of packets transmitted and errors."
    echo "   FLAGS:  -s    Show command line for xsystats (long)"
    echo "           -w n  Make window n graphs wide (default = 1)"
    exit 1
  else if ( "$argv[$n]" == "-show" || "$argv[$n]" == "-s" ) then
    set showcmd = "T"
    echo "Command line to be executed is:"
  else if ( "$argv[$n]" == "-width" || "$argv[$n]" == "-w" ) then
    @ n ++
    set width = $argv[$n]
  else
    set machines = ( $machines $argv[$n] )
  endif
end

@ n = 0
set statargs
foreach host ( $machines )
  @ win1  = $n * 3 + 1
  @ win2  = $n * 3 + 2
  @ win3  = $n * 3 + 3
  # You know there is no way I want to try to remember this, let
  # alone type it out...
  set statargs = ( -window $win1 -type load1@$host -min 1 -color yellow -type load5@$host -min 1 -color orange -type load15@$host -min 1 -color red -window $win2 -type disk@$host -color blue -type cpu@$host -color cyan -window $win3 -type errors@$host -min 0 -color red -type packets@$host -min 0 -color green $statargs )
  @ n ++
end

# Determine window size & number of graphs in each dimension
@ x = 3 * $width
@ y = ( $#machines + $width - 1 ) / $width
@ xsize = 864 * $width
@ ysize = $y * 99

# if you want to see the final argument list...
if ( $?showcmd ) then
  echo "size = ${xsize}x${ysize} graphs: ${x}x${y}"
  echo ${statargs}
endif

# execute the command
xsysstats -geometry ${xsize}x${ysize} -split ${x}x${y} -background Black -foreground White -baseline magenta -border 2 -allnames -ruler 60 ${statargs} &