Wednesday, May 8, 2013

RPi-Monitor: Raspberry Pi self monitoring

Note: A new version of RPi-Monitor is available: Version 1.1
All the details about the latest version of Rpi-Monitor are in RPi-Monitor overview

I would like be able to know in real time what is the status of the RPi and also to have an historical view of what happen in time.

As I didn't find an existing software that match my need and idea so, I decided to develop my own application and RPi-Monitor was born.

RPi-Monitor - Web Interface

The purpose of this post is be to describe RPi-Monitor and to explain and how you can install it and use it.



History and architecture of the project

Before starting the development of a new program I first had a look into Internet and I found some interesting thing like:
  • Raspcontrol which is giving an instant view on the RPi status and allow to do some action from the Web interface. An analyse of the chosen architecture show me that it is not really secure and is depending on an external web server. This two acpect of the design are enough for me to not retain this solution. Raspcontrol has a nice looking interface and I like it so, I'll reuse the same images and a similar look and feel of the status page.
  • I also find this web site http://youresuchageek.blogspot.fr/2013/01/howto-raspberry-pi-monitor-your.html explaining how to monitor the RPi but propose to include the RPi inside a global monitoring solution I like the graphs produced here but the solution is too heavy to match my needs. 
None of these application was matching my ideas and needs so I decided to develop RPI-Monitor.

For performance and security reason, RPi-Monitor separates the extraction of the information from the presentation of the information.

The extraction of the information is done by a process designed to run as a daemon (which can and will be executed as root). The extracted key performance indicators (KPI) from the computer are stored them into a Round Robin Database (RRD) to keep an history of the health of the computer.  The perl script rpimonitord which is extracting the information also starts the embedded web server giving access to the pages. The web server is running into a separate process owned by a non root user (the user 'pi' by default). This process is designed to return only the pages of RPi-Monitor and is working in read only.

The presentation of the information is performed by HTML5 pages. These pages dynamically download the information extracted by the daemon and perform the rendering the in a nice looking format (using bootstrap, jquery, jsqrencode and javascriptrrd). This design has the advantage in an embedded architecture to offload the server task and delegate processing and rendering to the client. The server is doing his jobs of server: processing data. The client is doing his job of client: showing nice looking interfaces to the human users.

Finally note that the embedded server doesn't provide access control or authentication. The role of RPi-Monitor is to monitor. The access control could be delegated to additional program designed for that. That's why it is still possible to not start the embedded web server and use an external web server to deliver the pages but we will see in next post a clean way to improve the security of RPi.


Installation

After this long introduction let's start to play with the program itself. First download the debian package from Github. You can use the following command directly from the RPi:

    wget https://github.com/XavierBerger/RPi-Monitor-deb/blob/master/packages/rpimonitor_1.0-1_all.deb?raw=true -O rpimonitor_1.0-1_all.deb

Install the dependencies by executing the following command:

    sudo apt-get install librrds-perl libhttp-daemon-perl libhttp-daemon-ssl-perl

Install RPI-Monitor as a standard debian package with the following command:

    sudo dpkg -i rpimonitor_1.0-1_all.deb

The installation is done, you can immediately browse http://RPiIpAddress:8888/. In the next chapter, we will see what RPi-Monitor is able to do.


Let's have a look to the interface

Open your favorite browser and go to http://RPiIpAddresss:8888/.

The first page you will see contains a qrcode that can be flashed with a smartphone to directly access to RPi-Monitor start page. This qrcode is containing the address of the page currently displayed so be sure this page is reachable from you smartphone before flashing.

RPi-Monitor - Web Interface welcome screen

Pressing the start button will drive you to the status page. This page will automatically download the current status from the server and will display the content in a nice looking view.

RPi-Monitor - Status page
The displayed information are gathered into 8 sections:

  • Version
  • Uptime 
  • CPU
  • Temperature
  • Memory
  • Swap
  • SD card
  • Network

In configuration page (accessible from the top menu), you can check auto refresh to automatically update the page every 10 seconds.

The statistics page is accessible from the top menu. Accessing this page will automatically download statistics files (rrd)  and will allow you to choose which data to draw within a fully interactive interface.

