Skip to content

Commit

Permalink
Merge pull request #58 from XavierBerger/devel
Browse files Browse the repository at this point in the history
Version 2.8
  • Loading branch information
XavierBerger committed Sep 13, 2014
2 parents 539e0f5 + 2fa34f8 commit a037249
Show file tree
Hide file tree
Showing 38 changed files with 904 additions and 1,337 deletions.
16 changes: 9 additions & 7 deletions PACKAGING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## Introduction
This document intended to help [**RPi-Monitor**](http://rpi-experiences.blogspot.fr/)'s package maintainer to know what to install and where.

## Version
This document describe file organisation for **Version 2.8**

## Dependencies
**rpimonitord** is a perl script which require the following perl modules to work:

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

## Installation

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

###Configuration

Since version 2.7:

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

###Web Interface

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

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

###Data
###Scripts

Since version 2.7:
* /usr/share/rpimonitor/scripts/updatePackagesStatus.pl: *Script periodically executed to update /var/lib/rpimonitor/updatestatus.txt*

###Data

* /var/lib/rpimonitor/web/stat : *Directory containing \*.rrd*
* /var/lib/rpimonitor/updatestatus.txt: * Current status of packages*
* /var/lib/rpimonitor/updatestatus.txt: *Current status of packages update*
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7
2.8
2 changes: 2 additions & 0 deletions init/apt/sources.list.d/rpimonitor.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# RPi-Monitor official repository
deb https://github.com XavierBerger/RPi-Monitor-deb/raw/master/repo/
2 changes: 1 addition & 1 deletion init/cron.d/rpimonitor
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
05 03 * * * root /usr/bin/apt-get update > /dev/null 2>&1

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


9 changes: 0 additions & 9 deletions init/default/rpimonitor

This file was deleted.

27 changes: 1 addition & 26 deletions init/init.d/rpimonitor
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@

DAEMON="/usr/bin/rpimonitord"
PIDFILE="/var/run/rpimonitord.pid"
DEFAULTFILE="/etc/default/rpimonitor"

[ -x $DAEMON ] || exit 0

[ -r $DEFAULTFILE ] && . $DEFAULTFILE

checkroot(){
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root"
Expand All @@ -29,12 +26,6 @@ checkroot(){
}

start() {
if [ "$DAEMON_START" = "0" ]; then
echo "RPi-Monitor deamon id disabled."
echo "Update /etc/default/rpimonitor and set DEAMON_START to 1."
return 0
fi

touch $PIDFILE

for pid in $(cat $PIDFILE); do
Expand Down Expand Up @@ -80,19 +71,6 @@ status(){
echo
}

update(){
if [ "$SHOW_PACKAGE_UPDATE" = "0" ]; then
echo > /var/lib/rpimonitor/updatestatus.txt
return 0
fi

log_daemon_msg "RPi-Monitor" "Updating package status"
LANG=C
apt-get upgrade --dry-run| perl -ne '/(.*upgraded.*installed|^ \S+.*)/ and print "$1 "' 2>/dev/null > /var/lib/rpimonitor/updatestatus.txt
status=$?
log_end_msg $status
}

checkroot
case "$1" in
start)
Expand All @@ -107,11 +85,8 @@ case "$1" in
restart)
restart
;;
update)
update
;;
*)
echo "Usage: $0 {start|stop|restart|status|update}"
echo "Usage: $0 {start|stop|restart|status}"
;;
esac

Expand Down
22 changes: 11 additions & 11 deletions rpimonitor/daemon.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,53 +5,53 @@
# if embedded server should be started and its configuration.
#
########################################################################

#
# daemon.sharedmemkey=20130906
# Define the share memory key
#daemon.sharedmemkey=20130906

#
# daemon.delay=10
# Define the delay between 2 kpi pooling (default:10)
# Note: If you want to change the default delay, the rrd file will
# have to be deleted rpimonitord will recreate them at next startup
#daemon.delay=10

#
# daemon.timeout=10
# Define the maximul duration of KPI extraction (default:5)
#daemon.timeout=10

