Combining my need for monitoring an EC2 instance running nginx, bamboo and artifactory, with my will to code in clojure, I have decided to use server-stats to basic monitor my server via ssh. EC2 supports interactions using SSH without need its .pem file if you add your public key to it. Take a look here to see how.
These are dead simple commands and of course you should use more serious ones for critical services.
The server-stats config file is actually a clojure file named server-stats.cfg where you put some definitions for monitoring. The strength of server-stats is the running it against several server. But in this case, I have just one.
The config file
Almost all the commands were borrowed from the sample cfg file. A small but important detail is the key :mute-for in alerts. As you can see, the above link to server-stats points to my fork of it.
The mute-for key adds the capability to prevent any scheduled ssh commands with short intervals to flood your alert communication channel (e-mail in this cfg). The alerts are sent only if the mute-for time has been elapsed.
This is done via empty files for controlling the alerts. server-stats checks the lastModified property of the file of a given alert, and activates the it only if the mute-for interval is over.
To make server-stats send alerts before the :mute-for time, you can just delete the file named .{Sanitized_alert_message}. The sanitized message is just the message alert message with no characters as underlines. I should consider a hash version of it to avoid big names for big messages, but it is ok for now.
Note that mute-for controls the alert activation per cmd message.
Use cron
Of course you can’t spend your time issuing ssh commands by hand. So, there are four cron entries for scheduled ssh interactions:
The run.sh is pretty simple. Just wraps java -jar to server-stats. Some times I want to log the ssh output, so I can pass the -log option and the output goes to log/cmd.
Don’t ask me why, but ssh does not behave the way you except when called from a cron command. But I managed to find this article that helped a lot.
This crontable is configured on my laptop and any strange behavior is sent to my e-mail immediately. The other cmds (app-log, http-errors) are used directly with ./run.sh cmd to see the output.
Conclusion
Of course the mute-for feature might be merged to the original repo. So, I would recommend you to use the original version of server-stats.
If you need simple monitoring features or more elaborated ones, it is up to you. Just use server-stats as the base for it.