Realtime logging

June 8, 2011

Wanted to play more with parsing log files with php, and then displaying the data to the user with javascript.

So first I had to find an application that did what I wanted, i.e. log something.

I decided to use coretemp, which can log to file the cpu speed, temp and load. So I set the settings for coretemp that it should start in the background and log to a file, that’s on the same smb mount as my webroot.

When I got the “client side” things working a started on the php. because of the log file being on my webroot I could easily fetch it with file_get_contents(), parse the csv to a multidimensional array and the JSON encode it an spit it out to the javascript, I then used a small prototype that I built a few months ago that draws up diagrams, with this I drew up three diagrams that are absolute positioned on each other.

I then wanted something that could show if the feed the user is looking at is realtime or not, this was easily done by comparing the latest datapoint time with current time, minus interval, ( log_unixtimestamp > (time()-10) ), if this returns true, then the data is coming in realtime.

Check it out