安裝需求
ActivePerl 5.8 / 5.10
MRTG
安裝方法 CentOS
- 預設下 CentOS 5 已裝完 ActivePerl 與相關模組
安裝方法 Windows
- 安裝 ActivePerl
- 於 command mode 執行 ppm ,安裝 Net::Ping 模組
使用方法
- 建立 ping.pl
- 建立 MRTG.cfg
- 執行三次 mrtg ,直到沒有錯誤訊息發生
- 利用 indexmaker 產生 index.html
- 加入 crontab 定期更新 mrtg
程式碼
ping.pl
#!/usr/bin/perl
use strict;
use warnings;
use Net::Ping;
use Time::HiRes;
my $host = shift;
my $p = Net::Ping->new("icmp");
$p->hires();
my ($ret, $duration, $ip) = $p->ping($host, 5.5);
if ( $ret ) {
printf "%.0f\n", 1000 * $duration;
} else {
print "0\n";
}
# Value "in" for mrtg
print "0\n";
# Value "out" for mrtg
print "\n";
# A comment for mrt
print "$host\n";
$p->close();
MRTG.cfg
#
# Defaults for some ping-checks into the internet
#
MaxBytes[_]: 10000
Options[_]: gauge,growright
LegendI[_]: Ping in ms
ShortLegend[_]: ms
YLegend[_]: ms
Factor[_]: 1
# every "section" muss have a unique name
# I prefer this: [$SERVICE$_$HOST$]
Target[ping_www.amazon.de]: `perl /home/mrtg/bin/ping.pl www.amazon.de`
Title[ping_www.amazon.de]: Ping www.amazon.de
PageTop[ping_www.amazon.de]: Ping www.amazon.de
LegendO[ping_www.amazon.de]:
特別方法
可利用
CRONw 執行更新
mrtg
參考網站
http://lena.franken.de/mrtg/