RPi-Monitor - Statistics page
You can select the graph to display from the top left drop down list. The graphs are fully interactive, it is possible to zoom inside the graph just by doing a drag and drop of the mouse inside the graph. The right panel allow to select the curve to be display. The position of the legend as well as the timescale are also configurable from the bottom drop down lists.

To go further

For more detail refer to GitHub : https://github.com/XavierBerger/RPi-Monitor and https://github.com/XavierBerger/RPi-Monitor-deb

This version of RPi-Monitor is implementing only the basic features and will still receive improvement.

If you feel that some improvement are needed or features should be add fill free to add comment in this post on directly in Github project page : https://github.com/XavierBerger/RPi-Monitor

The next feature to be implemented will be:
  • Add warning and critical levels and define warning and critical levels
  • Complete the development of https (experimental code already available in version 1.0)
  • Add more information in Version section coming from /proc/cpuinfo
  • Integrate shellinabox into the web interface (experimental code already available in version 1.0)




12 comments :

  1. This looks great. Thanks. But the wget method you give for retrieving the package gives me a page of html, not a .deb package.

    ReplyDelete
    Replies
    1. That was true and the command line has been fixed. Thanks for the feedback.

      Delete
  2. Merci Xavier pour cet outil, j'ai un peu galéré à l'installer car je devais utiliser l'ancienne méthode d'installation que je trouvais là:

    https://github.com/XavierBerger/RPi-Monitor/blob/master/INSTALL.md

    Bref, j'ai fini par réussir avec la méthode que tu indique ci-dessus.
    Ensuite j'ai voulu changé le numéro du port, je n'ai pas trouvé d'autre méthode que de modifier:

    /usr/bin/rpimonitord

    Y'a t'il une méthode plus propre ?

    ReplyDelete
    Replies
    1. La méthode la plus propre pour modifier durablement la configuration de rpimonitord est de modifier le fichier rpimonitord.conf utilisé par l'application. L'installation standard utilise /etc/rpimonitord.conf. En démarrage manuel, rpimonitord cherche ce fichier dans le même répertoire que l'executable. Il edt aussi possible de modifier la configuration avec la ligne de commande.

      L'aide à porpos de la ligne de commande est accessible avec l'option --help: rpimonitor --help .
      Le format du fichier de configuration est décrit dans le fichier lui même.

      Delete
  3. For those who wold like to customize the behavior of RP-Monitor, I did create a page in wiki ( https://github.com/XavierBerger/RPi-Monitor/wiki ) explaining how to do.

    ReplyDelete
  4. Super c'est joli et synthétique !

    ReplyDelete
  5. Sympa :D

    Mais il existait Raspcontrol aussi qui est pratique :p

    ReplyDelete
  6. Thanks, this looks amazing. I followed your instructions for installation however, when I try to start the daemon I get the message "Error while opening : No such file or directory". Can anyone help?

    ReplyDelete
    Replies
    1. The post you commented is quite outdated... You should uninstall RPi-Monitor (dpkg --purge rpimonitor) and resinstall it following the latest instructions you can find in this blog.

      Delete
  7. Hi, is there a way to change the temp to degrees Fahrenheit and change the network monitor to WLAN0 in the web interface?

    ReplyDelete
    Replies
    1. Hi Steve,

      First you should better use the latest version of RPi-Monitor which is today version 2.4.

      Secondly, yes you can do these 2 actions.
      To change from eth0 to wlan0, edit the file /etc/rpimonitord.conf.d/default and replace eth0 by wlan0.
      To have the temperature in °F, you should change the post-processing formula from $1/1000 to ($1/1000)*1.8+32 into the same file.

      Finally, to go deeper in customization, you should have a look to the different post I wrote explaining how to customize and adapt RPi-Monitor to your need. A good start is in the top menu of this blog: "RPi-Monitor Articles"

      Delete
    2. Thanks Xavier! I just got the wlan0 figured out right before you replied! I'm still new to the Pi and Linux and it's all just fascinating to me! The monitor you designed is exactly what a noob like me needs! I use my Pi primarily for streaming a police scanner audio feed to the Internet and just like to be able to keep an eye on whats going on with it. I'll give the formula a shot first and then check out your articles. Thanks Again!

      Delete