Skip to content

Commit a037249

Browse files
committed
Merge pull request #58 from XavierBerger/devel
Version 2.8
2 parents 539e0f5 + 2fa34f8 commit a037249

38 files changed

+904
-1337
lines changed

PACKAGING.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
## Introduction
44
This document intended to help [**RPi-Monitor**](http://rpi-experiences.blogspot.fr/)'s package maintainer to know what to install and where.
55

6+
## Version
7+
This document describe file organisation for **Version 2.8**
8+
69
## Dependencies
710
**rpimonitord** is a perl script which require the following perl modules to work:
811

@@ -11,6 +14,7 @@ This document intended to help [**RPi-Monitor**](http://rpi-experiences.blogspot
1114
* libjson-perl
1215
* libipc-sharelite-perl
1316
* libfile-which-perl
17+
* aptitude (required by script checking upgradable packages)
1418

1519
## Installation
1620

@@ -26,9 +30,6 @@ This document intended to help [**RPi-Monitor**](http://rpi-experiences.blogspot
2630

2731
###Configuration
2832

29-
Since version 2.7:
30-
31-
* /etc/default/rpimonitor : *Init script configuration file*
3233
* /etc/rpimonitor/daemon.conf : *configuration of rpimonitord daemon*
3334
* /etc/rpimonitor/data.conf : *(symlink to template/<distribution>.conf) configuration of default data to be extracted and presented*
3435
* /etc/rpimonitor/\*.conf : *all other *.conf file will be parsed to look for data to be monitored*
@@ -48,7 +49,6 @@ The template directory is also containing some templates that can be used as exa
4849

4950
###Web Interface
5051

51-
* /usr/share/rpimonitor
5252
* /usr/share/rpimonitor/web : *Directory containing html*
5353
* /usr/share/rpimonitor/web/js: *Directory containing javascripts*
5454
* /usr/share/rpimonitor/web/css: *Directory containing style*
@@ -58,9 +58,11 @@ The template directory is also containing some templates that can be used as exa
5858

5959
When **RPi-Monitor** is configured to not use the internal server, the json are written on the disk into the web root directory /usr/share/rpimonitor/web
6060

61-
###Data
61+
###Scripts
6262

63-
Since version 2.7:
63+
* /usr/share/rpimonitor/scripts/updatePackagesStatus.pl: *Script periodically executed to update /var/lib/rpimonitor/updatestatus.txt*
64+
65+
###Data
6466

6567
* /var/lib/rpimonitor/web/stat : *Directory containing \*.rrd*
66-
* /var/lib/rpimonitor/updatestatus.txt: * Current status of packages*
68+
* /var/lib/rpimonitor/updatestatus.txt: *Current status of packages update*

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.7
1+
2.8
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# RPi-Monitor official repository
2+
deb https://github.com XavierBerger/RPi-Monitor-deb/raw/master/repo/

init/cron.d/rpimonitor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
05 03 * * * root /usr/bin/apt-get update > /dev/null 2>&1
33

44
# run at 03:10 to update status
5-
10 03 * * * root /etc/init.d/rpimonitor update > /dev/null 2>&1
5+
10 03 * * * root /usr/share/rpimonitor/scripts/updatePackagesStatus.pl
66

77

init/default/rpimonitor

Lines changed: 0 additions & 9 deletions
This file was deleted.

init/init.d/rpimonitor

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@
1515

1616
DAEMON="/usr/bin/rpimonitord"
1717
PIDFILE="/var/run/rpimonitord.pid"
18-
DEFAULTFILE="/etc/default/rpimonitor"
1918

2019
[ -x $DAEMON ] || exit 0
2120

22-
[ -r $DEFAULTFILE ] && . $DEFAULTFILE
23-
2421
checkroot(){
2522
if [ "$(id -u)" != "0" ]; then
2623
echo "This script must be run as root"
@@ -29,12 +26,6 @@ checkroot(){
2926
}
3027

3128
start() {
32-
if [ "$DAEMON_START" = "0" ]; then
33-
echo "RPi-Monitor deamon id disabled."
34-
echo "Update /etc/default/rpimonitor and set DEAMON_START to 1."
35-
return 0
36-
fi
37-
3829
touch $PIDFILE
3930

4031
for pid in $(cat $PIDFILE); do
@@ -80,19 +71,6 @@ status(){
8071
echo
8172
}
8273

83-
update(){
84-
if [ "$SHOW_PACKAGE_UPDATE" = "0" ]; then
85-
echo > /var/lib/rpimonitor/updatestatus.txt
86-
return 0
87-
fi
88-
89-
log_daemon_msg "RPi-Monitor" "Updating package status"
90-
LANG=C
91-
apt-get upgrade --dry-run| perl -ne '/(.*upgraded.*installed|^ \S+.*)/ and print "$1 "' 2>/dev/null > /var/lib/rpimonitor/updatestatus.txt
92-
status=$?
93-
log_end_msg $status
94-
}
95-
9674
checkroot
9775
case "$1" in
9876
start)
@@ -107,11 +85,8 @@ case "$1" in
10785
restart)
10886
restart
10987
;;
110-
update)
111-
update
112-
;;
11388
*)
114-
echo "Usage: $0 {start|stop|restart|status|update}"
89+
echo "Usage: $0 {start|stop|restart|status}"
11590
;;
11691
esac
11792

rpimonitor/daemon.conf

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,53 @@
55
# if embedded server should be started and its configuration.
66
#
77
########################################################################
8-
8+
#
99
# daemon.sharedmemkey=20130906
1010
# Define the share memory key
1111
#daemon.sharedmemkey=20130906
12-
12+
#
1313
# daemon.delay=10
1414
# Define the delay between 2 kpi pooling (default:10)
1515
# Note: If you want to change the default delay, the rrd file will
1616
# have to be deleted rpimonitord will recreate them at next startup
1717
#daemon.delay=10
18-
18+
#
1919
# daemon.timeout=10
2020
# Define the maximul duration of KPI extraction (default:5)
2121
#daemon.timeout=10
22-
22+
#
2323
# daemon.noserver=1
2424
# Define that rpimonitor shouldn't start web server (default:0)
2525
# Note: A symbolic link from /var/lib/rpimonitor/stat to
2626
# /usr/share/rpimonitor/stat may be required
2727
#daemon.noserver=1
28-
28+
#
2929
# daemon.addr=0.0.0.0
3030
# Define the address used by the web server (default:0.0.0.0)
3131
#daemon.addr=0.0.0.0
32-
32+
#
3333
# daemon.port=8888
3434
# Define port of the web server (default:8888)
3535
#daemon.port=8889
36-
36+
#
3737
# daemon.user=pi
3838
# Define user used to run the server process (default:pi)
3939
# Note: If user is not existing, process will run with uid=1000
4040
#daemon.user=pi
41-
41+
#
4242
# daemon.group=pi
4343
# Define group used to run the server process (default:pi)
4444
# Note: If group is not existing, process will run with gid=1000
4545
#daemon.group=pi
46-
46+
#
4747
# daemon.webroot=/usr/share/rpimonitor/web
4848
# Define the root directory of the web server (Default:/usr/share/rpimonitor/web)
4949
#daemon.webroot=/usr/share/rpimonitor/web
50-
50+
#
5151
# daemon.datastore=/var/lib/rpimonitor
5252
# Define the data storage directory (Default:/var/lib/rpimonitor)
5353
#daemon.datastore=/var/lib/rpimonitor
54-
54+
#
5555
# daemon.shellinabox=https://0.0.0.0:4200/
5656
# Define shellinabox address (Default: calculated automatically based on http request)
5757
#daemon.shellinabox=https://127.0.0.1:4200/

rpimonitor/rpimonitord

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ sub new
4141
$this->Debug(3,"");
4242
$this->{'rrd'}=();
4343
$this->{'daemon'}->{'confFiles'} = [];
44+
$this->{'counter'}->{'static'} = 0;
45+
$this->{'counter'}->{'dynamic'} = 0;
46+
$this->{'counter'}->{'status'} = 0;
47+
$this->{'counter'}->{'statistics'} = 0;
4448
return $this;
4549
}
4650

