Raspberry Pi monitor: Difference between revisions

From WickyWiki
mNo edit summary
 
(40 intermediate revisions by the same user not shown)
Line 3: Line 3:
[[Category:20180121]]
[[Category:20180121]]


= Links =
= Info =


With RPi-Monitor you can monitor various aspects of your Raspberry Pi. The package has its own simple webserver. It works well for smaller screens (mobile phone) and history can be visualized with some graphs. If it still isn't to your liking it allows for some serious tinkering.
With RPi-Monitor you can monitor various aspects of your Raspberry Pi. The package has its own simple webserver. It works well for smaller screens (mobile phone) and history can be visualized with some graphs. If it still isn't to your liking it allows for some serious tinkering.


* http://rpi-experiences.blogspot.nl/p/rpi-monitor-installation.html
* https://xavierberger.github.io/RPi-Monitor-docs/index.html
* https://github.com/XavierBerger/RPi-Monitor
* https://github.com/XavierBerger/RPi-Monitor


Line 15: Line 15:
= Install =
= Install =


* https://xavierberger.github.io/RPi-Monitor-docs/11_installation.html
Install packages:


<syntaxhighlight lang=bash>
<source lang=bash>
echo "deb http://www.giteduberger.fr rpimonitor/" | sudo tee /etc/apt/sources.list.d/rpimonitor.list
sudo apt install librrds-perl libhttp-daemon-perl libjson-perl libipc-sharelite-perl
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 2C0D3C0F
sudo apt install libfile-which-perl libsnmp-extension-passpersist-perl
sudo apt-get update
sudo apt install aptitude
sudo apt-get install rpimonitor
</source>
</syntaxhighlight>


= Remove =
Download and install monitor:


Repository:
<source lang=bash>
wget https://github.com/XavierBerger/RPi-Monitor-deb/blob/develop/packages/rpimonitor_latest.deb
sudo dpkg -i rpimonitor_latest.deb
</source>


<syntaxhighlight lang=bash>
= Remove =
sudo rm /etc/apt/sources.list.d/rpimonitor.list
sudo apt-key del 2C0D3C0F
</syntaxhighlight>


Monitor package:
Monitor package:
Line 67: Line 66:
== Modify interval ==
== Modify interval ==


Default is 10 seconds, changed it to 150 seconds (2.5min).
Default is 10 seconds, changed it to 30 seconds.


<syntaxhighlight lang=bash>
<source lang=bash>
sudo nano -l +17 /etc/rpimonitor/daemon.conf
sudo nano -l +6 /etc/rpimonitor/daemon.conf
</syntaxhighlight>
</source>


<blockquote>
<blockquote>
<syntaxhighlight lang=bash>
<source lang=bash>
daemon.delay=150
daemon.delay=30
</syntaxhighlight>
</source>
</blockquote>
</blockquote>


<syntaxhighlight lang=bash>
<source lang=bash>
sudo systemctl restart rpimonitor
sudo systemctl restart rpimonitor
</syntaxhighlight>
</source>


== Network monitoring ==
Note: that if you change the delay, you probably want to delete the "rrd" files that contain the graph history. The delay is used during their creation. They wil be automatically recreated but obviously you will loose the history.


