Http statistics with curl


apache-hourlyWith CURL and RRDTOOL it is possible to collect http request statistics. Below you can find the 2 scripts #************************ #************************ #!/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 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` $RRDTOOL update  “$BASE/$FILE” -t “total:dns:connect:pretransfer:starttransfer” N:$OUT sleep 30 done #************************ #************************ #!/bin/sh MEASUREMENT=“matteo” SITE=“" 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”

Enter your instance's address

More posts like this

My Networking Survival Kit

2020-03-15 | #Me

In this small tutorial I’ll speak about tunneling, ssh port forwarding, socks, pac files, Sshuttle I’ve been using Linux since 1995 but I have never been interested a lot in networking.

Continue reading 