r4 - 09 Sep 2007 - 06:14:24 - PorchLightYou are here: TWiki >  Main Web > MrtgTricks

MrtgTricks

Overview

Below is a collection of scripts to make MRTG graph different things. Some of this can be done over snmp, but sometimes, snmp can't be installed. Attached to this document are some of the scripts used.

Run MRTG as Daemon

Add the below to the config file.
Interval: 10
NoDetach: No
RunAsDaemon: Yes  

HDD Temps

Graphs the HDD Temp as long as the HDD is active and not in sleep mode. Gaps will appear when the drive is in sleep mode.

Example

ds-hda-temp-day.png

mrtg.cfg

Target[ds-hda-temp]: `run-temp /dev/hda`
Options[ds-hda-temp]: gauge,integer,nopercent,growright
MaxBytes[ds-hda-temp]: 60
YLegend[ds-hda-temp]: Temp C
ShortLegend[ds-hda-temp]:    
LegendI[ds-hda-temp]:   Temp C:
LegendO[ds-hda-temp]:
Title[ds-hda-temp]: Analysis for hda Temp
PageTop[ds-hda-temp]: <H1>Analysis for hda Temp</H1>
 Note: HDD do not generate stats when in standby mode.<BR>

script

run-temp
#!/bin/bash

HDD=$1
#HDD="/dev/hdc"

ACTIVE=`hdparm -C $HDD | grep active`

if [ ! -n "$ACTIVE" ]; then    # -n tests to see if the argument is non empty
#  HDD is not active. Don't do anything.
echo 0
echo 0
exit
fi


HDDTEMP=`/usr/sbin/smartctl -a $HDD |grep Temperature | /bin/awk '{print $10}'`
HDDPOWER=`smartctl -a $HDD | grep -m 1 "Extended off" | /bin/awk '{print $9}'`
HDDID=`smartctl -a $HDD | grep -m 1 "Model"`

echo $HDDTEMP
echo $HDDTEMP
echo $HDDPOWER
echo $HDDID

HDD Space Used/Free

Graphs the free and used space. Does not wake the drive out of sleep mode. Does not report anything if the drive is in sleep mode. MRTG assumes that if nothing is reported, then the data is the same as last time. So this generates a solid graph.

Example

ds-hda-free-month.png

Month Graph

mrtg.cfg

Note For the graph to have the correct scale, the MaxBytes? should be set to the max size of the HDD as reported by df and padded with a few zeros.
Target[ds-hda-free]: `run-free /dev/hda`
Options[ds-hda-free]: gauge,integer,nopercent,growright
MaxBytes[ds-hda-free]: 277737980000
YLegend[ds-hda-free]: Disk Space 
ShortLegend[ds-hda-free]: &nbsp;&nbsp;&nbsp;
LegendI[ds-hda-free]: &nbsp; used:
LegendO[ds-hda-free]: &nbsp; free:
Title[ds-hda-free]: Analysis for hda free
PageTop[ds-hda-free]: <H1>Analysis for hda Free Space</H1>
 Note: HDD do not generate stats when in standby mode.<BR>

script

#!/bin/bash

HDD=$1
#HDD="/dev/hdc"

ACTIVE=`hdparm -C $HDD | grep active`

if [ ! -n "$ACTIVE" ]; then    # -n tests to see if the argument is non empty
#  HDD is not active. Don't do anything. We assume nothing has changed.
exit
fi


HDDFREE=`df |grep $HDD | tail -n 1 | /bin/awk '{print $4}'`
HDDUSED=`df |grep $HDD | tail -n 1 | /bin/awk '{print $3}'`
HDDPOWER=`smartctl -a $HDD | grep -m 1 "Extended off" | /bin/awk '{print $9}'`
HDDID=`smartctl -a $HDD | grep -m 1 "Model"`
HDDTOTAL=`df -h |grep $HDD | tail -n 1| /bin/awk '{print $2}'`

