Server Stats on Desktop

Server Stats on Desktop

Knowing how my server is preforming at all times kind of an hobby with mine. I know I can subscribe to some tools and services that display this info in beautiful graphics and charts, but I like simple things, and I like using default stuff. Years ago I wrote about a similar script to this, that used this info with jQuery gauges and Panic StatusBoard, but this is a much cleaner and easier method, and much simpler, and I just like it a whole heck of a lot better. So to do this, we have three steps:

  1. Remote Server cronjob that puts top output into a non-public server_top.txt file
  2. Remote Server public PHP file server_top.php that regex’s and sorts out the server_top.txt values and creates a¬†serialized array of our desired stats for public
  3. Finally a local PHP file geeklet-server_top.php file that converts theserialized array into something and put it on our desktop with GeekTool

First on Remote Server we need to make sure top¬†outputs all CPU’s so we can factor them all in and find an average. To do that, run top¬†and hit the key 1¬†this will reveal all CPUs. Next hit W¬†to save this CPU-revealed configuration as default.

We then setup a cronjob with crontab -e that puts the top result in a file in a non-public directory:

Second,¬†with our server outputing¬†top¬†into a non-public¬†file, we don’t want to share all the info, so we’ll be cryptic with this next script. We’ll make a file in the public directory called server_top.php¬†and we’ll read the .txt file, and only output a vauge array of non-compromising data, which¬†we’ll interperut locally in the next step:

Lastly, with out Remote Server now giving us an array of¬†the CPU, Memeory, Average Load, Top Time, and HDD size, we’ll render this data on our local server¬†into bars for GeekTool:

We locally, now have a script creating our server stats into bars. We then create a new Shell Geeklet and run the command:

Then¬†set the font to somthing monospace for lining up the text, and to refresh as often as our crontab does, and that’s all!

You’ll notice there’s a¬†warning point, which simply changes the progress bar to somthing more attention grabbing if¬†any of the stats are above a conerning percentage. If static text hidden on the desktop isn’t enough, you could take this script further and use mail()¬†or to email you a notification of this high stat.


Leave a Reply

%d bloggers like this: