How I tested my web hosting and got response time data graph

By | February 9, 2017

I decided to check how change my hosting response time during the whole day for this purpose I created simple bash urltest.sh script. The script is base on cUrl tool which sends GET request to some specific URL. If server is not responding 60 seconds timeout is used. The script requires 2 argument URL and name of the file for collecting data.

The source of the script is presented below:

#!/bin/bash
if [ $# -ne 2 ];
then
echo "2 argtuments are required:"
echo "1. URL"
echo "2. log file"
echo "Example: ./urltest.sh http://wordchaos.com /tmp/urlavailability.log"
exit -1
fi
date >> $2
(time curl -H "Cache-Control: no-cache" -m 60 -I -L $1) 2>&1 | grep 'HTTP\|Location:\|real\|resolve\|timed' >> $2
echo >> $2

Then put the script into crontab with interval 15 seconds:
root@smike19-VirtualBox:/# crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
*/15 * * * * /tmp/urltest.sh http://wordchaos.com /tmp/urltestresult.log

Collected data in /tmp/urltestresult.log file looks like:


Tue Feb 7 00:00:01 EST 2017
HTTP/1.1 200 OK
real 0m0.155s

Tue Feb 7 00:15:01 EST 2017
HTTP/1.1 200 OK
real 0m0.153s

Tue Feb 7 00:30:01 EST 2017
HTTP/1.1 200 OK
real 0m2.643s

Tue Feb 7 00:45:01 EST 2017
HTTP/1.1 200 OK
real 0m0.166s

Tue Feb 7 01:00:01 EST 2017
HTTP/1.1 200 OK
real 0m0.170s

I opened the text file in Excel and got this:

Not nice! To make it applicable to conversion to graph I created VBA script to modify worksheet:

Sub ProceedTestResult()
UsedRange.Select
Set xRng = Selection
' Recalculate time in milliseconds and place in into diffent cell
For Counter = 1 To xRng.Rows.Count
cellvalue = xRng.Cells(Counter, 1).Value
If cellvalue = "real" Then
cellvalue = xRng.Cells(Counter, 2).Value
mPos = InStr(cellvalue, "m")
sPos = InStr(cellvalue, "s")
cellvalue = Left(cellvalue, sPos - 1)
Min = Left(cellvalue, mPos - 1)
MinInMs = Min * 60 * 1000
Msec = Right(cellvalue, Len(cellvalue) - mPos) * 1000 + MinInMs
xRng.Cells(Counter - 2, 2).Value = Msec
xRng.Cells(Counter, 1).EntireRow.Delete
End If
Next Counter
' Delete empty rows
For Counter = 1 To xRng.Rows.Count
cellvalue = xRng.Cells(Counter, 1).Value
If cellvalue = "" Then
xRng.Cells(Counter, 1).EntireRow.Delete
End If
Next Counter
' Remove HTTP return code
For Counter = 1 To xRng.Rows.Count
cellvalue = xRng.Cells(Counter, 1).Value
mPos = InStr(cellvalue, "HTTP")
If mPos = 1 Then
xRng.Cells(Counter, 1).EntireRow.Delete
End If
Next Counter
' Convert datetime
For Counter = 1 To xRng.Rows.Count
cellvalue = xRng.Cells(Counter, 1).Value
timeArray = Split(cellvalue, " ")
For Each element In timeArray
cPos = InStr(element, ":")
If (cPos = 3) Then
xRng.Cells(Counter, 1).Value = TimeValue(element)
Exit For
End If
Next
Next Counter
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub

After processing modified worksheet became good for graphing:

And finaly graphical result presentation:

Leave a Reply

Your email address will not be published. Required fields are marked *