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:

12 comments so far

Add Your Comment
  1. Mischa ter Smitten

    “Also make sure to fill in an ip address or hostname”

    Where exactly?

  2. Mischa ter Smitten

    In the IP Address field under Data Sources -> – HTTP Reponse Time (nrpe) -> Supplemental Data Template Data -> Custom Data

  3. Mischa ter Smitten

    NRPE is required on the supervised machine?

  4. Mischa ter Smitten

    No, it just makes HTTP Requests.

    See http://nagiosplugins.org/man/check_http for more information.

  5. Mischa ter Smitten

    I tested the Perl wrapper. It works but the result contains only an integer.
    ex:
    perl check_http.pl myHost
    0

    I create a graph ton the corresponding host in Cacti but only got an empty graph.

    Do you have any idea?

  6. Mischa ter Smitten

    (I filled an hostname)

  7. Mischa ter Smitten

    I have no idea. I just checked my version.

    # perl check_http.pl http://www.google.nl
    0.088465

    What is the output of the check_http binary?

    # /usr/lib/nagios/plugins/check_http -H http://www.google.nl -f follow -t 60
    HTTP OK: HTTP/1.1 200 OK – 15150 bytes in 0.089 second response time |time=0.088995s;;;0.000000 size=15150B;;;0

  8. Mischa ter Smitten

    /usr/lib/nagios/plugins/check_http -I 127.0.0.1 -p 5865 -u http://www.google.com HTTP OK: HTTP/1.1 302 Found – 2118 bytes in 2,456 second response time |time=2,456238s;;;0,000000 size=2118B;;;0

    I use a Microsoft ISA proxy whith. The port 5865 is the port of ntlmaps.

  9. Mischa ter Smitten

    Hey Marco,

    I think I know what the problem is. Your output contains comma decimal separators (non en_US locale?). The perl wrapper probably matches points.

  10. Mischa ter Smitten

    I have no graph andI filled an IP

  11. Mischa ter Smitten

    and if i execute the script it’s ok

  12. Mischa ter Smitten

    Hey Flo,

    Can you post the output?