Article 291 of meer.list.mrtg:
Path: matra.meer.net!gateway
From: julie@morn.MageNet.com (Julia Anne Case)
Newsgroups: meer.list.mrtg
Subject: Monitoring Diskspace and other things
Date: 8 Apr 1997 04:11:46 -0000
Organization: meer.net
Lines: 120
Distribution: meer
Message-ID: <199704080401.AAA05579@morn.MageNet.com>
NNTP-Posting-Host: matra.meer.net
Content-Type: text
Xref: matra.meer.net meer.list.mrtg:291

#! /bin/bash

## monitor
## A shell script to feed mrtg the proper data to monitor various
## system resources
## v0.2 Julia A. Case (julie@MageNet.com)
## (c) 1996-1997 Valley of the Mage Consulting

case $1 in

  ipacct)
    /sbin/ipfwadm -A -l -x | grep $2 | cut -c9-19
    ;;

  df)
    df /dev/$2 | grep $2 | cut -c 39-47
    df /dev/$2 | grep $2 | cut -c 29-37
    ;;

  mail)
    case $2 in
      files)
	mailstats | grep T | cut -c 3-9
	mailstats | grep T | cut -c 22-28
	;;

      bytes)
	mailstats | grep T | cut -c 14-20
	mailstats | grep T | cut -c 33-39
	;;
      *)
  	echo 'Usage - monitor mail [files|bytes]'     
	exit 1
    esac
    ;;

  memory)
    case $2 in
     physical)
	free | grep Mem | cut -c 35-40
	free | grep Mem | cut -c 25-30
	;;

     swap)
	free | grep Swap | cut -c 25-30
	free | grep Swap | cut -c 35-40
	;;
     *)
	echo 'Usage - monitor memory [physical|swap]'
	exit 1
    esac
    ;;

  *)
     echo 'Usage - monitor [mail|memory|ipacct|df]'
     exit 1
esac

uptime | cut -c 14-26
uname -a


# Mailstats
Target[mailstats.1]: `/root/mrtg/monitor mail files`
MaxBytes[mailstats.1]: 1000000
Title[mailstats.1]: Mail Stats (Number of files)
PageTop[mailstats.1]: <H1> Mail Stats (Number of files) </H1>
Options[mailstats.1]: gauge

Target[mailstats.2]: `/root/mrtg/monitor mail bytes`
MaxBytes[mailstats.2]: 1000000
Title[mailstats.2]: Mail Stats (Bytes)
PageTop[mailstats.2]: <H1> Mail Stats (Bytes) </H1>
Options[mailstats.2]: gauge

# Free Memory
Target[freemem.1]: `/root/mrtg/monitor memory physical`
MaxBytes[freemem.1]: 14984
Title[freemem.1]: Memory (Physical)
PageTop[freemem.1]: <H1> Memory (Physical) </H1>
Options[freemem.1]: gauge

Target[freemem.2]: `/root/mrtg/monitor memory swap`
MaxBytes[freemem.2]: 66020
Title[freemem.2]: Memory (Swap)
PageTop[freemem.2]: <H1> Memory (Swap) </H1>
Options[freemem.2]: gauge

# Disk space
Target[sda2.1]: `/root/mrtg/monitor df sda2 `
MaxBytes[sda2.1]: 500000
Title[sda2.1]: Drivespace /var (/dev/sda2)
PageTop[sda2.1]: <H1> Drivespace /var (/dev/sda2) </H1>
Options[sda2.1]: gauge

Target[morn.1]: `/root/mrtg/monitor ipacct morn`
MaxBytes[morn.1]: 192500
Title[morn.1]: IP Acct Morn.MageNet.com
PageTop[morn.1]: <H1> IP Acct Morn.MageNet.com </H1>


The ip acconting stuff works via the Linux ipfwadm command...  You'll need
to add the appropriat commands to your rc.local for this to work  mine
looks like this.

ipfwadm -A -a -P all -Dmorn.MageNet.com/32          -S0.0.0.0/0 
ipfwadm -A -a -P all -Smorn.MageNet.com/32	    -D0.0.0.0/0

I'll package this all up with some better docs later...  as well as add
the CPU monitoring stuff...  I'm still thinking about that one...  any
feedback?

Julie

-- 
[  Julia Anne Case  ] [        Ships are safe inside the harbor,       ]
[Programmer at large] [      but is that what ships are really for.    ]  
[   Admining Linux  ] [           To thine own self be true.           ]
[ Windows/WindowsNT ] [ Fair is where you take your cows to be judged. ]



