第一弾からの変更点
測定値数の増加に対応
第一弾では測定値が3つ(温度、湿度、気圧)だったのが、2つ(ガス、照度)増えたのでその追加変更を行った
グラフ表示順の設定
第一弾ではカテゴリー内のグラフ表示順が希望通り(温度、湿度、気圧の順番で表示して欲しかった)で無かった。
どうもグラフ名(title)でソートされるようなので、グラフ名の最初に数字を入れて希望通りの順番に表示されるようにした。
グラフオプションの微調整
- グラフのデフォルトが1K = 1,024 だったので、気圧値等不適切だったので、明示的に1K=1,000 となるようにオプション設定するようにした
- 気圧値はより変化が見えやすくなるように範囲指定(下限設定)をあえて行わないようにオプションを変更
$ ./roomstat2 config
graph_title 5. Room Illumination
graph_vlabel lx
graph_args --base 1000
graph_category roomstat2
graph_info This graph show room illumination value.
rmlx.label illumination
rmlx.warning
rmlx.critical
graph_title 3. Atmospheric Pressure
graph_vlabel hPa
graph_args --base 1000
graph_category roomstat2
graph_info This graph show room atomospheric pressure value.
rmpr.label Pressure
rmpr.warning
rmpr.critical
graph_title 4. Room GAS level
graph_vlabel Kohms
graph_args --base 1000
graph_category roomstat2
graph_info This graph show room gas value.
rmgs.label gas level
rmgs.warning
rmgs.critical
graph_title 1. Room Temperature
graph_vlabel degrees Celsius
graph_args --base 1000 --upper-limit 60 -l 0
graph_category roomstat2
graph_info This graph show room temparature value.
rmtp.label Temperature
rmtp.warning 40
rmtp.critical 50
graph_title 2. Room Humidity
graph_vlabel %
graph_args --base 1000 --upper-limit 100 --lower-limit 0 --rigid
graph_category roomstat2
graph_info This graph show room humidity value.
rmhm.label 2. Humidity
rmhm.warning 10:90
rmhm.critical 5:95
$
ファイル名: roomstat2
このファイル名がMunin のカテゴリーになる
#!/usr/bin/perl -w
# -*- perl -*-
=head1 NAME
roomstat - Wildcard-plugin to monitor information(temperature, humiditiy, pressure) from IoT web
=head1 CONFIGURATION
The possible wildcard values are the following: 'temerareure','humidity','pressure'
So you
would create symlinks as following to this plugin called
roomstat_rmtp
roomstat_rmhm
roomstat_rmpr
roomstat_rmgs
roomstat_rmlx
=back
IoT Web returns values as following
line1: data time
2: temperature, humidity, pressure
3: temerature value
4: humidity value
5: pressure value
6: gas value
7: illumination value
return values example
---
2020/02/19 16:19:30
Room Temrerature=21.58 *C,Room Humidity=35.44 %,Atmospheric Pressure=1023.84 hPa,Gas=105 Kohms,Illumination=0.00 lx
21.58
35.44
1023.84
105952
0.00
---
=head1 AUTHOR
myos
=head1 LICENSE
GPLv2
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf suggest
=cut
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
use File::Basename;
my $ua = LWP::UserAgent->new();
#
# *** Change for each environment ***
# IP address and port number...
my $req = GET('http://192.168.1.48:8090/data');
#
#
#
my $res = $ua->request($req);
my $rm_datetime;
my $rm_string;
my $rm_temp;
my $rm_humi;
my $rm_prss;
my $rm_gas;
my $rm_lx;
my $rm_dummy;
if ($res->is_success) {
# print $res->as_string;
# print $res->content;
($rm_datetime,$rm_string,$rm_temp,$rm_humi,$rm_prss,$rm_gas,$rm_lx,$rm_dummy) = split(/\n/,$res->content,8);
sleep 2;
}
else {
# print $res->status_line . "\n";
exit 1;
}
#
my $scriptName = basename($0, '');
my ($category_name, $func) = split(/_/, $scriptName, 2); # get catetofy name and function name from linked script name
#
my %config = (
rmtp => {
value => $rm_temp,
title => '1. Room Temperature',
vlabel => 'degrees Celsius',
label => 'Temperature',
category => $category_name,
info => 'This graph show room temparature value.',
warning => '40',
critical => '50',
graph_args => '--base 1000 --upper-limit 60 -l 0'
},
rmhm => {
value => $rm_humi,
title => '2. Room Humidity',
vlabel => '%',
label => '2. Humidity',
category => $category_name,
info => 'This graph show room humidity value.',
warning => '10:90',
critical => '5:95',
graph_args => '--base 1000 --upper-limit 100 --lower-limit 0 --rigid'
},
rmpr => {
value => $rm_prss,
title => '3. Atmospheric Pressure',
vlabel => 'hPa',
label => 'Pressure',
category => $category_name,
info => 'This graph show room atomospheric pressure value.',
warning => '',
critical => '',
graph_args => '--base 1000'
},
rmgs => {
value => $rm_gas,
title => '4. Room GAS level',
vlabel => 'Kohms',
label => 'gas level',
category => $category_name,
info => 'This graph show room gas value.',
warning => '',
critical => '',
graph_args => '--base 1000'
},
rmlx => {
value => $rm_lx,
title => '5. Room Illumination',
vlabel => 'lx',
label => 'illumination',
category => $category_name,
info => 'This graph show room illumination value.',
warning => '',
critical => '',
graph_args => '--base 1000'
},
);
if (defined $ARGV[0] and $ARGV[0] eq 'config') {
# exit 2 unless defined $func;
if (defined $func) {
print "graph_title $config{$func}->{title}\n";
print "graph_vlabel $config{$func}->{vlabel}\n";
print "graph_args $config{$func}->{graph_args}\n";
print "graph_category $config{$func}->{category}\n";
print "graph_info $config{$func}->{info}\n";
print "${func}\.label $config{$func}->{label}\n";
print "${func}\.warning $config{$func}->{warning}\n";
print "${func}\.critical $config{$func}->{critical}\n";
} else {
foreach my $func (keys %config) {
# print $func, "\n" if $text =~ $config{$func}->{value};
print "graph_title $config{$func}->{title}\n";
print "graph_vlabel $config{$func}->{vlabel}\n";
print "graph_args $config{$func}->{graph_args}\n";
print "graph_category $config{$func}->{category}\n";
print "graph_info $config{$func}->{info}\n";
print "${func}\.label $config{$func}->{label}\n";
print "${func}\.warning $config{$func}->{warning}\n";
print "${func}\.critical $config{$func}->{critical}\n";
}
}
exit 0;
}
if ( defined $ARGV[0] and $ARGV[0] eq 'autoconf' ) {
# Web access check
if ($res->is_success) {
print "yes\n";
exit 0;
} else {
print "WEB access problem\n";
exit 1;
}
}
if (defined $ARGV[0] and $ARGV[0] eq 'suggest') {
foreach my $func (keys %config) {
print "${func}\n";
}
exit 0;
}
if (defined $func) {
print "${func}\.value $config{$func}->{value}\n";
} else {
foreach my $func (keys %config) {
print "${func}\.value $config{$func}->{value}\n";
}
}
exit 0;