[mrtg] Newbie - Memory and Disk usage on linux system

Corstian corstian at consonare.nl
Mon Apr 4 07:46:41 MEST 2005


After searching the web, about writing your own script to create input for
mrtg I finally got the memory usage and the disk usage working.

For those who want to know:

I created two simple bash scripts. The first one filters the output of the
"free" command, the second one filters the output of the "df" command.

When you want to create scripts for your own, you have to know, that the
output of these script has to contain four lines.
1: Result 1
2: Result 2
3: Uptime of the system
4: Hostname of the system


<< Memory Usage Script: >>

#!/bin/bash

###
###     Memory Usage - outputs four lines for mrtg graphs.
###
###     1: used bytes of memory
###     2: total available bytes of memory
###     3: server uptime
###     4: hostname
###

memtype=$1

###     When no memtype asked just echo zero's and exit
if [ -z "$memtype" ]; then
        echo "0"
        echo "0"
        uptime
        hostname
        exit
fi

###     Get line from "free" command
line=`free | grep "^$memtype " `

###     Return four lines of output
echo $line | awk '{ print $3 }'
echo $line | awk '{ print $2 }'
uptime
hostname

<< mrtg.conf section for memory usage: >>
###
### Memory usage
###

Target[memory.mem]:     `/home/corstian/bin/mrtg/memory_usage Mem:`
Options[memory.mem]:    gauge,growright,nopercent
Title[memory.mem]:      Memory Usage of PinkPanther
MaxBytes[memory.mem]:   10000000000
Factor[memory.mem]:     1024
LegendO[memory.mem]:    Total
LegendI[memory.mem]:    Used
Legend1[memory.mem]:    Total memory
Legend2[memory.mem]:    Used memory
YLegend[memory.mem]:    Bytes
ShortLegend[memory.mem]:        B
PageTop[memory.mem]:    <H1>Memory Usage of PinkPanther </H1>


###
### Swap usage
###

Target[memory.swap]:    `/home/corstian/bin/mrtg/memory_usage Swap:`
Options[memory.swap]:   gauge,growright,nopercent
Title[memory.swap]:     Swap Usage of PinkPanther
MaxBytes[memory.swap]:  10000000000
Factor[memory.swap]:    1024
LegendO[memory.swap]:   Total
LegendI[memory.swap]:   Used
Legend1[memory.swap]:   Total memory
Legend2[memory.swap]:   Used memory
YLegend[memory.swap]:   Bytes
ShortLegend[memory.swap]: B
PageTop[memory.swap]:   <H1>Swap Usage of PinkPanther </H1>

<< Disk Usage script: >>
#!/bin/bash

###
###     Partition space - outputs four lines for mrtg graphs
###
###     1: used bytes on partition
###     2: total available bytes on partition
###     3: uptime
###     4: hostname
###

partition=$1

###     No partition asked ?? just echo zero's and exit
if [ -z "$partition" ]; then
        echo "0"
        echo "0"
        uptime
        hostname
        exit
fi

###     Get info from "df" command
line=`df | grep "^$partition " `

###     Return four lines of output
echo $line | awk '{ print $3 }'
echo $line | awk '{ print $2 }'
uptime
hostname


<< mrtg.conf section for disk usage: >>
###
### Disk space of /dev/hda1 partition on mounted on /
###

Target[disk.hda1]:      `/home/corstian/bin/mrtg/partition_space /dev/hda1`
Options[disk.hda1]:     gauge,growright,nopercent
Title[disk.hda1]:       Disk Usage of /dev/hda1 mounted on /
MaxBytes[disk.hda1]:    10000000000
Factor[disk.hda1]:      1024
LegendO[disk.hda1]:     Total
LegendI[disk.hda1]:     Used
Legend1[disk.hda1]:     Total diskspace
Legend2[disk.hda1]:     Used diskspace
YLegend[disk.hda1]:     Bytes
ShortLegend[disk.hda1]: B
PageTop[disk.hda1]:     <H1>Disk Usage of /dev/hda1 mounted on / </H1>

--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the mrtg mailing list