[mrtg] Solaris

Neil Calvert ncalvert at cabletron.com
Thu Nov 11 22:43:28 MET 1999


Hi all,

Since a few people have asked, I'm posting a couple scripts that I have
for Solaris. In all cases, I use the SNMP agent too - so to get system
uptime I use the RouterUptime facility in the MRTG Config file. I
manually put in the system name. To enable rsh on various sun machines
consult the man pages. For Solaris an entry in the /etc/hosts.equiv file
of the form

<remote machine calling script> <remote user calling script>

is usually enough.

Diskspacer
-----------

This script graphs 2 variables gotten from df -k - it will graph 2
separate partitions, at least that's the idea. You have to call it from
the MRTG config file with the command

`rsh <machine> <path to script> | sed -e s/%//`

to strip off the % symbols. You could probably code this into the script
but I haven't got around to it yet.

#!/bin/ksh
#This script outputs the percentage of disk space used by two
partitions.
#Replace 'Linenumberpart1goeshere' with the line number that partition 1
appears on on a df -k list. Replace 'Linenumberp
art2goeshere' with the line number that partition 2 appears on on a
df -k list.
diskspacearray[0]=`df -k | awk 'NR == Linenumberpart1goeshere { print
$5 }`
diskspacearray[1]=`df -k | awk 'NR == Linenumberpart2goeshere { print
$5 }`
echo Uptime #MRTG will get uptime from a different source
echo machinenamegoeshere #print out machine name for MRTG to put on the
page

Vmstatscript
-------------

#!/bin/ksh
#This provides output of free swap space and free memory in megabytes
vmarray[0]=`vmstat 1 2 | awk 'NR == 4 { printf "%d\n", $5 / 1000}'` #
Free Memory
vmarray[1]=`vmstat 1 2 | awk 'NR == 4 { printf "%d\n", $4 / 1000}'` #
Free Swap
echo ${vmarray[0]}
echo ${vmarray[1]}
echo Uptime #MRTG will get uptime from a different source
echo machinenamegoeshere #print out machine name for MRTG to put on the
page

Vmstatscript2
--------------

#!/bin/ksh
#This script graphs used CPU (system + user) vs idle CPU
vm2array[0]=`vmstat 1 2 | awk 'NR == 4 { printf "%d\n", $20 + $21 }'`
vm2array[1]=`vmstat 1 2 | awk 'NR == 4 { print $22 }'`
echo ${vm2array[0]}
echo ${vm2array[1]}
echo Uptime #MRTG will get uptime from a different source
echo machinenamegoeshere #print out machine name for MRTG to put on the
page

Cpupercent
------------

#!/bin/ksh
#This script provides output of the ratio of CPU used by a specific
process vs. idle CPU time. As you can see it uses grep, for the
processname.
ssarray[0]=`ps -efo pcpu,fname | grep processnamegoeshere | awk '{printf
"%d\n", $1}'`
ssarray[1]=`vmstat 1 2 | awk 'NR == 4 {print $22}'`
: ${ssarray[0]:=0}
echo ${ssarray[0]}
echo ${ssarray[1]}
echo Uptime #MRTG will get uptime from a different source
echo machinenamegoeshere #print out machine name for MRTG to put on the
page


I hope these of are some use. Usual rules for use apply. (No support, no
debugging). Hopefully they're simple enough that you can hack them all
around to make them work for your environment.
--
Neil

--
* To unsubscribe from the mrtg mailing list, send a message with the
  subject: unsubscribe to mrtg-request at list.ee.ethz.ch
* The mailing list archive is at http://www.ee.ethz.ch/~slist/mrtg


More information about the mrtg mailing list