Robert Eisele
Systems Engineer, Architect and DBA

Simple System monitoring with PHP

It's time for the next release. Okay what is it today - we still have an OpenCV wrapper, an IDN wrapper - what's next? A libsensors wrapper! No, just a joke. This extension is a few month old. I tried to build a monitoring extension for PHP with details such as CPU temperature, loadavg which sends an alert if something goes wrong. As I said, this is not a libsensors wrapper and so we have only one detail to monitor in this first version of PHP Sysload.

What is this extension good for. If you have a computationally intensive or a high traffic application so it's possible, that one server is not enough. Okay, you order a second Applicationserver and as a possible solution for load balancing you use DNS Round Robin. A better way for beginners is to set up a reverse proxy such as pound or lighttpd in front of this two application servers. If you use a proxy between the application server and the client you have one big benefit: You have a man in the middle. If one backend server is overloaded you could say the proxy "don't send me more connections".

This is quite easy by sending a HTTP Header for our Proxy. But how? Let the request in the application is very expensive. Handle this task directly in the Webserver is evil too. We have a chance between webserver and PHP script, where sit my Extension. Lets take a look at the new php.ini configuration directives: = 1.0
sysload.five-minutes = 0.5
sysload.ten-minutes = 0.3
sysload.header = "X-Sysload: Critical"
sysload.force-exit = 1

The first 3 directives are quite easy I think. sysload.header is the header to send if one of the first three directives will overrun. force-exit declares itself.

The header directive overwrites a further given value, so it's also possible to change the HTTP Status by sending "Status: 503 Service Unavailable".

You might also be interested in the following


Sorry, comments are closed for this article. Contact me if you have an inventive contribution.