Skip to content
Jon's View

Jon's View

a technology blog by Jon Stacey

Menu
  • Contact
Menu

How I use Pingdom’s HTTP Custom Feature

Posted on December 26, 2008January 24, 2010 by Jon Stacey

One of the biggest annoyances to me when doing research on the internet is when I find an enticing summary from a search engine query, but, when I try to access the resource, the website is not accessible because [the database server was down | enter your reason here]. This is why for the year of 2009, I am going to be more proactive in monitoring my server’s reliability.

I chose Pingdom, a company that specializes in uptime monitoring services. The 70% off holiday special didn’t hurt that decision either. For a measly $35 this year, I will be notified the minute (literally) that there is a problem with my server. [Track my server (Swift) uptime]

One of the relatively new features that Pingdom added to their services is the ability to call your own scripts on the server and set your own status report. This allows more comprehensive tests that go beyond a simple ping. I use this functionality to check the status of services that I don’t want accessible on the internet directly (e.g. MySQL) as well as server vitals like RAM usage. Here are two simple PHP scripts that demonstrate how I am using the services from Pingdom with their HTTP Custom check.

pingdom-core.php

[download pingdom-core.php]

This is my core services check. It makes sure that web services and MySQL are operational. Simply configure the script with the username and password of a MySQL database. If the script cannot make a connection to the database server, then a ‘MYSQL DOWN’ status will be returned to Pingdom. Of course, if the script doesn’t respond at all, then the web service is down and Pingdom will report a down status.

pingdom-server.php

[download pingdom-server.php]

This script is intended to be an early warning system. It will raise the alarm if something looks out of the ordinary so that I can be prepared for a possible service failure. The following server vitals are checked: swap usage, hard drive usage, and cpu usage. If any one of these goes beyond the preset thresholds, a down status will be returned to Pingdom.

You might be thinking that checks like these could be done with a monitoring script on the server without using Pingdom at all, and there is merit to that argument. However, if you run out of memory and your system comes crashing to a halt, that probably means that services like email, which you would have used to alert yourself to the problem, would no longer be working. By performing these checks remotely, you can sleep a little easier. Plus, Pingdom will generate nifty looking graphs, and I like graphs.

pingdom.php

–Added on 12/4/2009–

[download pingdom.php]

This script is a combination of pingdom-core.php and pingdom-server.php if you’re using the free acount

Ideas for the future

I would like to check the Apache or Nginx status reports to determine how many connections there are. This may be useful in detecting a digg or slashdot to temporarily boost resources before it becomes a problem.

How do you track your server’s reliability? Leave a comment below.

