2011
11.28

For a while I wanted to graph the HTTP response time of my server(s). I already had Nagios monitor it but now I wanted a nice Cacti image. Based on the check_http script I created (thanks to guy2006) a Perl wrapper to return the response time part:

# /usr/lib/nagios/plugins/check_http -H foo.bar.com -f follow -t 60
HTTP OK: HTTP/1.1 200 OK - 17235 bytes in 0.135 second response time |time=0.134897s;;;0.000000 size=17235B;;;0

The response time part is used as a “Data Input Method” for Cacti.

Implementation:

Create the file check_http.pl in /usr/share/cacti/site/scripts/.

#!/usr/bin/env perl
$response = `/usr/lib/nagios/plugins/check_http -H $ARGV[0] -f follow -t 60`;
chomp $response;
($load) = ($response =~ /time=(\d+\.\d+|\d+\.|\.\d+|\d+)/);
print "$load\n";

Make sure you have the file check_http (it’s in the nagios-plugins-basic package) and it’s located in /usr/lib/nagios/plugins/.

# apt-file search check_http
kannel-extras: /usr/lib/kannel/checks/check_http.sh
kannel-extras: /usr/lib/kannel/checks/check_httpsmsc_kannel.sh
nagios-plugins-basic: /usr/lib/nagios/plugins/check_http
nagiosgrapher: /usr/share/nagiosgrapher/debian/cfg/ngraph.d/standard/check_http.ncfg
# locate check_http
/usr/lib/nagios/plugins/check_http

Test the Perl wrapper, preferably as user cacti:

# perl check_http.pl foo.bar.com
0.425045

Import the XML Template into Cacti (it’s under Import/Export).

Make sure to change the “Consolidation Function” (of Item # 1) from LAST to Average (it’s under Templates -> Graph Templates). Also make sure to fill in an ip address or hostname. Otherwise your graph will be blank.

Your graph will look something like this:

Cacti - HTTP Response Time

Cacti - HTTP Response Time

References:

No Comment.

Add Your Comment