echo $[$HDDUSED*1000]
echo $[$HDDFREE*1000]
echo $HDDPOWER
echo "$HDDID <br> Total Size [formatted]:$HDDTOTAL"

CPU Load

This graphs the system load. It does a poor job of parsing the uptime command and tends to mess up the 5 min avg unless the system has been up for over a day. But all my systems I track with this are, so it's not something worth the time to fix.

Example

load-day.png

mrtg.cfg

run-load script
Target[ds-load]: `run-load`
Options[ds-load]: gauge,integer,nopercent,growright
MaxBytes[ds-load]: 500
Unscaled[ds-load]: n
YLegend[ds-load]: System Load 
ShortLegend[ds-load]: &nbsp;&nbsp;&nbsp;
LegendI[ds-load]: &nbsp; 1 min avg:
LegendO[ds-load]: &nbsp; 5 min avg:
Title[ds-load]: Analysis for System Load
PageTop[ds-load]: <H1>Analysis for System Load</H1>

script

#!/bin/bash

UPTIME=`uptime | /bin/awk -F , '{print $1}'`
ONEMIN=`uptime | /bin/awk  '{print $10}' | /bin/awk -F,  '{print $1}'  `
FIVEMIN=`uptime | /bin/awk  '{print $11}' | /bin/awk -F,  '{print $1}'  `

echo $ONEMIN*100|bc
echo $FIVEMIN*100|bc
echo $UPTIME
echo localhost

Multiple host ping graph

This set of scripts is designed to ping multiple systems and generate a graph showing the ping times. This script generates it's own mrtg.cfg files if none are found. This makes it easy to add and remove hosts to monitor. Unlike other mrtg scripts, this runs from a looping shell script. The script is set to run every 40 seconds. Due to the huge amount of data this script can generate over a few weeks of operation, it's not recommended to run this script forever. MRTG was designed to run every 10 minutes, not 40 seconds. This script should just be used to debug a connection.

  1. Get first host from list
  2. If mrtg.cfg is not found for this host, make one.
  3. Call MRTG with the mrtg.cfg file
  4. MRTG reads the config file, then calls a small ping script that pings the host
  5. MRTG generates the graph.
  6. Script loops and does next host
  7. Once every host is done, wait X amount of time, then do it again.

After every loop, the script checks for the existence of a blank file called "run". If this file does not exist, then the script quits. This makes it easy to kill off the script without knowing it's PID. Aka, crontab or just something like "sleep 300 && rm ./run" will end the script in 5 minutes.

To install, extract into a directory, change the SCRIPTPATH to the directory it's in, add the hosts to monitor, and change the path to MRTG. Then run "masterping".

Example

ping-day.png

scripts

-- PorchLight - 03 Sep 2007

Topic attachments
I Attachment Action Size Date Who Comment
pngpng ds-hda-free-month.png manage 2.2 K 03 Sep 2007 - 10:32 PorchLight  
pngpng ds-hda-temp-day.png manage 2.0 K 03 Sep 2007 - 10:31 PorchLight  
pngpng load-day.png manage 4.6 K 08 Sep 2007 - 06:54 PorchLight  
elsegz mrtg-ping.tar.gz manage 0.8 K 09 Sep 2007 - 06:08 PorchLight  
pngpng ping-day.png manage 5.7 K 09 Sep 2007 - 05:59 PorchLight  
elseEXT run-free manage 0.7 K 03 Sep 2007 - 10:37 PorchLight  
elseEXT run-load manage 0.3 K 08 Sep 2007 - 06:56 PorchLight  
elseEXT run-temp manage 0.5 K 03 Sep 2007 - 10:21 PorchLight  
Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r4 < r3 < r2 < r1 | More topic actions
Main.MrtgTricks moved from TWiki.MrtgTricks on 05 Sep 2007 - 00:01 by PorchLight - put it back

tip TWiki Tip of the Day
SmiliesPlugin emoticons
Smilies are common in e mail messages and bulletin board posts. They are used to convey an emotion, such ... Read on Read more

 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback