Creating RRD files in PHP

I was looking for a way to store (and graph) data for all of our physical servers.  Now sure, we could install SNMP on every machine and just use MRTG, but as a lot of them are leased by clients, I wanted something out of band which will ‘just work’.  We have a very nice IMPI based system which we use for provisioning every server on the network.  That seemed like a good way to go!  Pulling all the fun info via IPMI is really easy:

That gives us quite a useful amount of info!  Though for our purposes, we’ll ignore everything except the first three columns.

Handling that in PHP, we do something like the following:

Then we need to think about the RRD’s.  We need to check if we HAVE one, if so we put the data in.  Or we generate a new RRD and put the data in.

What we’re doing above is creating the datastore, and creating Round Robin Archives for Min, Max, and Average. Storing a sample every 5 minutes for 24 hours (288 samples), a sample every hour for 7 days, and a sample every day for a year.

Now we need to store our data.  That’s the easy part!

And we’re now storing data.  Note the use of the shell_exec.  At least in PHP5.4 on Ubuntu, rrd_update and rrd_graph do not work.

But that’s not much fun if we can’t display the graphs when we need them!

I could write them out to file and then include them from static HTML etc.  But I’d rather have it all dynamically generated.  I have a php file which generates the HTML table referencing the graphs:

And then the actual graphing script:

And now it’s working very nicely indeed!

 

 

Leave a Reply