Uncomment all lines that are commented and comment the lines that contain the configuration message.
<source lang=bash>
sudo rm /var/lib/rpimonitor/stat/*.rrd
</source>


<syntaxhighlight lang=bash>
<source lang=bash>
sudo nano /etc/rpimonitor/template/network.conf
sudo systemctl restart rpimonitor
</syntaxhighlight>
</source>


== Update upgradables ==
More info:
* https://oss.oetiker.ch/rrdtool/
* https://codeblog.dotsandbrackets.com/quick-intro-to-rrdtool/


After you upgrade your system:
== Network monitoring ==


<syntaxhighlight lang=bash>
Uncomment all lines that are commented and comment the lines that contain the configuration message.
sudo apt upgrade
</syntaxhighlight>
 
The upgradable packages keep being listed, this is only refreshed once a day. You can do this manually with:


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
sudo /etc/init.d/rpimonitor update
sudo nano /etc/rpimonitor/template/network.conf
</syntaxhighlight>
 
= Backup modified files =
 
<syntaxhighlight lang=bash>
zip ~/rpi-monitor-files.zip /etc/rpimonitor/daemon.conf
zip ~/rpi-monitor-files.zip /etc/rpimonitor/template/raspbian.conf
 
zip ~/rpi-monitor-files.zip /etc/rpimonitor/template/services.conf
zip ~/rpi-monitor-files.zip /etc/rpimonitor/template/version.conf
zip ~/rpi-monitor-files.zip /etc/rpimonitor/template/uptime.conf
zip ~/rpi-monitor-files.zip /etc/rpimonitor/template/cpu.conf
zip ~/rpi-monitor-files.zip /etc/rpimonitor/template/temperature.conf
zip ~/rpi-monitor-files.zip /etc/rpimonitor/template/memory.conf
zip ~/rpi-monitor-files.zip /etc/rpimonitor/template/swap.conf
zip ~/rpi-monitor-files.zip /etc/rpimonitor/template/sdcard.conf
zip ~/rpi-monitor-files.zip /etc/rpimonitor/template/network.conf  
zip ~/rpi-monitor-files.zip /usr/share/rpimonitor/web/js/rpimonitor.statistics.js
</syntaxhighlight>
</syntaxhighlight>


Line 151: Line 132:
<blockquote>
<blockquote>
<syntaxhighlight lang=css>
<syntaxhighlight lang=css>
dynamic.1.source=/proc/uptime
dynamic.1.regexp=(^\S+)
dynamic.1.name=cpu_frequency
dynamic.1.name=cpu_frequency
dynamic.1.source=vcgencmd measure_clock arm | sed -e "s/frequency(45)=//g"
dynamic.1.source=vcgencmd measure_clock arm | sed -e "s/frequency(45)=//g"
dynamic.1.regexp=(.*)
dynamic.1.postprocess=$1/1000000
dynamic.1.postprocess=$1/1000000
dynamic.1.rrd=
dynamic.1.rrd=
Line 167: Line 146:
Modify the function Start() in "rpimonitor.statistics.js" to read a parameter 'graph':
Modify the function Start() in "rpimonitor.statistics.js" to read a parameter 'graph':


<syntaxhighlight lang=bash>
<source lang=bash>
sudo nano -l +26 /usr/share/rpimonitor/web/js/rpimonitor.statistics.js
sudo nano -l +26 /usr/share/rpimonitor/web/js/rpimonitor.statistics.js
</syntaxhighlight>
</source>


<blockquote>
<blockquote>
<syntaxhighlight lang=js>
<source lang=js>


// ...
// ...
Line 194: Line 173:


// ...
// ...
</syntaxhighlight>
</source>
</blockquote>
</blockquote>


Then modify "uptime.conf" (graph=0) to include a link to the graph. Same for for "cpu.conf" (graph=1), "temperature.conf" (graph=2), etc:
Then modify "uptime.conf" (graph=0) to include a link to the graph. Same for for "cpu.conf" (graph=1), "temperature.conf" (graph=2), etc:


<syntaxhighlight lang=bash>
<source lang=bash>
sudo nano /etc/rpimonitor/template/uptime.conf
sudo nano /etc/rpimonitor/template/uptime.conf
</syntaxhighlight>
</source>


<blockquote>
<blockquote>
<syntaxhighlight lang=js>
<source lang=js>
web.status.1.content.1.name=<a target=_blank href=statistics.html?graph=0>Uptime</a>
web.status.1.content.1.name=<a target=_blank href=statistics.html?graph=0>Uptime</a>
</syntaxhighlight>
</source>
</blockquote>
</blockquote>


= RPi Built-in Webserver problem =
== Link to logfiles ==
 
<!-- main.1.log -->
 
<source lang=bash>
cd /usr/share/rpimonitor/web
sudo ln -f -s /var/log/wjv/main.log main.log.txt
sudo ln -f -s /var/log/wjv/main.log.1 main.log.1.txt
</source>


The Web-server seems to stop regularly. In the Perl code (rpimonitord) there is a "Check if the server is up" part in "Monitor->Run". This is called once every "daemon.delay". With a higher daemon.delay the problem is quite annoying. I changed the code to break-up the delay in 10s parts and check the server every 10s. The problem will still be there but now I only need to wait 10 sec.
== Graph dips and spikes ==
 
There seems to be a problem where recorded values show dips and spikes while the actual value doesn't change. For example, receiving 2.478 continuously, the recorded value would fall to 2.446, then jump to 2.510 and then goes back to 2.478. This may happen about every 10 minutes. Note that at this time the recording delay was set at 60 seconds.


<syntaxhighlight lang=bash>
Setting the delay to be around 60 seconds probably causes RRD intervals (of 60 seconds) without a recorded value and therefore anomalies in the recorded values. It looks like this will happen a lot less with a lower value for the delay.
sudo nano -l +676 /usr/bin/rpimonitord
</syntaxhighlight>


My changes:
== Using LAST instead of AVERAGE ==


<syntaxhighlight lang=perl highlight="9,12,18,22,24,27,32" start=663 line>
I modified the consolidation function to "LAST" instead of "AVERAGE" for the small intervals so it would record exact values.
...


for(;;)
Modify the source code (Perl):
{
...


# tempo before next process
<source lang=bash>
sudo nano -l +309 /usr/bin/rpimonitord
## exit the 'for' loop if the delay-option is not set
</source>
$configuration->{'daemon'}->{'delay'} or last;
## disabled the full delay
#sleep $configuration->{'daemon'}->{'delay'};


my $keeplooping = 1;
<source lang=perl>
my $waited = 0;
...
while($waited < $configuration->{'daemon'}->{'delay'}) {
RRDs::create( "$filename",
   ## sleep in 10 second parts
"--start", $start,
  sleep 10;
"--step", $this->{'daemon'}->{'delay'},
  $waited = $waited + 10;
"DS:$name:$type:600:$min:$max",
"RRA:LAST:0.5:1:8640",    # 1 day with interval of 10sec
"RRA:LAST:0.5:6:2880",   # 2 day with interval of 1min
"RRA:AVERAGE:0.5:60:2016",  # 2 week with interval of 10min
"RRA:AVERAGE:0.5:180:1488",  # 1 month with interval of 30min
"RRA:AVERAGE:0.5:360:8784"  # 1 year with interval of 1hour
);
...
</source>


  ## skip if noserver-option is set
The files need to be deleted and will be re-created on rspat of the service. RRD file info:
  if ( !$configuration->{'daemon'}->{'noserver'}) {
        ## kill will return 'true' if the process is running, it doesn't kill anything
        $keeplooping = kill(0,$serverpid);
        $this->Debug(2,"Check server active $keeplooping");
        ## exit the 'while' loop if $keeplooping is 'false'
        $keeplooping or last;
  }
}


## exit the 'for' loop if $keeplooping is 'false', this will restart the Web-server process
<source lang=bash>
$keeplooping or last;
#backup-remove
}
sudo mv /var/lib/rpimonitor/stat/soc_temp.rrd /var/lib/rpimonitor/stat/soc_temp.rrd.bak
#restart
sudo systemctl restart rpimonitor
#check
rrdtool info /var/lib/rpimonitor/stat/soc_temp.rrd
</source>


...
= Debugging =
</syntaxhighlight>


The StartServer-code is around line 1335:
The StartServer-code is around line 1335:
Line 271: Line 255:
</syntaxhighlight>
</syntaxhighlight>


= Make it work with Apache Webserver =
= Make it work with a webserver =
 
The Web-server seems to stop regularly. In the Perl code (rpimonitord) there is a "Check if the server is up" part in "Monitor->Run". This is called once every "daemon.delay". With a higher daemon.delay the problem is quite annoying. I changed the code to break-up the delay in 10s parts and check the server every 10s. The problem will still be there but now I only need to wait 10 sec.
 
Disable the built-in webserver:
 
<syntaxhighlight lang=bash>
sudo nano /etc/rpimonitor/daemon.conf
 
daemon.noserver=1
</syntaxhighlight>
 
Problem: the rdd files can't be found by apache. We add a symbolic link to point to the right place:
 
<syntaxhighlight lang=bash>
cd /usr/share/rpimonitor/web
sudo ln -s /var/lib/rpimonitor/stat stat
</syntaxhighlight>
 
Restart:
 
<syntaxhighlight lang=bash>
sudo service rpimonitor restart
</syntaxhighlight>


Some tips (nginx Webserver):
Go to:
* https://xavierberger.github.io/RPi-Monitor-docs/35_external.html
* http://<yourserver>/rpimonitor/status.html


Configure Apeche2 webserver:
== Configure Apache2 webserver, port 80 virtual directory ==


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
Line 296: Line 303:
</syntaxhighlight>
</syntaxhighlight>


Go to:
== Configure Nginx webserver, port 80 virtual directory ==
* http://<yourserver>/rpimonitor


Disable the built-in webserver:
Some tips (for use of nginx webserver):
* https://xavierberger.github.io/RPi-Monitor-docs/35_external.html
* [[Nginx webserver configuration]]


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
sudo nano /etc/rpimonitor/daemon.conf
sudo nano /etc/nginx/sites-available/raspberrypi4
 
  server
  {
    listen      80;
    server_name wjv.duckdns.org;
    autoindex off;
    index index.htm;
 
    location /rpimonitor {
        alias /usr/share/rpimonitor/web;
        allow all;
    }
  }
</syntaxhighlight>
 
Restart:


daemon.noserver=1
<syntaxhighlight lang=bash>
sudo systemctl restart nginx
</syntaxhighlight>
</syntaxhighlight>


Problem: the rdd files can't be found by apache. We add a symbolic link to point to the right place:
= Snippets =
 
== Apply pending upgrades ==
<!-- updates -->
The monitor notifies you of pending upgrades. To apply the upgrades:


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
cd /usr/share/rpimonitor/web
pihole -up
sudo ln -s /var/lib/rpimonitor/stat stat
sudo apt upgrade
</syntaxhighlight>
</syntaxhighlight>


Restart:
Upgradable packages are refreshed once a day. To force a refresh manually:


<syntaxhighlight lang=bash>
<syntaxhighlight lang=bash>
sudo service rpimonitor restart
sudo /etc/init.d/rpimonitor update
sudo systemctl restart rpimonitor
</syntaxhighlight>
</syntaxhighlight>

Latest revision as of 19:58, 19 December 2025


Info

With RPi-Monitor you can monitor various aspects of your Raspberry Pi. The package has its own simple webserver. It works well for smaller screens (mobile phone) and history can be visualized with some graphs. If it still isn't to your liking it allows for some serious tinkering.

Local webservice, access within the local network with:

Install

Install packages:

sudo apt install librrds-perl libhttp-daemon-perl libjson-perl libipc-sharelite-perl 
sudo apt install libfile-which-perl libsnmp-extension-passpersist-perl
sudo apt install aptitude

Download and install monitor:

wget https://github.com/XavierBerger/RPi-Monitor-deb/blob/develop/packages/rpimonitor_latest.deb
sudo dpkg -i rpimonitor_latest.deb

Remove

Monitor package:

sudo apt-get purge rpimonitor
rm -fr /etc/rpimonitor
rm -fr /usr/share/rpimonitor

Configure

Documentation

man rpimonitord
man rpimonitord.conf
rpimonitord -i

Main configuration files

Main configuration-file with possible references to the other templates:

sudo nano /etc/rpimonitor/template/raspbian.conf

Configuration of the daemon:

sudo nano /etc/rpimonitor/daemon.conf

Modify interval

Default is 10 seconds, changed it to 30 seconds.

sudo nano -l +6 /etc/rpimonitor/daemon.conf
daemon.delay=30
sudo systemctl restart rpimonitor

Note: that if you change the delay, you probably want to delete the "rrd" files that contain the graph history. The delay is used during their creation. They wil be automatically recreated but obviously you will loose the history.

sudo rm /var/lib/rpimonitor/stat/*.rrd
sudo systemctl restart rpimonitor

More info:

Network monitoring

Uncomment all lines that are commented and comment the lines that contain the configuration message.

sudo nano /etc/rpimonitor/template/network.conf

Tweaking

Edit services.conf to check for running apache webservice

sudo nano /etc/rpimonitor/template/services.conf
dynamic.3.name=http
dynamic.3.source=systemctl show -p SubState --value apache2
dynamic.3.regexp=(.*)

web.status.1.content.1.line.1= Label(data.http,"=='running'","Apache","success") + Label(data.http,"!='running'","apache","danger")

Edit cpu.conf to include CPU throttling

(Rapberry Pi 3)

sudo nano /etc/rpimonitor/template/cpu.conf
dynamic.1.name=cpu_frequency
dynamic.1.source=vcgencmd measure_clock arm | sed -e "s/frequency(45)=//g"
dynamic.1.regexp=(.*)
dynamic.1.postprocess=$1/1000000
dynamic.1.rrd=

Link from the main page directly to the corresponding graph

  • Included in new version v2.13+

Modify the function Start() in "rpimonitor.statistics.js" to read a parameter 'graph':

sudo nano -l +26 /usr/share/rpimonitor/web/js/rpimonitor.statistics.js

// ...

function Start() {
  static = getData('static')
  graphconf = getData('statistics')

  //modified: read activestat from url graph parameter
  activestat = GetURLParameter('graph');
  if (activestat == null){
    activestat = localStorage.getItem('activestat') || 0;
  }

  // ... unchanged ...

  activePage = GetURLParameter('activePage');

  // ...
}

// ...

Then modify "uptime.conf" (graph=0) to include a link to the graph. Same for for "cpu.conf" (graph=1), "temperature.conf" (graph=2), etc:

sudo nano /etc/rpimonitor/template/uptime.conf
web.status.1.content.1.name=<a target=_blank href=statistics.html?graph=0>Uptime</a>

Link to logfiles

cd /usr/share/rpimonitor/web
sudo ln -f -s /var/log/wjv/main.log main.log.txt
sudo ln -f -s /var/log/wjv/main.log.1 main.log.1.txt

Graph dips and spikes

There seems to be a problem where recorded values show dips and spikes while the actual value doesn't change. For example, receiving 2.478 continuously, the recorded value would fall to 2.446, then jump to 2.510 and then goes back to 2.478. This may happen about every 10 minutes. Note that at this time the recording delay was set at 60 seconds.

Setting the delay to be around 60 seconds probably causes RRD intervals (of 60 seconds) without a recorded value and therefore anomalies in the recorded values. It looks like this will happen a lot less with a lower value for the delay.

Using LAST instead of AVERAGE

I modified the consolidation function to "LAST" instead of "AVERAGE" for the small intervals so it would record exact values.

Modify the source code (Perl):

sudo nano -l +309 /usr/bin/rpimonitord
	...
	RRDs::create( "$filename",
		"--start", $start,
		"--step", $this->{'daemon'}->{'delay'},
		"DS:$name:$type:600:$min:$max",
		"RRA:LAST:0.5:1:8640",    # 1 day with interval of 10sec
		"RRA:LAST:0.5:6:2880",    # 2 day with interval of 1min
		"RRA:AVERAGE:0.5:60:2016",   # 2 week with interval of 10min
		"RRA:AVERAGE:0.5:180:1488",  # 1 month with interval of 30min
		"RRA:AVERAGE:0.5:360:8784"   # 1 year with interval of 1hour
		);
	...

The files need to be deleted and will be re-created on rspat of the service. RRD file info:

#backup-remove
sudo mv /var/lib/rpimonitor/stat/soc_temp.rrd /var/lib/rpimonitor/stat/soc_temp.rrd.bak
#restart
sudo systemctl restart rpimonitor
#check
rrdtool info /var/lib/rpimonitor/stat/soc_temp.rrd

Debugging

The StartServer-code is around line 1335:

sudo nano -l +1335 /usr/bin/rpimonitord

Start RPi-Monitor in a terminal with logging:

sudo systemctl stop rpimonitor
sudo rpimonitord -vvvvvv

Make it work with a webserver

The Web-server seems to stop regularly. In the Perl code (rpimonitord) there is a "Check if the server is up" part in "Monitor->Run". This is called once every "daemon.delay". With a higher daemon.delay the problem is quite annoying. I changed the code to break-up the delay in 10s parts and check the server every 10s. The problem will still be there but now I only need to wait 10 sec.

Disable the built-in webserver:

sudo nano /etc/rpimonitor/daemon.conf

	daemon.noserver=1

Problem: the rdd files can't be found by apache. We add a symbolic link to point to the right place:

cd /usr/share/rpimonitor/web
sudo ln -s /var/lib/rpimonitor/stat stat

Restart:

sudo service rpimonitor restart

Go to:

  • http://<yourserver>/rpimonitor/status.html

Configure Apache2 webserver, port 80 virtual directory

sudo nano /etc/apache2/sites-available/raspberrypi.conf

	<VirtualHost _default_:80>
	 Alias /rpimonitor/ /usr/share/rpimonitor/web/
	 <Directory /usr/share/rpimonitor/web/>
	  AllowOverride None
	  Require all granted
	 </Directory>
	</VirtualHost>

Restart:

sudo systemctl restart apache2

Configure Nginx webserver, port 80 virtual directory

Some tips (for use of nginx webserver):

sudo nano /etc/nginx/sites-available/raspberrypi4

  server
  {
    listen      80;
    server_name wjv.duckdns.org;
    autoindex off;
    index index.htm;

    location /rpimonitor {
        alias /usr/share/rpimonitor/web;
        allow all;
    }
  }

Restart:

sudo systemctl restart nginx

Snippets

Apply pending upgrades

The monitor notifies you of pending upgrades. To apply the upgrades:

pihole -up
sudo apt upgrade

Upgradable packages are refreshed once a day. To force a refresh manually:

sudo /etc/init.d/rpimonitor update
sudo systemctl restart rpimonitor