Graph Load Averages

November 2010 — Foothill Ranch, CA

I’ve been working on web sites a long time now, and sometimes I get the unwelcome notice that the web server is overloaded. This usually comes as a surprise to me because I don't always have my finger on the "pulse" of the server. There are a lot of ways to do this. SSH’ing into the server and running uptime is a good way to get a glimpse of load averages, but it’s not very convenient to do that.

I’m sure there are some fantastic graphing tools for all the hard-core sysadmins out there, but I am not one of them. I just want a simple way to see how my server is doing. I recently learned about the Linux sar command and it was the answer I was looking for! Then, I decided I should couple that with my functions for building Google Charts and voila, a really simple way to keep a pulse on my server. And then, for the true icing on the cake, use Safari to add it to your dashboard. For even more fun, load the page in your iPhone and save a shortcut icon on your home screen!

Below is a live demo followed by the source code of the PHP script. I tried to self-document the script as much as possible. Basically the linux sar command is executed which returns load average results (among other results). These results are formatted into an array, which is passed to a function to turn the data into a Google Chart. The formatted image URL is then formatted into a brief HTML page, although the URL could simply be used.

I hope you enjoy and can use this to easily monitor your server’s load using a little bit of PHP.

Media: Google Charts API PHP HTML

Source Code

Tags: Programming Web Development Information Visualization Google Charts API PHP HTML