PLANEX MZK-750DHP用 トラフィック監視スクリプト(munin)
若者のWiFi離れと携帯キャリアの20GBプランに掲載した回線トラフィックグラフを作成しているperl スクリプトです。 うちで使っているMZK-750DHPは SNMPが使えないので、Web管理画面からログインし、ステータス画面から情報を拾っています。
今時の流行りはEdgeRouter Xらしいけど、動いているものを買い換えるのもなー。

使い方
munin のプラグインとして動作します。 プログラム内の ip-adress, admin-id, admin-password を環境に合わせて修正したのちに /etc/munin/plugins に放り込んでください。
パスワード直書きが気になる方は使わない方がいいかも。
スクリプト本体
#!/usr/bin/perl -w
# -*- perl -*-
=head1 NAME
=head1 APPLICABLE SYSTEMS
=head1 CONFIGURATION
=head1 USAGE
Link this plugin to /etc/munin/plugins/ and restart the munin-node.
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf
=head1 BUGS
=head1 VERSION
$Id$
=head1 AUTHOR
@zu2
=head1 LICENSE
GPLv2
=cut
use strict;
use warnings;
use Munin::Plugin;
use utf8;
use strict;
use warnings;
use Web::Scraper;
use WWW::Mechanize;
use Data::Dumper;
use Web::Scraper;
use URI;
binmode STDOUT => ":utf8";
my $mode = ($ARGV[0] or "print");
if ($mode eq 'autoconf' ) {
if (`/usr/bin/perl $0` eq '') {
print "no (no devices to monitor)\n";
exit 1;
} else {
print "yes\n";
exit 0;
}
}
if ($mode eq 'config' ) {
# The headers
print "multigraph mzk750dhp_wan\n";
print "graph_title MZK-750DHP WAN traffic\n";
print "graph_args -l 0\n";
print "graph_vlabel Bytes\n";
# print "graph_scale no\n";
print "graph_category wan\n";
print "WANRxBytes.label Receive\n";
print "WANTxBytes.label Send\n";
exit 0;
}
my $ua = WWW::Mechanize->new;
$ua->credentials('ip-address:80', 'MZK-750DHP', 'admin-id', 'admin-password');
$ua->get("http://ip-address/adm/statistic.asp");
#print $ua->content;
my $scraper = scraper {
process '//td[@id="statisticWANRxBytes"]/../td[2]','Rx'=>'TEXT';
process '//td[@id="statisticWANTxBytes"]/../td[2]','Tx'=>'TEXT';
};
my $result = $scraper->scrape($ua->content);
print "multigraph mzk750dhp_wan\n";
print "WANRxBytes.value ",$result->{Rx},"\n";
print "WANTxBytes.value ",$result->{Tx},"\n";
exit 0;
困ってること
ルーターの負荷が高い場合、データを取りこぼすことがある。気になる人はリトライするなりなんなり書き換えてください。
月初に0リセットしたいんだけど、どうするのがいいのかな。ルーター本体リセットはまずいので、どっかに月初のデータを持って引き算?







ディスカッション
コメント一覧
まだ、コメントがありません