Cacti: Using Cacti to monitor web page loading – Part 3

Welcome to Part 3 on using Cacti for monitoring of web page loading time. In the previous 2 parts, I walked you through how to install a custom script which will query for the loading time of a web page (Part 1), and how to configure Cacti to start collecting data (Part 2).

In this, and final part, I will cover how to start graphing your data collected within Cacti.

A quick recap
At this stage you should have created a Data Input Method (Step 1):

cacti screencap 1

And, you should have created a Data Source (Step 2):

cacti screencap 2

You should also have left Cacti a bit of time to collect the data so that you have some data points you can use to draw your graph.

Step 3: Creating a Graph
From the menu, choose Graph Management and click ‘Add’ to create a new graph.

cacti screencap 3

At the Graph Template Selection webform, just leave both as ‘None’ and click the ‘Create’ button. You’ll be show a new webform called Graph Configuration. You can pretty much leave all the configuration setting as it is, except the Title field. Just key in a name for this graph you can recognize. Once done, go to the bottom of the page and click ‘Create’.

cacti screencap 4

A new Graph Items table will appear where you can define what will appear in the graph.

cacti screencap 5

Click the ‘Add’ button on the top-right of this table. At this form, you can define which parameter you want to plot onto the graph.

cacti screencap 6

For this example, choose the ‘ttl’ parameter as the data source to plot into the graph. Pick yourself a color to use, and choose the ‘Area’ option to plot an area graph. (You can of course choose to use line graph, or stack graph etc – I’ll leave you to play with it once you get the basics). Lastly, give a title to this plot at the Text Format field.

Once done, click ‘Save’ and you should have a graph showing up (hopefully) as so:

cacti screencap 7

And that’s it! The only thing left now is to get your graph included into the Graph Tree so that it will appear in Cacti’s Graphs tab.

Improving your graphs
If you want, you can go back to Graph Management, and improve your graph with other plots and legends etc. Just keep adding Graph Items for your graph and maybe create a graph such as this:

cacti screencap 8

How to read the graph?
If you look at my graph above, there are a few useful pieces of information you can derive from this.

  1. It takes on average 391.2ms to complete the whole transaction, from receiving a request for my blog’s homepage until receiving the last byte.
  2. If I subtract 234.1ms (start transfer) from 391.2ms (total time), I will get 157.1ms, which is the time it takes for the monitoring agent to receive the webpage data. Of course if your monitor is logically far away from your webserver, this number will be larger.
  3. If I subtract 64.67ms from 234.1ms, I will get 169.43ms. This tells me on average it take 169.43ms for wordpress (which is my ‘CMS’) to compose and build my page.

Although I didn’t plot the ’spd’ parameter, this parameter would be quite useful if you want to monitor the transfer rate between the monitor location and your website hosting location. Plotting this will give you a sense of whether your bandwidth is congested at any point in time. (I’m sure you can get that from monitoring your network device bandwidth too).

There are other things you can do too, like create CDEFs, your own Data, Host, Graph templates to make it easier to create more data sources and graphs. But I’m leaving that for another day.

That’s all folks!
Well, that bring me to the end of this long 3 part tutorial. Thanks for your patience and please feel free to leave comments or questions. Hopefully, this article has been of use to someone.

Part 1 | Part 2 | Part 3
Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • DZone
  • Propeller
  • Reddit
  • StumbleUpon
  • Technorati
  • Yahoo! Buzz
Posted on September 19, 2008 at 4:19 pm by Eldee · Permalink
In: PHP Tutorials · Tagged with: , ,

33 Responses

