With CURL and RRDTOOL it is possible to collect http request statistics.
Below you can find the 2 scripts
#************************
#curl-rrdtool.sh
#************************
#!/bin/bash
# Paths... adjust as necessary
BASE="/home/matteo/curl"
CONFIG="config"
CURL="/usr/bin/curl"
RRDTOOL="/usr/bin/rrdtool"
# Given a URL, return a file name
# ensure we have the needed parameters
# Strip out any non alphas, replace with underscores,
# and add a host name
FILE=apache.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
# Convert the URL to a name and build the RRD
$RRDTOOL create "$BASE/$FILE" -s 30 \
DS:total:GAUGE:60:0:U DS:dns:GAUGE:60:0:U DS:connect:GAUGE:60:0:U \
DS:pretransfer:GAUGE:60:0:U DS:starttransfer:GAUGE:60:0:U \
RRA:AVERAGE:0.5:1:288 RRA:AVERAGE:0.5:6:336 RRA:AVERAGE:0.5:24:372 \
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 \
RRA:LAST:0.5:1:288
}
if [ ! -f "$BASE/$FILE" ]; then
create_rrd $URL
fi
while true ; do
$CURL -b /tmp/cookies.txt -c /tmp/cookies.txt -d "username=test1&password=XXXXX" -s http://learninglab.group.mysite.com/moodle/login/index.php
OUT=`$CURL -b /tmp/cookies.txt -c /tmp/cookies.txt -m 30 -w %{time_total}:%{time_namelookup}:%{time_connect}:\
%{time_pretransfer}:%{time_starttransfer} -o /dev/null -s http://learninglab.group.mysite.com/moodle/`
$RRDTOOL update "$BASE/$FILE" -t "total:dns:connect:pretransfer:starttransfer" N:$OUT
sleep 30
done
#************************
#curl-rrdtool-chart.sh
#************************
#!/bin/sh
MEASUREMENT="matteo"
SITE="http://learninglab.group.mysite/moodle/"
FILE=/home/matteo/curl/apache
DEFS=" DEF:total=$FILE.rrd:total:AVERAGE \
DEF:dns=$FILE.rrd:dns:AVERAGE \
DEF:connect=$FILE.rrd:connect:AVERAGE \
DEF:pretransfer=$FILE.rrd:pretransfer:AVERAGE \
DEF:starttransfer=$FILE.rrd:starttransfer:AVERAGE"
width=800
height=400
rrdtool graph $FILE-hourly.png \
--width $width --height $height \
-r -s end-30min \
-t "Performance of $SITE from $MEASUREMENT" -v "Seconds" \
$DEFS \
AREA:total#FF0000:"Data Transfer" \
AREA:starttransfer#CAAA00:"First Byte" \
AREA:connect#0000FF:"Connection" \
AREA:dns#00FF00:"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"
Iscriviti a:
Commenti sul post (Atom)
Nessun commento:
Posta un commento