25 thoughts on “How I use Pingdom’s HTTP Custom Feature”

  1. Robert_ITman says:
    April 26, 2016 at 9:20 am

    AWESOME – Thanks so much for the pingdom.php file – it works perfectly and you saved me many hours of trying to write this myself.

    Nice website – excellent content!

    Reply
  2. Joecoolest says:
    October 4, 2015 at 7:47 am

    Thanks for the script. Your efforts are greatly appreciated!

    Reply
  3. Al says:
    May 19, 2014 at 2:37 pm

    Great script however after setting this up, Pingdom send Up and Down alerts. Should it not be passing the string so if MySQL is down for example the alert would state that instead of just saying Down? Cheers!

    Reply
  4. Mark Dixon says:
    March 6, 2014 at 10:42 am

    I had to change the $totaltime to as follows, otherwise Pingdom was displaying a “?” for Response Time:
    $totaltime = round(($endtime – $starttime) * 1000000); // Time in milliseconds

    Thanks!

    Reply
    1. Josh Fredrickson says:
      April 15, 2021 at 7:41 am

      This comment stands true in 2021.

      Reply
  5. Robert Chambers says:
    September 24, 2013 at 1:25 am

    Great scripts – thanks.

    Is there any reason not to use:
    $hdUsage = shell_exec(“df -h | grep “.$HD_MOUNT.” | awk ‘{print $5}’ | perl -pe ‘s/%//'”);

    So you can make use of the $HD_MOUNT variable?

    Reply
    1. Jon Stacey says:
      October 1, 2013 at 10:52 pm

      I’m not familiar with that–is it a global PHP variable? Google didn’t turn up any ready results for that variable and my local system says it doesn’t exist. Do you have a doc link? But if it works and points to the right mount point for you, go for it! 😀

      Reply
  6. David Gitman says:
    January 30, 2012 at 3:58 pm

    Great Script! Thanks.

    Reply
  7. Simon says:
    December 8, 2011 at 12:22 am

    Very useful – thanks.

    Reply
  8. napi says:
    March 6, 2011 at 1:15 am

    Hi
    I just wonder, what is the best value for the $CPU_THRESHOLD ?. How to determine the cpu threshold?

    Reply
    1. Jon Stacey says:
      March 6, 2011 at 12:46 pm

      Well, there are several things to consider. The first is the number of CPUs and cores you have. The CPU threshold is not a percentage, but average load which is a bit tricky. I suggest reading up on the wikipedia page to better understand load averages. Then it’s just a matter of judgement and personal preference as to what limit you want to be notified about. A lot is dependent on how you’re using the server in the first place. I use the threshold primarily as an early indicator of a runaway process, so it’s set pretty high.

      Reply
  9. MaryAnne says:
    February 8, 2011 at 9:05 pm

    Hi Jon,

    Your post is very helpful. ‘pingdom.php’ is brilliant!
    I was wondering if you have the script to monitor CPU usage as well.

    Reply
    1. Jon Stacey says:
      February 8, 2011 at 9:41 pm

      MaryAnne,

      That part is in the pingdom-server.php file. Essentially the line is `uptime | awk ‘{print $10}’ | perl -pe ‘s/,//’`

      Reply
  10. Steve says:
    December 1, 2010 at 11:47 pm

    oh, right! I didn’t know about the backtick operator having that functionality, I was planning to remove it.

    Sorry for the false alarm.

    Reply
  11. Jon Stacey says:
    December 1, 2010 at 11:36 pm

    Ahh, the backtick operator executes those lines as a shell command, so exec() is not needed. However, in hindsight the return should be cast to an integer otherwise the conditional won’t work:

    $hdUsage = (int)(`df -h | grep ‘/dev/sda1′ | awk ‘{print $5}’ | perl -pe ‘s/%//’`);

    Reply
  12. Steve says:
    December 1, 2010 at 11:07 pm

    Hi Jon,

    All the lines are in this format:

    $hdUsage = `df -h | grep ‘/dev/sda1’ | awk ‘{print $5}’ | perl -pe ‘s/%//’`;

    if ($hdUsage > $HD_THRESHOLD)
    $status = ‘HARD DRIVE OVER THRESHOLD’;

    I’m assuming you wanted:
    $hdUsage = exec(`df -h | grep ‘/dev/sda1’ | awk ‘{print $5}’ | perl -pe ‘s/%//’`);

    So that the string is actually executed and you are comparing the return result…?

    Reply
  13. Jon Stacey says:
    December 1, 2010 at 10:27 pm

    Steve, where is the exec() missing?

    I’m a bit too lazy to remove the unused $HD_MOUNT since it doesn’t break anything, but it was originally intended for the hard drive usage check so that /dev/sda1 wasn’t hardcoded.

    Reply
  14. Steve says:
    December 1, 2010 at 10:20 pm

    ummm didn’t you leave out exec() on the current version?

    Additionally the $HD_MOUNT variable is unused.

    Otherwise, thanks this has been a big help.

    Reply
  15. Pingback: Pingdom’s HTTP Custom Monitoring | Louie Miranda
  16. Louie Miranda says:
    November 3, 2010 at 7:23 pm

    Excellent Work. Very helpful.

    Reply
  17. Jon Stacey says:
    December 4, 2009 at 5:43 pm

    I added a new pingdom.php script which combines the previous two for use with a free Pingdom account.

    Reply
  18. Fouad says:
    November 24, 2009 at 1:45 pm

    Very helpful! Thank you a lot 🙂

    Reply
  19. Daniel says:
    October 5, 2009 at 12:47 pm

    thanks for scripts. extremely helpful!

    Reply
  20. Quentin Stafford-Fraser says:
    June 13, 2009 at 4:42 am

    Very nice – thanks!

    Reply
  21. Pingback: SSH on your iPhone with TouchTerm | Jon's View

Leave a Reply to Robert Chambers Cancel reply

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

Time limit is exhausted. Please reload CAPTCHA.

©2025 Jon's View | Built using WordPress and Responsive Blogily theme by Superb