Sunday, August 17, 2014

RPi-Monitor: Use labels to show servers status

RPi-Monitor version 2.7 introduces a new javascript function named Label.



The goal of this function is to add a colored text reflecting the status of a service.

This post is explaining how this new feature can be used.

Note: In version 2.10, a closing parenthesis ' ) ' is missing in the last line of  service.conf .
If you want to use this file as a source of your customisation, remember to add to fix this issue. It is already fixed in github repositories (and future releases).


Label funtion overview

The function Label is designed to write a text highligted by a color.
Label(value, condition, text, level)
This function determine if the label has to be displayed ot not base on a value (extracted by RPi-Monitor) and a condition. The label contains a text to be displayed and a level. 6 levels of labels are available with 6 differences colors:



How to use it?

The file /etc/rpimonitor/template/services.conf is showing an example of Label usage.

In this example, we monitor if the service ssh is listening on port 22 and display a label _OK_ if yes or a lable _KO_ if not.
We do the same for RPi-Monitor on port 8888 and for nginix on port 80 and 443.




How does it work?

Information is extracted from the command netstat.
The regular expression will return the port number if a service is listening on this port or nothing if no service is listenning on this port.
Note: these regular expression may be optimised to return more accurrate result.

The results are accessible into javascript from the variable data. This variable is passed to the Label function as value.
For ssh, the condition is "==22" to check if the value is equal to 22 or "!=22" to check if the value is different form 22. As only one of the condition will be true, only one label will be displayed.

Other ports checking are using the same technic.


Example of Label function used to show server status


As you see, the usage of this new function is quite easy. You can now imagine how to use it for your own needs.


No comments :

Post a Comment