Home > Code Snippets, Javascript, Linux Shell, PHP > Linux CPU usage and montioring using shell memcache and jquery

Linux CPU usage and montioring using shell memcache and jquery

December 15th, 2011 Leave a comment Go to comments

Recently in a project where the application was deployed across multiple servers, the Client QA as well as Support Team wanted a better monitoring of all the servers in the production. It was too much to provide everybody with shell access and ask them to monitor using top. Well after a lot of digging through the wonderful search index of Google. And with insights from Paul Colby vide his article Calculating CPU Usage from /proc/stat, and various comments of Memcache usage through telnet along with the /dev/tcp socket connections it was just a matter of using some nifty shell processing before I could store each machine cpu values, loadavg, and running tasks as a json encoded string into memcache on one of the hosts with hostname as the key.

The rest was simple to write a jQuery based interface to fetch the collected data, and process it before adding to a continuous update, the number of rows shown and the frequency was also tweaked, and the latest values are shown on top. Well the page is a bit crude, but serves our purpose. There is not much to configure other than the memcache server in the shell script, which is mcs, and the same in the loader.php. If there are multiple servers to be monitored, the hostname should be added to the $hosts array in the loader.php.

The shmon could be either run from the local service (rc.local) or as a @reboot job in the root cron. The shmon line 10 has a sleep directive, it could even be 15 since that is the minimum value set in the sampling in html, but for calculating the cpu usage, multiple samples are needed, and these could only be obtained from successive hits. The calculation is all done in javascript using jQuery library. I could go for a much smaller library, but just wanted to complete this at the earliest.

I am adding the full kit for download Linux CPU usage and montioring using shell memcache and jquery - Files (665).

  1. No comments yet.
  1. No trackbacks yet.

fifty five − fifty two =