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.


  1. How do I get the services to appear on RPI-Monitor webpage?

    1. The example on this post is explaining how to do that.
      If you are a new RPi-Monitor user, I also advise to read carefully the FAQ and other articles listed into "RPi-Monitor Articles".

  2. I love how you can adjust RPi-Monitor to your needs/wishes.
    E.g. in this case, I use it also to monitor whether my other Raspberries are alive with a simple ping :)

  3. How can I auto hide a drive or data of service if it doesn't working?
    Example I want to auto hide the storage No4 if it not plugged to usb port:

    1. Actually, there is not simple solution but the idea looks good: We could imagine to have a condition into the configuration file defining if a status should be displayed or not...

  4. Replies
    1. Done. This feature has been added in the next release (2.9)

  5. hi,
    anyway to add a URL link to labels? Use case: some servers have a web front end and I'd like to be able to click on a corresponding label and be redirected to the right front end

    1. The configurationof the web front end (written in conf files) is done by javascript code which is eveluated at runtime. You should then write a piece of code that can match your need and produce valide javascript with your link.

  6. This comment has been removed by the author.

    1. Your question is not very clear. I understand that you want to monitor is a process is present or not. The list of process is available by the command process. Using this command and defining the good filter will let you know if the process is running or not.

  7. it's a very nice tool for the raspberry.

    How do I get the services on the main page?

  8. Jan, I had the same question. If the answer is in the docs (or 'articles' as Xavier calls them) I could not find it.... here is how I got it to show on the main page.

    cd /etc/rpimonitor
    sudo nano data.conf
    At the bottomish of this file, you will see where the list of things that are shown on the main page are, add services.conf to the position where you want it to show up.
    Save the edit.

    sudo /etc/init.d/rpimonitor restart

    Then refresh your browser and the services should (they did for me) show up in the location where you added them.

  9. This comment has been removed by the author.

  10. I would like to show the contents of a log file but can only show the last line of it:
    static.12.postprocess=$1 log
    web.status.1.content.1.line.1='Cron log:'

    I could not find a complete set of documentation, only the template files.

    1. RPi-Monitor manage only one information at a time (one line).
      If you want to have more lines, I would advise to use the fonction insertHTML() added in 2.10 version or create a dedicated addons (new feature also introduced in version 2.10).
      top3 addons could be a good example to see how to do to develop your own addon.
      If you succeed doing this configuration and share it with us, I'll be happy to add it into next release of RPi-Monitor

  11. is it possible to use a continuation character to enable the label line to be easier to read / amend? if each server was on a new line it would be much better, I think.

    1. yes, something like the backslash, which is not working here...
      I edit with notepad++. which syntax highlighting could work?

  12. hello xavier,
    i have noticed that the label names you use here are not exactly the same as the ones used in version 2.10-1 on debian.
    for example "label-important" does not show the label at all. i had to use "label-danger" instead. same goes for "label-inverse", which i didn't find, but i found a "label-primary".

  13. Hi,
    I have a fresh installation and i tried this, sadly labels are not named in the css file as you say here.
    here red is: label-important
    in css file red is: label-danger

    so to get it working change your config from label-important to label-danger. Thank you for rpi-monitor!

  14. Hi Xavier,

    the current regexp format can give false positives, for example:
    tcp .*:(80).*LISTEN --> this will match any listening port starting with 80 (so 8080, 8089...), and not exclusively 80, which you want to ensure.

    Adding a \s+ would fix the issue:
    tcp .*:(80)\s+.*LISTEN


  15. Is a server(webcam) on?:
    (maybe usefull for someone)
    dynamic.24.source=ping -c 1


  16. Hi,
    I am triying to add transmission-daemon to my services.conf but I can't make it work.

    this is my file now
    web just hangs -

    someone can help me?

    1. I fixed it removing non used services as mysql and https. Is there a max number of services for monitoring ?