Skip to content

Commit

Permalink
Multiple extraction, postprocessing and default values. Update docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierBerger committed Mar 11, 2018
1 parent 6b1a0f5 commit 56ba6e9
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 19 deletions.
18 changes: 10 additions & 8 deletions docs/source/22_extraction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ static.<static data id>.regexp=<data regexp>
In case of KPI list, each group will be affected to a KPI name.

static.<static data id>.postprocess=<data postprocess>
``<data postprocess>`` is an expression defining the postprocessing to
be applied on result. KPI are idendified by ``$1``. In case of list,
other KPI are identified by ``$2``, ``$3``, ...
``<data postprocess>`` is an expression defining the postprocessing formula or the
list of postprocessing formula (comma separated) to be applied on result.
Each result is processed individually and is identified by ``$1``
This parameter will be evaluate by the command eval of ``perl``.

Dynamic
Expand Down Expand Up @@ -84,9 +84,10 @@ dynamic.<dynamic data id>.regexp=<data regexp>
In case of KPI list, each group will be affected to a KPI name.

dynamic.<dynamic data id>.postprocess=<data postprocess>
``<data name>``, ``<data source>``, ``<data regexp>``, ``<data postprocess>``
This 4 first parameters have the same signification as for static
parameters.
``<data postprocess>`` is an expression defining the postprocessing formula or the
list of postprocessing formula (comma separated) to be applied on result.
Each result is processed individually and is identified by ``$1``
This parameter will be evaluate by the command eval of ``perl``.

.. note:: Static values are accessible for the post processing using the
variable ``$this->{'static'}->{'static_data_name'}`` and can be used.
Expand All @@ -98,8 +99,9 @@ dynamic.<dynamic data id>.interval=<interval>
Default value is ``1``. This means that data is extracted at every loop.

dynamic.<dynamic data id>.default=<default>
If ``rpimonitord`` can't extract information, it is now possible to define
a ``<default>`` value which will be set for the KPI.
If ``rpimonitord`` can't extract information, it is possible to define
a ``<default>`` value which will be set for the KPI or defaults values of a list
of KPI separated by comma.

dynamic.<dynamic data id>.rrd=<GAUGE|COUNTER|DERIVE|ABSOLUTE|COMPUTE>
``rrd`` parameter is defining if the KPI has to be stored into a RRD
Expand Down
36 changes: 36 additions & 0 deletions src/etc/rpimonitor/template/example.postprocess_default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
########################################################################
# Extract CPU information
# Page: 1
# Information Status Statistics
# - cpu frequency - yes - no
# - cpu voltage - yes - no
# - cpu load 1, 5, 15 - yes - yes
# - cpu scaling governor - yes - no
########################################################################
dynamic.1.name=load1,load5,load15
dynamic.1.source=/proc/loadavg
dynamic.1.regexp=^(\S+)\s(\S+)\s(\S+)
dynamic.1.postprocess=

dynamic.2.name=pload1,pload5,pload15
dynamic.2.source=/proc/loadavg
dynamic.2.regexp=^(\S+)\s(\S+)\s(\S+)
dynamic.2.postprocess=$1*100,$1*100,$1*100

dynamic.3.name=default1,default2,default3
dynamic.3.default=1,2,3

dynamic.4.name=test0
dynamic.4.source=echo 0
dynamic.4.postprocess=$1+1

dynamic.5.name=test00
dynamic.5.source=echo 0
dynamic.5.default=5

web.status.1.content.1.title="CPU"
web.status.1.content.1.icon=cpu.png
web.status.1.content.1.line.1="Loads: <b>" + data.load1 + "</b> [1min] - <b>" + data.load5 + "</b> [5min] - <b>" + data.load15 + "</b> [15min]"
web.status.1.content.1.line.2="100 x Loads: <b>" + data.pload1 + "</b> [1min] - <b>" + data.pload5 + "</b> [5min] - <b>" + data.pload15 + "</b> [15min]"
web.status.1.content.1.line.3="Default: <b>" + data.default1 + "</b> - <b>" + data.default2 + "</b> - <b>" + data.default3 + "</b> "
web.status.1.content.1.line.4="Test 0: <b>" + data.test0 + "</b> - <b>" + data.test00
30 changes: 19 additions & 11 deletions src/usr/bin/rpimonitord
Original file line number Diff line number Diff line change
Expand Up @@ -762,26 +762,34 @@ sub Process
alarm $configuration->{'daemon'}->{'timeout'};

# Extract dynamic data
undef @_;
$pid = open(FEED, $file) or (@_ = split(',',$kpi->{'default'} ));
my @values;
$pid = open(FEED, $file);
while (<FEED>){
/$kpi->{'regexp'}/ and (@_ = /$kpi->{'regexp'}/) or next;
if ( $kpi->{'postprocess'} ) {
@_=eval( $kpi->{'postprocess'} );
}
/$kpi->{'regexp'}/ and (@values = /$kpi->{'regexp'}/) or next;
}
close(FEED);
alarm 0;
$pid = 0;

# Set default value is no data is present
scalar(@_) or defined($kpi->{'default'}) and @_ = split(',',$kpi->{'default'} );

# Store dynamic data
my $i=0;
my @postprocess = split(',',$kpi->{'postprocess'});
my @default = split(',',$kpi->{'default'} );
my @names = split(',',$kpi->{'name'});
foreach ( @_ ) {
$this->{$list}->{$names[$i]}=$_[$i];
foreach ( @names ) {
my $val = $values[$i];
# Post process
if ( defined($val) ) {
if ( $postprocess[$i] ) {
$val =~ /(.*)/;
$val = eval( $postprocess[$i] );
}
}
else {
# Set default value is no data is present
$val = $default[$i];
}
$this->{$list}->{$names[$i]}=$val;
$i++;
}
};
Expand Down

0 comments on commit 56ba6e9

Please sign in to comment.