@@ -83,7 +87,7 @@ sub Load
8387
$this->{'daemon'}->{'delay'} ||= 10;
8488
$this->{'daemon'}->{'timeout'} ||= 5;
8589
$this->{'daemon'}->{'sharedmemkey'}||= 20130906;
86-
90+
8791
# Check user and group
8892
$this->{'daemon'}->{'gid'} = getgrnam($this->{'daemon'}->{'user'}) || 1000;
8993
$this->{'daemon'}->{'uid'} = getpwnam($this->{'daemon'}->{'group'}) || 1000;
@@ -112,6 +116,11 @@ sub Load
112116

113117
#print Data::Dumper->Dump([$this->{'rrdlist'}]);
114118

119+
# manage page common parameters
120+
$this->{'web'}->{'page'}->{'icon'} ||= 'img/logo.png';
121+
$this->{'web'}->{'page'}->{'menutitle'} ||= 'RPi-Monitor';
122+
$this->{'web'}->{'page'}->{'pagetitle'} ||= 'RPi-Monitor';
123+
115124
# manage menu
116125
foreach (@{$this->{'web'}->{'status'}}) {
117126
$_->{'name'} and push(@{$this->{'menu'}->{'status'}}, $_->{'name'});
@@ -127,6 +136,7 @@ sub Load
127136
) or die $!;
128137

