Bash Collection – Server Health Monitor for getting quick information of server status
The last three days, I’ve created a small bash script that outputs some important server health information. I’m using this script for displaying the server health on my Raspberry Pi at home. I’ll buy one of these official 7 inch touch screen displays for the Raspberry Pi and then show these health information on it.
Given the maximum values of some output variables, it also will change the colors of these values.
The usage of this script is simple: The main script lays on the server itself where it can get called via SSH each 2 seconds. On the raspberry pi there is just only a small script with a while true loop, that connects via SSH to the server and gets the output of that main script.
The main bash script needs some, mostly standard tools. If they are not already installed, they should be available through your package manager (apt-get install <packagename>)
The other tools are standard and should be already available:
You need to add the following line to the “/etc/rc.local” on your server:
/usr/bin/ifstat -n -z -q -b -i em1 2 >/tmp/netstat.log 2>/dev/null &
Please change the name of the interface (“em1”) according to your needs.
Next, copy and save the following script as /root/bin/monitoring.sh on your server:
You may want to adjust or change some things in this script. For example in the lines 93 until 108 the maximum values (2nd parameter of function call “colorize”)
Note: This script was self written by me, Alex Löhner. It is still not really finished. You can see that at the end of the script. There are many placeholder lines. I’ll add other information to this script when I need them.
Save the script and make it executable:
chmod 755 /root/bin/monitoring.sh
You now already can call that script from your command line. It will output all the information needed to get the server status health.
You may want to create a monitor like me with a little Raspberry Pi and a 7″ touch screen monitor. For this, the user “pi” on the raspberry must be able to connect via SSH with your server without entering a password (Use SSH public key for this!).
Then save the following script on the raspberry and make it executable:
while true; do
out=$( $ssh '/root/bin/monitoring.sh' 2>/dev/null )
echo -e "$out" # | column -t
When running, the Pi should give you the output of the main script in your Pi Monitor.
See my monitor on the image below. 🙂