#
# daemon.noserver=1
# Define that rpimonitor shouldn't start web server (default:0)
# Note: A symbolic link from /var/lib/rpimonitor/stat to
# /usr/share/rpimonitor/stat may be required
#daemon.noserver=1

#
# daemon.addr=0.0.0.0
# Define the address used by the web server (default:0.0.0.0)
#daemon.addr=0.0.0.0

#
# daemon.port=8888
# Define port of the web server (default:8888)
#daemon.port=8889

#
# daemon.user=pi
# Define user used to run the server process (default:pi)
# Note: If user is not existing, process will run with uid=1000
#daemon.user=pi

#
# daemon.group=pi
# Define group used to run the server process (default:pi)
# Note: If group is not existing, process will run with gid=1000
#daemon.group=pi

#
# daemon.webroot=/usr/share/rpimonitor/web
# Define the root directory of the web server (Default:/usr/share/rpimonitor/web)
#daemon.webroot=/usr/share/rpimonitor/web

#
# daemon.datastore=/var/lib/rpimonitor
# Define the data storage directory (Default:/var/lib/rpimonitor)
#daemon.datastore=/var/lib/rpimonitor

#
# daemon.shellinabox=https://0.0.0.0:4200/
# Define shellinabox address (Default: calculated automatically based on http request)
#daemon.shellinabox=https://127.0.0.1:4200/
78 changes: 61 additions & 17 deletions rpimonitor/rpimonitord
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ sub new
$this->Debug(3,"");
$this->{'rrd'}=();
$this->{'daemon'}->{'confFiles'} = [];
$this->{'counter'}->{'static'} = 0;
$this->{'counter'}->{'dynamic'} = 0;
$this->{'counter'}->{'status'} = 0;
$this->{'counter'}->{'statistics'} = 0;
return $this;
}

Expand Down Expand Up @@ -83,7 +87,7 @@ sub Load
$this->{'daemon'}->{'delay'} ||= 10;
$this->{'daemon'}->{'timeout'} ||= 5;
$this->{'daemon'}->{'sharedmemkey'}||= 20130906;

# Check user and group
$this->{'daemon'}->{'gid'} = getgrnam($this->{'daemon'}->{'user'}) || 1000;
$this->{'daemon'}->{'uid'} = getpwnam($this->{'daemon'}->{'group'}) || 1000;
Expand Down Expand Up @@ -112,6 +116,11 @@ sub Load

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

# manage page common parameters
$this->{'web'}->{'page'}->{'icon'} ||= 'img/logo.png';
$this->{'web'}->{'page'}->{'menutitle'} ||= 'RPi-Monitor';
$this->{'web'}->{'page'}->{'pagetitle'} ||= 'RPi-Monitor';

# manage menu
foreach (@{$this->{'web'}->{'status'}}) {
$_->{'name'} and push(@{$this->{'menu'}->{'status'}}, $_->{'name'});
Expand All @@ -127,6 +136,7 @@ sub Load
) or die $!;