129138
if ( $this->{'show'} ) {
139+
$Data::Dumper::Indent = 1;
130140
die Data::Dumper->Dump([$this]);
131141
}
132142
}
@@ -135,43 +145,69 @@ sub LoadFile
135145
{
136146
my $this = shift;
137147
my $confFile = shift;
148+
my $dict;
138149
$this->Debug(2,"Loading file: $confFile");
139150

140151
open ( FILE, $confFile)
141152
or die "Error while openning configuration file \"$confFile\" because $!\n";
142153
while (<FILE>){
143154
chomp;
144155
/^\s*#|^$/ and next; # Ignore comments
156+
/^include=(.*)/ and -f $1 and push($this->{'daemon'}->{'confFiles'}, $1) and next;
145157
my ($key, $value) = /^([^=]*)=(.*)/; # Extract key and value
146158
my @leaves=split('\.', $key); # Explode key and construct config hash
147159
my $tree=$this;
160+
my $previous;
148161
my $current;
149162
my $next;
150-
while (scalar(@leaves) > 0) {
151-
$current ||= shift (@leaves);
152-
$next = shift (@leaves);
153-
if ( $next =~ /^\d+$/ ) {
154-
if ($current =~ /^\d+$/) {
155-
@{$tree}[$current-1] ||= [];
156-
$tree=@{$tree}[$current-1];
163+
my $root;
164+
while (scalar(@leaves) > 0) { # While @leaves contains data
165+
$current ||= shift (@leaves); # If root is empty, shift the first element of @leaves to $current
166+
$root ||= $current;
167+
if ( $root eq 'web' ) { $root = $current }
168+
$next = shift (@leaves); # Shift the first element of @leaves in $next
169+
if ( $next =~ /^\d+$/ ) { # If $next is an integer -> we are in an array
170+
if ($current =~ /^\d+$/) { # If $current is an integer -> we are in an array
171+
@{$tree}[$current-1] ||= []; # If the branch is not an array, create an empty array
172+
$tree=@{$tree}[$current-1]; # Define this array as $tree root
157173
}
158174
else {
159-
$tree->{$current} ||= [];
160-
$tree=$tree->{$current};
175+
$tree->{$current} ||= []; # If the branch is not an array, create an empty array
176+
$tree=$tree->{$current}; # Define this array as $tree root
161177
}
162-
} else {
163-
if ($current =~ /^\d+$/) {
164-
@{$tree}[$current-1] ||= {};
165-
$tree=@{$tree}[$current-1];
178+
} else { # If $next is not an integer -> We are in a hash
179+
if ($current =~ /^\d+$/) { # If $current is an integer -> we are in an array
180+
my $index = $current;
181+
182+
# Manage per file indexes unicity
183+
if ( ($root eq "static") ||
184+
($root eq "dynamic") ||
185+
( ( ($root eq 'status' ) ||
186+
($root eq 'statistics' ) ) &&
187+
($previous eq "content") ) )
188+
{
189+
# If $index is not in $dict, add it with counter++
190+
if ( ! $dict->{$root}[$current] )
191+
{
192+
$dict->{$root}[$current] = ++$this->{'counter'}->{$root};
193+
}
194+
$index = $dict->{$root}[$current];
195+
}
196+
197+
@{$tree}[$index-1] ||= {}; # If the branch is not an array, create an empty hash
198+
$tree=@{$tree}[$index-1]; # Define this hash as $tree root
166199
}
167-
else {
168-
$tree->{$current} ||= {};
169-
$tree=$tree->{$current};
200+
else { # We are in a hash
201+
$tree->{$current} ||= {}; # If the branch is not an array, create an empty hash
202+
$tree=$tree->{$current}; # Define this hash as $tree root
170203
}
171204
}
172205
if ( ($next eq 'rrd') and $value) { push(@{$this->{'rrd'}},$tree) };
206+
$previous = $current;
173207
$current = $next;
174208
}
209+
210+
# Add value
175211
if ($current =~ /^\d+$/) {
176212
@{$tree}[$current-1] = $value;
177213
}
@@ -242,6 +278,7 @@ sub new
242278
"/statistics.json",
243279
"/menu.json",
244280
"/friends.json",
281+
"/page.json",
245282
"/version.json",
246283
"/favicon.ico",
247284

@@ -439,6 +476,7 @@ sub Run
439476
$this->{'status'} = encode_json(\@{$configuration->{'web'}->{'status'}});
440477
$this->{'statistics'} = encode_json(\@{$configuration->{'web'}->{'statistics'}});
441478
$this->{'friends'} = encode_json(\@{$configuration->{'web'}->{'friends'}});
479+
$this->{'page'} = encode_json(\%{$configuration->{'web'}->{'page'}});
442480
$this->{'static'} = encode_json(\%{$monitor->{'static'}});
443481
$this->{'menu'} = encode_json(\%{$configuration->{'menu'}});
444482
$this->{'version'} = "{\"version\":\"$configuration->{'version'}\"}";
@@ -519,6 +557,10 @@ sub Run
519557
or warn $!;
520558
print FILE encode_json \@{$configuration->{'web'}->{'status'}} ;
521559
close(FILE);
560+
open(FILE, "> $configuration->{'daemon'}->{'webroot'}/page.json")
561+
or warn $!;
562+
print FILE encode_json \%{$configuration->{'web'}->{'page'}} ;
563+
close(FILE);
522564
open(FILE, "> $configuration->{'daemon'}->{'webroot'}/statistics.json")
523565
or warn $!;
524566
print FILE encode_json \@{$configuration->{'web'}->{'statistics'}} ;
@@ -935,6 +977,7 @@ sub Run
935977
package main;
936978
use strict;
937979
use POSIX;
980+
use Sys::Hostname;
938981
939982
sub help
940983
{
@@ -1077,6 +1120,7 @@ $pidfile and &daemonize;
10771120
my $monitor = Monitor->new();
10781121
# Process data that should be extracted once, before the server starts
10791122
$monitor->Process($configuration,'static');
1123+
$monitor->{'static'}->{'hostname'} = hostname();
10801124

10811125
$SIG{INT} = sub { stop(); }; # catch Ctrl+C
10821126

0 commit comments

Comments
 (0)