#bash

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:

https://gist.github.com/davidsword/5020318fe00c167a1d00107fd8182c5e

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:

https://gist.github.com/davidsword/b01a38ea335471c23615e0330eeeb286

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:

https://gist.github.com/davidsword/9efeecac8769887a2a2afb038011153a

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

https://gist.github.com/davidsword/a382521e4d04073a9b15f9c24c69a952

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.

Fix for Finder

It may have to do with having Duet installed, but macOS Sierra’s Finder, Expose, and Dock – along with custom mac OS keyboard shortcuts, have been failing a bit more regularily than I’m willing to tolerate.

The fix is simple enough, just restarting them, but I have to dig through my notes or Google and find the commands I’m looking for, which interupts my workflow even more. So I made a single word Terminal alias that fixes prettymuch any blow up any of those services experience:

https://gist.github.com/davidsword/fb421f2e762b0affe3bb0308a06ba889

I added that too my bash profile via vi ~/.bash_profile and reload it with source ~/.bash_profile So now, any problem I have, just pop to Terminal (which is open all day anyways) and > fix the problem.

Quickly Toggle Hidden Files Mac OS X

Working with hidden files often in OS X? but not often enough to keep them on all the time? Me too. Here’s a little edit to your bash profile to quickly toggle the visibility of hidden files with one word in terminal.

https://gist.github.com/davidsword/e34fefc48b5cc6b02d9434b855e0be46

Press i to insert, use down key to reach the bottom, and add the following:

https://gist.github.com/davidsword/2260e9728a70ee3dadaf8cc0e3ec08ef

Exit insert mode with Esc save and close with ZZ

Restart your bash profile with:

https://gist.github.com/davidsword/e5c12e281640382ccae1f38901eef8f6

And now you have some beautiful simple commands:

showhidden and nohidden