Munin のプラグインは以前作成したMacOS istats 用を基に作成。
設定の手順は基本的に依然と同じだけど、設置したmumin-nodeサーバーがCentOS 7.7 なので、ディレクトリパスが異なる。
設定手順
今回プラグイン・ファイル名は’roomstat’ とする。
注:このファイル名がMunin のカテゴリー名となる
1. プラグイン・ファイルをプラグイン・ファイル・ディレクトリにコピーする
# cp roomstat /usr/share/munin/plugins
2. プラグイン・リンク・ディレクトリに下記シンボリックを上記コピーしたファイルに対して3つ作成する
roomstat_rmtp
roomstat_rmhm
roomstat_prss
(コマンド実行例)
# cd /etc/munin/plugins
# ln -s /usr/share/munin/plugins/roomstat ./roomstat_rmtp
# ln -s /usr/share/munin/plugins/roomstat ./roomstat_rmhm
# ln -s /usr/share/munin/plugins/roomstat ./roomstat_prss
3. munin-node を再起動する
# systemctl restart munin-node
動作確認
プラグイン・リンク・ディレクトに移動して、下記コマンド実行を行いエラーとならばければOK。
sh-4.2# cd /etc/munin/plugins
sh-4.2# ./roomstat_rmtp config
graph_title Room Temperature
graph_vlabel degrees Celsius
graph_args --upper-limit 60 -l 0
graph_category roomstat
rmtp.label Temperature
rmtp.warning 40
rmtp.critical 50
sh-4.2# ./roomstat_rmhm config
graph_title Room Humidity
graph_vlabel %
graph_args --upper-limit 100 --lower-limit 0
graph_category roomstat
rmhm.label Humidity
rmhm.warning 80
rmhm.critical 90
sh-4.2# ./roomstat_rmpr config
graph_title Atmospheric Pressure
graph_vlabel hPa
graph_args -l 800
graph_category roomstat
rmpr.label Pressure
rmpr.warning
rmpr.critical
sh-4.2# ./roomstat_rmtp
rmtp.value 23.41
sh-4.2# ./roomstat_rmhm
rmhm.value 35.02
sh-4.2# ./roomstat_rmpr
rmpr.value 1018.85
sh-4.2#
プラグインコード
コード内の下記のURL 情報をIoT WEB環境に合わせて変更すれば動作すると思います。
my $req = GET(‘http://192.168.1.49:8090/data’);
#!/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
=back
IoT Web returns values as following
line1: data time
2: temperature, humidity, pressure
3: temerature value
4: humidity value
5: pressure value
return values example
---
2020/02/13 15:16:24
Temperature=20.85 *C,Humidity=29.79 %,Pressure=1008.93 hPa
20.85
29.79
1008.93
---
=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.49:8090/data');
#
#
#
my $res = $ua->request($req);
my $rm_datetime;
my $rm_string;
my $rm_temp;
my $rm_humi;
my $rm_prss;
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_dummy) = split(/\n/,$res->content,6);
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 => 'Room Temperature',
vlabel => 'degrees Celsius',
label => 'Temperature',
category => $category_name,
warning => '40',
critical => '50',
graph_args => '--upper-limit 60 -l 0'
},
rmhm => {
value => $rm_humi,
title => 'Room Humidity',
vlabel => '%',
label => 'Humidity',
category => $category_name,
warning => '80',
critical => '90',
graph_args => '--upper-limit 100 --lower-limit 0'
},
rmpr => {
value => $rm_prss,
title => 'Atmospheric Pressure',
vlabel => 'hPa',
label => 'Pressure',
category => $category_name,
warning => '',
critical => '',
graph_args => '-l 800'
},
);
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 "${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 "${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;