if ( $this->{'show'} ) {
$Data::Dumper::Indent = 1;
die Data::Dumper->Dump([$this]);
}
}
Expand All @@ -135,43 +145,69 @@ sub LoadFile
{
my $this = shift;
my $confFile = shift;
my $dict;
$this->Debug(2,"Loading file: $confFile");

open ( FILE, $confFile)
or die "Error while openning configuration file \"$confFile\" because $!\n";
while (<FILE>){
chomp;
/^\s*#|^$/ and next; # Ignore comments
/^include=(.*)/ and -f $1 and push($this->{'daemon'}->{'confFiles'}, $1) and next;
my ($key, $value) = /^([^=]*)=(.*)/; # Extract key and value
my @leaves=split('\.', $key); # Explode key and construct config hash
my $tree=$this;
my $previous;
my $current;
my $next;
while (scalar(@leaves) > 0) {
$current ||= shift (@leaves);
$next = shift (@leaves);
if ( $next =~ /^\d+$/ ) {
if ($current =~ /^\d+$/) {
@{$tree}[$current-1] ||= [];
$tree=@{$tree}[$current-1];
my $root;
while (scalar(@leaves) > 0) { # While @leaves contains data
$current ||= shift (@leaves); # If root is empty, shift the first element of @leaves to $current
$root ||= $current;
if ( $root eq 'web' ) { $root = $current }
$next = shift (@leaves); # Shift the first element of @leaves in $next
if ( $next =~ /^\d+$/ ) { # If $next is an integer -> we are in an array
if ($current =~ /^\d+$/) { # If $current is an integer -> we are in an array
@{$tree}[$current-1] ||= []; # If the branch is not an array, create an empty array
$tree=@{$tree}[$current-1]; # Define this array as $tree root
}
else {
$tree->{$current} ||= [];
$tree=$tree->{$current};
$tree->{$current} ||= []; # If the branch is not an array, create an empty array
$tree=$tree->{$current}; # Define this array as $tree root
}
} else {
if ($current =~ /^\d+$/) {
@{$tree}[$current-1] ||= {};
$tree=@{$tree}[$current-1];
} else { # If $next is not an integer -> We are in a hash
if ($current =~ /^\d+$/) { # If $current is an integer -> we are in an array
my $index = $current;

# Manage per file indexes unicity
if ( ($root eq "static") ||
($root eq "dynamic") ||
( ( ($root eq 'status' ) ||
($root eq 'statistics' ) ) &&
($previous eq "content") ) )
{
# If $index is not in $dict, add it with counter++
if ( ! $dict->{$root}[$current] )
{
$dict->{$root}[$current] = ++$this->{'counter'}->{$root};
}
$index = $dict->{$root}[$current];
}

@{$tree}[$index-1] ||= {}; # If the branch is not an array, create an empty hash
$tree=@{$tree}[$index-1]; # Define this hash as $tree root
}
else {
$tree->{$current} ||= {};
$tree=$tree->{$current};
else { # We are in a hash
$tree->{$current} ||= {}; # If the branch is not an array, create an empty hash
$tree=$tree->{$current}; # Define this hash as $tree root
}
}
if ( ($next eq 'rrd') and $value) { push(@{$this->{'rrd'}},$tree) };
$previous = $current;
$current = $next;
}

# Add value
if ($current =~ /^\d+$/) {
@{$tree}[$current-1] = $value;
}
Expand Down Expand Up @@ -242,6 +278,7 @@ sub new
"/statistics.json",
"/menu.json",
"/friends.json",
"/page.json",
"/version.json",
"/favicon.ico",

Expand Down Expand Up @@ -439,6 +476,7 @@ sub Run
$this->{'status'} = encode_json(\@{$configuration->{'web'}->{'status'}});
$this->{'statistics'} = encode_json(\@{$configuration->{'web'}->{'statistics'}});
$this->{'friends'} = encode_json(\@{$configuration->{'web'}->{'friends'}});
$this->{'page'} = encode_json(\%{$configuration->{'web'}->{'page'}});
$this->{'static'} = encode_json(\%{$monitor->{'static'}});
$this->{'menu'} = encode_json(\%{$configuration->{'menu'}});
$this->{'version'} = "{\"version\":\"$configuration->{'version'}\"}";
Expand Down Expand Up @@ -519,6 +557,10 @@ sub Run
or warn $!;
print FILE encode_json \@{$configuration->{'web'}->{'status'}} ;
close(FILE);
open(FILE, "> $configuration->{'daemon'}->{'webroot'}/page.json")
or warn $!;
print FILE encode_json \%{$configuration->{'web'}->{'page'}} ;
close(FILE);
open(FILE, "> $configuration->{'daemon'}->{'webroot'}/statistics.json")
or warn $!;
print FILE encode_json \@{$configuration->{'web'}->{'statistics'}} ;
Expand Down Expand Up @@ -935,6 +977,7 @@ sub Run
package main;
use strict;
use POSIX;
use Sys::Hostname;
sub help
{
Expand Down Expand Up @@ -1077,6 +1120,7 @@ $pidfile and &daemonize;
my $monitor = Monitor->new();
# Process data that should be extracted once, before the server starts
$monitor->Process($configuration,'static');
$monitor->{'static'}->{'hostname'} = hostname();

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

Expand Down
Loading

0 comments on commit a037249

Please sign in to comment.