Subscribe to comments via RSS

  1. Written by Joe on October 3, 2008 at 1:51 am
    Permalink

    Hoping you have a part 4. I would like to know how to make this templated, so I can add graphs and data per device.

  2. Written by webmaster on October 3, 2008 at 3:35 pm
    Permalink

    Hi Joe
    You may want to check out the Cacti docs on how to create your own templates.

    http://docs.cacti.net/node/80

  3. Written by Anderson Pereira on November 19, 2008 at 11:35 pm
    Permalink

    Hello,
    I m trying to use this script, I have been followed the tutorial step by step, and the script works fine on prompt line, it allway give me back a result, but in Cacti the graph isnt perfectly, on Cacti it give me some gaps with some parameters (almost all) just the parameter DNS is being graphted, the others some times get a gap… There are no way to increase the perfomance of this graph?

  4. Written by webmaster on November 21, 2008 at 6:15 pm
    Permalink

    Hi Anderson

    Not sure what could be the problem. Have you read these suggestions on debugging Cacti?

    http://docs.cacti.net/?q=node/283

    The very first thing I would do is to look at the logs. The logs normally will show me the result of the execution of the external script. If the log entries shows proper numbers output from the script, then it’s Cacti being a bit unrealiable.

    Hope this helps.

  5. Written by Anderson Pereira on November 21, 2008 at 8:23 pm
    Permalink

    Look, sometimes the poller work perfect.

    “11/21/2008 09:57:02 AM – CACTID: Poller[0] Host[0] DS[20] SCRIPT: /usr/bin/php -q /var/www/html/scripts/https/pageload-agent.php http://www.itau.com.br, output: dns:0.015233 con:0.065969 pre:0.197159 str:0.255121 ttl:0.29715 sze:1249 spd:4203″

    And other times (where cause the gap) it doesnt work perfect:

    “11/21/2008 10:00:02 AM – CACTID: Poller[0] Host[0] DS[20] SCRIPT: /usr/bin/php -q /var/www/html/scripts/https/pageload-agent.php http://www.itau.com.br, output: dns:0.018203″

    As you can check, the poller just return the DNS output. Its very strange…

  6. Written by Anderson Pereira on November 21, 2008 at 9:56 pm
    Permalink

    Hi again, I have made some modifications in your script to get a better performance and to return all parameters that I need, I think its working now perfectly.

    Add me on msn messenger to discuss about these modifications, I sent you the modifications to post on blog.

    I have a question I did Size Download and Speed Download work too, I think Size Download is bytes valor, right?

    And Speed Download? Is Byte per second? Kb per second? Mb per second? How can I define it on graph?

    My msn (apereira_multirede@yahoo.com)

    Thx,
    Anderson Pereira.

  7. Written by Anderson Pereira on November 22, 2008 at 12:36 am
    Permalink

    Hi again, I have a question, when this script load the page, it load all contet page in HTML and all images and other aplications that this page has been running? Its very importante to know, because the total size page that it show for me… is very very little, like 1KB from https://www.itau.com.br
    And I think this page is more larger… maybe it load just the HTML content, and not the images.

    So? What you think?

  8. Written by Vineeth Venugopal on December 1, 2008 at 12:21 pm
    Permalink

    Hi admin,

    Excellent Tutorial, Is there any tutorial like this for monitoring web page hits, online user’s etc..

  9. Written by webmaster on December 2, 2008 at 3:28 pm
    Permalink

    Hi Anderson
    Sorry, for the late reply. My script only loads the HTML part of the webpage. It doesn’t load all the components. You probably need to modify script to also download all the page components.

    Hi Vineeth
    Thanks for your feedback. There won’t be such tutorials you mentioned. You can already monitor web page hits by using tools like Google Analytics or any other web stats reporting tool.

  10. Written by dev on December 3, 2008 at 4:20 am
    Permalink

    awsome !

  11. Written by Travis Fitch on December 9, 2008 at 1:38 pm
    Permalink

    Hi there,

    I followed these instructions step by step, and I am able to generate a graph of repsonse times.

    However my Start Transfer time is longer than my Total Time. Any ideas around this oddity?

  12. Written by webmaster on December 11, 2008 at 12:29 pm
    Permalink

    Hi Travis
    This is the first I’ve heard of this. Is it consistently longer than your total time or just the occasional blip?
    Anyone else have any ideas?

    Webbie.

  13. Written by Travis Fitch on December 15, 2008 at 2:47 pm
    Permalink

    Hi there,

    It seems that the Start Time is longer by about 60% of the time. Is there any where I should start to debug this?

    Travis

  14. Written by Adam on February 14, 2009 at 5:33 am
    Permalink

    Excellent script + tutorial. Using it to monitor my site, thanks!

    Adam
    http://www.howinthetech.com/

  15. Written by blackr on April 17, 2009 at 2:51 am
    Permalink

    Anyone done the templates yet?

    Thanks!

  16. Written by Fitz on May 30, 2009 at 4:43 am
    Permalink

    Thank you for a great tutorial. But, I am experiencing the same thing that Anderson Pereira describes on 11/21/08. In a 24 hour period, the dns data is always graphed but I have only seen the rest of the data reported twice on my 1 minute interval graph. Could you provide the edits to the script that Anderson says he provided?

  17. Written by webmaster on May 30, 2009 at 10:04 am
    Permalink

    hi Fitz, sorry I never contacted Anderson about this. Maybe you can get hold of him directly? he left his email in the comments.
    Thanks

  18. Written by Ameet on September 8, 2009 at 1:18 pm
    Permalink

    Hi there,

    Excellent tutorial. I am able to understand quite thoroughly at the amateur level. I followed the instructions step-by-step, however, i am unable to plot a graph for the same.
    It gives away saying –>
    “ERROR: No DS called ‘ttl’ in /var/www/cacti/rra/con_27/rrd”

    Could you please suggest any remedy for this.

    Thanks,
    Ameet

  19. Written by Ameet on September 8, 2009 at 1:19 pm
    Permalink

    Please note: all my other graphs are working!

  20. Written by Ameet on September 8, 2009 at 1:24 pm
    Permalink

    Also, when i run your script as–>
    ./pageload-agent.php http://www.askaboutphp.com/
    I dont get only the blank parameters as
    dns: con: pre: str: sze: spd:

    thats it…..

  21. Written by webmaster on September 9, 2009 at 10:28 am
    Permalink

    hi Ameet,
    please check that your PHP has cURL enabled. If you are not sure, check out

    http://www.wallpaperama.com/forums/how-to-find-out-if-php-is-compiled-with-curl-extension-installed-enabled-t1576.html

    on how to enabled cURL.

  22. Written by Tom Kirkpatrick on September 13, 2009 at 7:19 am
    Permalink

    I’m getting the same problem (ERROR: No DS called ‘ttl’ in ‘/var/www/html/cacti/rra/con_114.rrd’)

    My PHP has curl enabled. Running the php script from the command line work fine.

  23. Written by Tom Kirkpatrick on September 13, 2009 at 8:05 am
    Permalink

    The only graph item that I can add to my graph without getting that error is th ‘con’ item. With just that item added, I do get a graph, but it has no data. Adding any more graph items results in the above error.

  24. Written by Ben Lye on September 24, 2009 at 4:58 pm
    Permalink

    I think I’ve fixed the problem where only the dns parameter is returned. I don’t know if it’s the same fix as Anderson, but it’s working for me.

    Change these lines in pageload-agent.php:

    print “dns:”.$output['namelookup_time'];
    print ” con:”.$output['connect_time'];
    print ” pre:”.$output['pretransfer_time'];
    print ” str:”.$output['starttransfer_time'];
    print ” ttl:”.$output['total_time'];
    print ” sze:”.$output['size_download'];
    print ” spd:”.$output['speed_download'];

    To this (beware any line wrapping, it should only be two lines):

    $outstring = “ttl:”.$output['total_time'].” str:”.$output['starttransfer_time'].” dns:”.$output['namelookup_time'].” con:”.$output['connect_time'].” pre:”.$output['pretransfer_time'].” sze:”.$output['size_download'].” spd:”.$output['speed_download'];

    print chop($outstring,”\n\r”);

    Ben.

  25. Written by yugi on September 30, 2009 at 2:36 am
    Permalink

    Hi,

    I tried to add a threshold to the graph, but for some reason it’s not triggered, though I used a low value which is lower than a current one. What could be a problem?

  26. Written by jafo on November 20, 2009 at 7:42 am
    Permalink

    Very nice walkthrough. Part 4 could be named “Troubleshooting tips” ;-) Good work!

  27. Written by joeyd on November 26, 2009 at 1:34 pm
    Permalink

    Great script!! and does return values from the command line but it prints out a blank line then the results. Could this be the reason it’s not storing in the RRD?

    Also when I look at the logs I see the script attempt to run but the “output” is just ‘U’..wierd

    11/26/2009 12:14:12 AM – SPINE: Poller[0] Host[0] DS[221] SCRIPT: /usr/bin/php -q /var/www/html/scripts/pageload-agent.php http://www.naturalstandard.com, output: U

    Any thoughts?

  28. Written by Anil Perera on January 8, 2010 at 1:44 am
    Permalink

    Hi,
    I do not know whether you are still maintaining this site, but when I run your script from the command line, I get he result. However in Cacti, I do not get a graph and cacti.log shows the following message:-

    01/06/2010 12:51:23 PM – SPINE: Poller[0] Host[1] ERROR: Empty result [127.0.0.1
    ]: ‘php /usr/opt/apache/htdocs/cacti/scripts/pageload-agent.php http://www.askaboutphp.
    com’
    01/06/2010 12:51:23 PM – SPINE: Poller[0] Host[1] DS[33119] SCRIPT: php /usr/opt
    /apache/htdocs/cacti/scripts/pageload-agent.php http://www.askaboutphp.com, output: U
    01/06/2010 12:51:23 PM – SPINE: Poller[0] Host[1] DEBUG: The NIFTY POPEN returne
    d the following File Descriptor 6

  29. Written by webmaster on January 8, 2010 at 10:43 am
    Permalink

    hi Anil

    Unfortunately I have stopped running this service so I can’t offer much help, as I’ve found a better alternative for measure page load time that’s more reflective of how pages load.

    http://www.askaboutphp.com/71/webpagetest-tool-the-little-known-but-great-webpage-benchmarking-tool.html

  30. Written by pajarofeo on March 10, 2010 at 11:28 pm
    Permalink

    hi

    I’m getting the same problem (ERROR: No DS called ‘ttl’ in ‘/var/www/html/cacti/rra/con_114.rrd’)

    My PHP has curl enabled.

    Running the php script from the command line work fine.

  31. Written by pajarofeo on March 11, 2010 at 12:15 am
    Permalink

    hi

    I think that the error is:

    the script doesn´t save datas to the file con_114.rrd because the date isn’t update

    debian:/usr/share/cacti/site/pageload# ls -l /var/lib/cacti/rra/con_263.rrd
    -rw-r–r– 1 www-data www-data 56224 mar 10 13:10 /var/lib/cacti/rra/con_263.rrd
    debian:/usr/share/cacti/site/pageload# date
    wend mar 10 17:04:22 CET 2010
    cactimap:/usr/share/cacti/site/pageload#

  32. Written by dan on June 22, 2010 at 4:35 pm
    Permalink

    can anybody say, how long is running pageload-agent.php if a web sute is not available?

  33. Written by Matthijs on July 29, 2010 at 9:32 pm
    Permalink

    Dan,

    That depens on the timeout you set in Cacti probably.

    $ time ./pageload-agent.php 192.168.123.123
    dns:0.012674 con:0 pre:0 str:0 ttl:0 sze:0 spd:0
    real 0m21.138s
    user 0m0.060s
    sys 0m0.024s

    Running the script manually, it stopped after 24 secs on my host

Subscribe to comments via RSS

Leave a Reply