Révision 665430de
Initial version
| plugins/other/multiping | ||
|---|---|---|
| 1 |
#!/usr/bin/perl -w |
|
| 2 |
# |
|
| 3 |
# Copyright (C) 2008 Thomas Gutzler (thomas.gutzler@gmail.com) |
|
| 4 |
# original shell script by Jimmy Olsen |
|
| 5 |
# |
|
| 6 |
# This program is free software; you can redistribute it and/or |
|
| 7 |
# modify it under the terms of the GNU General Public License |
|
| 8 |
# as published by the Free Software Foundation; version 2 dated June, |
|
| 9 |
# 1991. |
|
| 10 |
# |
|
| 11 |
# This program is distributed in the hope that it will be useful, |
|
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 |
# GNU General Public License for more details. |
|
| 15 |
# |
|
| 16 |
# You should have received a copy of the GNU General Public License |
|
| 17 |
# along with this program; if not, write to the Free Software |
|
| 18 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 19 |
# |
|
| 20 |
# |
|
| 21 |
# Plugin to monitor ping times |
|
| 22 |
# |
|
| 23 |
# Parameters: |
|
| 24 |
# |
|
| 25 |
# ping_args - Arguments to ping (default "-c 2 -w 1") |
|
| 26 |
# ping_args2 - Arguments after the host name (required for Solaris) |
|
| 27 |
# ping - Ping program to use |
|
| 28 |
# host - Host to ping |
|
| 29 |
# |
|
| 30 |
# Arguments for Solaris: |
|
| 31 |
# ping_args -s |
|
| 32 |
# ping_args2 56 2 |
|
| 33 |
# |
|
| 34 |
# Tips for very fast ping replies |
|
| 35 |
# (thanks to Alex Davies and Nicolai Langfeldt): |
|
| 36 |
# Apparently, old versions of munin can't handle scientific notation of values |
|
| 37 |
# so, if you're getting replies like this from your node: |
|
| 38 |
# site1.value 5.2e-05 |
|
| 39 |
# and your graph looks like a flat line, remove the -o argument from graph_args |
|
| 40 |
# |
|
| 41 |
# Configuration example |
|
| 42 |
# [multiping] |
|
| 43 |
# env.hosts www.google.com,www.yahoo.com |
|
| 44 |
# env.names Google, Yahoo |
|
| 45 |
# env.ping_args -A -c 5 -w 2 |
|
| 46 |
# |
|
| 47 |
#%# family=auto |
|
| 48 |
#%# capabilities=autoconf |
|
| 49 |
|
|
| 50 |
use strict; |
|
| 51 |
|
|
| 52 |
my @hosts = exists $ENV{hosts} ? split(/,/, $ENV{hosts}) : 'www.google.com.au';
|
|
| 53 |
my @names = exists $ENV{names} ? split(/,/, $ENV{names}) : 'Google Australia';
|
|
| 54 |
my $ping_cmd = exists $ENV{ping} ? $ENV{ping} : 'ping';
|
|
| 55 |
my $ping_args = exists $ENV{ping_args} ? $ENV{ping_args} : '-c 2 -w 1';
|
|
| 56 |
my $ping_args2 = exists $ENV{ping_args2} ? $ENV{ping_args2} : '';
|
|
| 57 |
|
|
| 58 |
if ($#hosts != $#names) {
|
|
| 59 |
print "unequal amount of hosts and names\n"; |
|
| 60 |
exit 1; |
|
| 61 |
} |
|
| 62 |
|
|
| 63 |
if ((exists $ARGV[0]) && ($ARGV[0] eq "autoconf")) {
|
|
| 64 |
my @ping = `$ping_cmd $ping_args $hosts[0] $ping_args2`; |
|
| 65 |
chomp @ping; |
|
| 66 |
my $ping = join(" ", @ping);
|
|
| 67 |
if ($ping =~ m@min/avg/max@) {
|
|
| 68 |
print "yes\n"; |
|
| 69 |
exit 0; |
|
| 70 |
} else {
|
|
| 71 |
print "no\n"; |
|
| 72 |
exit 1; |
|
| 73 |
} |
|
| 74 |
} |
|
| 75 |
|
|
| 76 |
if ((exists $ARGV[0]) && ($ARGV[0] eq "config")) {
|
|
| 77 |
print "graph_title Ping times\n"; |
|
| 78 |
print "graph_args --base 1000 -o\n"; |
|
| 79 |
print "graph_vlabel seconds\n"; |
|
| 80 |
print "graph_category network\n"; |
|
| 81 |
print "graph_info This graph shows ping RTT statistics.\n"; |
|
| 82 |
for (my $site=1; $site<=$#hosts+1; $site++) {
|
|
| 83 |
print "site$site.label $names[$site-1]\n"; |
|
| 84 |
print "site$site.info Ping RTT statistics for $hosts[$site-1].\n"; |
|
| 85 |
print "site$site.draw LINE2\n"; |
|
| 86 |
print "site${site}_packetloss.label $names[$site-1] packet loss\n";
|
|
| 87 |
print "site${site}_packetloss.graph no\n";
|
|
| 88 |
} |
|
| 89 |
exit 0; |
|
| 90 |
} |
|
| 91 |
|
|
| 92 |
for (my $site=1; $site<=$#hosts+1; $site++) {
|
|
| 93 |
my $host = $hosts[$site-1]; |
|
| 94 |
my @ping = `$ping_cmd $ping_args $host $ping_args2`; |
|
| 95 |
chomp @ping; |
|
| 96 |
my $ping = join(" ", @ping);
|
|
| 97 |
print "site".$site.".value ".($1 / 1000)."\n" if ($ping =~ m@min/avg/max.*\s\d+(?:\.\d+)?/(\d+(?:\.\d+)?)/\d+(?:\.\d+)?@); |
|
| 98 |
print "site".$site."_packetloss.value $1\n" if ($ping =~ /(\d+)% packet loss/); |
|
| 99 |
} |
|
| 100 |
|
|
Formats disponibles : Unified diff