Converting Apache curl benchmark script into Cacti

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
keysorsoze
Posts: 14
Joined: Thu May 10, 2007 7:14 pm

Converting Apache curl benchmark script into Cacti

Post by keysorsoze »

Coverting a Curl script to benchmark apache into a cacti poller query.

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

Here is what I get when I run the script followed by a domain name. This returns output fields I am looking
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
This was the script he used to graph the rrds after the measurement script above did the curl query.

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.
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

I suppose you're quite on the right way. For more help, please see 1st link of my sig.
See 2nd link for debugging.
Some hints:
You may want to prepend the script path by /usr/bin/sh or the like to make cactiuser select the correct shell (rebuild_poller_cache.php must be run thereafter).
For the data sources, make sure to modify the default MAX value of 100. Setting it to 0 deactivates the MAX checking.
Reinhard
keysorsoze
Posts: 14
Joined: Thu May 10, 2007 7:14 pm

Post by keysorsoze »

Thanks gandalf, it was indeed the default max value being zero. One I flipped it to 100 my graphs started showing.

Thanks for the help.
SeanW
Posts: 26
Joined: Tue Nov 28, 2006 9:17 am
Location: Winnipeg, Canada
Contact:

Post by SeanW »

That's a clever hack! Glad to see the tutorial was of use.

Sean
fosiul
Posts: 12
Joined: Thu Jun 04, 2009 7:03 am

Post by fosiul »

Hi
i am trying to follow your suggestion but still has the same problem graph is not comming,

can i just ask you a question, you said

" it was indeed the default max value being zero. One I flipped it to 100 my graphs started showing. "

so my understanding is: datasource->edit data source item->set maximum value to 100
and i have done this,
but still graph is not showing.
but if i follow Sean Walberg command to create graph manually, its creating sample.png file with accurate data.
so what i am missing ??
can you please tel me ??
Attachments
this png is create by <br />rrdtool graph sample2.png  \<br />        DEF:connect=localhost-connect.rrd:connect:AVERAGE \<br />        LINE1:connect#FF0000:&amp;quot;Total connect time&amp;quot;
this png is create by
rrdtool graph sample2.png \
DEF:connect=localhost-connect.rrd:connect:AVERAGE \
LINE1:connect#FF0000:&quot;Total connect time&quot;
sample1.png (8.03 KiB) Viewed 5458 times
Cacti-console picture
Cacti-console picture
cacti-graph.GIF (18.82 KiB) Viewed 5458 times
fosiul
Posts: 12
Joined: Thu Jun 04, 2009 7:03 am

Post by fosiul »

Solve :
Graphmanagement->Select the Graph->Edit graph item->select graph item type to Line1
yreddy
Posts: 43
Joined: Fri May 02, 2008 7:33 am
Location: Canada

Re: Converting Apache curl benchmark script into Cacti

Post by yreddy »

I've made a CURL Graph template. Check it out in the following links:
http://forums.cacti.net/viewtopic.php?f=12&t=40200
http://docs.cacti.net/usertemplate:grap ... ponse_time

Youri
Attachments
CURL Stats of &quot;http://fr.yahoo.com&quot; via proxy.
CURL Stats of "http://fr.yahoo.com" via proxy.
CURLBWTEST-Response_Time-yahoo-proxy.png (50.04 KiB) Viewed 4033 times
CURL Stats of &quot;http://fr.yahoo.com&quot;.
CURL Stats of "http://fr.yahoo.com".
CURLBWTEST-Response_Time-yahoo-noproxy.png (59.32 KiB) Viewed 4033 times
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests