Hi, I am trying to convert a simple shell script written by Sean Walberg from:
http://www.ibm.com/developerworks/edu/d ... rrd-i.html and would like some
help from Cacti users if possible. My primary goal is to gather information using
Cacti with a bash curl script and store it into Cacti RRD's.
Here is my attempt to explain my process of Modifying Seans scripts into Cacti. I am
however not getting any graphs. Could someone let me know if my shell script is correct?
This script was a one liner curl statement called measure.sh. I basically stripped out the curl section of Shawns generate script below. I then appended the 5 fields:
connect, pretransfer, total, starttransfer, and dns to the output fields.
Code: Select all
#!/bin/bash
CURL=/usr/bin/curl
$CURL -m 60 -w "total:%{time_total} dns:%{time_namelookup} connect:%{time_connect} pretransfer:\
%{time_pretransfer} starttransfer:%{time_starttransfer}" -o /dev/null -s $1
for so I proceeded to move to cacti.
[cactiuser@cactilab ~]$ ./measure.sh www.example.com
total:0.000 dns:0.249 connect:0.000 pretransfer:0.000 starttransfer:0.000[cactiuser@cactilab ~]$
Here are the steps I took in Cacti to create the data input method.
1. Went to "Collection Methods"
-Data Input Methods
Went to add.
Gave the Data Input a name of "Apache Curl Query"
Changed the Input Type to: "Script/Command"
Gave the Input String a complete path to the script of: "/home/cactiuser/measure.sh" followd by <url>
So the complete Input string is: /home/cactiuser/measure.sh <url>
-Also made sure the script was owned my cactiuser and made sure it was executable.
Next I identified 1 Input field and gave it a name of "url" with all defaults.
I then proceeded to define 5 output fields below:
1st was "connect" with a friendly name of "Time Connect" hit save.
2nd was "dns" with a friendly name of "DNS lookup" hit save.
3rd was "pretransfer" with a friendly name of "Time Pretransfer"
4th was "starttransfer" with a friendly name of "Start Transfer"
5th was "total" with a friendly name of "Total Transfer"
Once the Data Input methods where complete I went into Data Sources.
I went to add, left the Data Template selection blank and hit create.
Gave the Data Source a name: Time Connect
Left the data source path blank so cacti would create it's own.
Selected "Apache Curl Query" as the Data Input Method, left Associated RRA's,Step
and data source active at their defaults.
THen proceeded to Data Source Item, and added a Internal Data Source Name of "connect"
Left the min, max default, and The data source type of "GAUGE" to the default. Left
heartbeat and output field at their defaults.
Then under Custom Data - I put the url www.example.com and hit save. I repeated this for the remaining
4 outputs.
Next I proceed to create the graphs.
Navigated to Graph Management
1. Clicked on add
2. Left the Graph Template Selection blank hit create.
3. Gave the graph a title of "Apache Curl RRD"
4. Left the defaults and hit create.
5. Clicked on Graph items and began to add the following:
a. Selected a data source of Total Transfer(total).
b. Selected color of FF0000
c. Left Graph item type, Colsolidation fucnction, CDEF function, value GPRINT type, all default.
d. Gave the Text format a name of "Total:"
e. hit save.
After hitting save no graph showed up. I have done this with other inputs and got graphs but this one is a little tricky.
Can someone point out what I am doing wrong?
Here are the original scripts from Sean Walberg.
This is the measurement code used to use curl and grab the 5 fields we are interested in. I pulled the curl line out of this script and modified it above.
Measurement code:
Code: Select all
#!/bin/bash
# Paths... adjust as necessary
BASE="/home/sean"
CONFIG="config"
CURL="/usr/bin/curl"
RRDTOOL="/usr/bin/rrdtool"
# Given a URL, return a file name
makefile () {
# ensure we have the needed parameters
[ -z "$1" ] && exit 2
# Strip out any non alphas, replace with underscores,
# and add a host name
FILE=`echo $1 | sed 's/[^a-zA-Z0-9_]/_/g'`
FILE="`/bin/hostname`-${FILE}.rrd"
# Can only return numeric results, so global $FILE
# has the result
}
# Called to create the RRD
create_rrd () {
# ensure we have the needed parameters
[ -z "$1" ] && exit 2
# Convert the URL to a name and build the RRD
makefile $1
$RRDTOOL create "$BASE/$FILE" -s 300 \
DS:total:GAUGE:600:0:U DS:dns:GAUGE:600:0:U DS:connect:GAUGE:600:0:U \
DS:pretransfer:GAUGE:600:0:U DS:starttransfer:GAUGE:600:0:U \
RRA:AVERAGE:0.5:1:288 RRA:AVERAGE:0.5:6:336 RRA:AVERAGE:0.5:24:372 \
developerWorks® ibm.com/developerWorks
Expose Web performance problems with the RRDtool
Page 8 of 23 © Copyright IBM Corporation 1994, 2007. All rights reserved.
RRA:AVERAGE:0.5:144:730 RRA:MIN:0.5:1:288 RRA:MIN:0.5:6:336: \
RRA:MIN:0.5:24:372 RRA:MIN:0.5:144:730 RRA:MAX:0.5:1:288 \
RRA:MAX:0.5:6:336 RRA:MAX:0.5:24:372 RRA:MAX:0.5:144:730 \
I RRA:LAST:0.5:1:288
}
# Loop through config file
cat "$BASE/$CONFIG" | while read LINE; do
# For later expansion, the URL is the last field
URL=`echo $LINE | awk '{print $NF}'`
# If the RRD doesn't exist, create it
makefile $URL
if [ ! -f "$BASE/$FILE" ]; then
create_rrd $URL
fi
# take the measurement and dump to RRD with current timestamp
OUT=`$CURL -m 60 -w %{time_total}:%{time_namelookup}:%{time_connect}:\
%{time_pretransfer}:%{time_starttransfer} -o /dev/null -s $LINE`
$RRDTOOL update \
"$BASE/$FILE" -t "total:dns:connect:pretransfer:starttransfer" N:$OUT
done
Code: Select all
#!/bin/sh
MEASUREMENT="bob.ertw.com"
SITE="http://canoe.ca"
makefile () {
# ensure we have the needed parameters
[ -z "$1" ] && exit 2
# Strip out any non alphas, replace with underscores,
# and add the host name
FILE=`echo $1 | sed 's/[^a-zA-Z0-9_]/_/g'`
# Can only return numeric results, so global $FILE
# has the result
}
makefile $SITE
DEFS=" DEF:total=$MEASUREMENT-$FILE.rrd:total:AVERAGE \
DEF:dns=$MEASUREMENT-$FILE.rrd:dns:AVERAGE \
DEF:connect=$MEASUREMENT-$FILE.rrd:connect:AVERAGE \
DEF:pretransfer=$MEASUREMENT-$FILE.rrd:pretransfer:AVERAGE \
DEF:starttransfer=$MEASUREMENT-$FILE.rrd:starttransfer:AVERAGE"
rrdtool graph $FILE-daily.png \
-u 3 -r \
-t "Performance of http://canoe.ca from $MEASUREMENT" -v "Seconds" \
$DEFS \
AREA:total#DADAAA:"Data Transfer" \
AREA:starttransfer#CAAA00:"First Byte" \
AREA:connect#555555:"Connection" \
AREA:dns#222222:"DNS Lookup" \
COMMENT:"\n" COMMENT:"\n" \
GPRINT:total:AVERAGE:"Average request time %0.2lf %Ss" \
GPRINT:total:MIN:"Min/Max %0.2lf %Ss/" \
GPRINT:total:MAX:"%0.2lf %Ss" \
COMMENT:"\n" \
GPRINT:total:LAST:"Current request time %0.2lf %Ss"
rrdtool graph $FILE-monthly.png \
-u 3 -r -s end-1month\
-t "Performance of http://canoe.ca from $MEASUREMENT" -v "Seconds" \
$DEFS \
AREA:total#DADAAA:"Data Transfer" \
AREA:starttransfer#CAAA00:"First Byte" \
AREA:connect#555555:"Connection" \
AREA:dns#222222:"DNS Lookup" \
COMMENT:"\n" COMMENT:"\n" \
GPRINT:total:AVERAGE:"Average request time %0.2lf %Ss" \
GPRINT:total:MIN:"Min/Max %0.2lf %Ss/" \
GPRINT:total:MAX:"%0.2lf %Ss" \
COMMENT:"\n" \
GPRINT:total:LAST:"Current request time %0.2lf %Ss"
Thanks for the help.