Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / network / multiping @ 093708d7

Historique | Voir | Annoter | Télécharger (3,37 ko)

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
# 	hosts          - List of comma-separated hosts to ping (IP address or FQDN)
29
# 	names          - Friendly display name of each host given in the "hosts" parameter (comma-separated list)
30
#
31
# Arguments for Solaris:
32
#      ping_args      -s
33
#      ping_args2     56 2
34
#
35
# Tips for very fast ping replies
36
#   (thanks to Alex Davies and Nicolai Langfeldt):
37
# Apparently, old versions of munin can't handle scientific notation of values
38
# so, if you're getting replies like this from your node:
39
# site1.value 5.2e-05
40
# and your graph looks like a flat line, remove the -o argument from graph_args
41
#
42
# Configuration example
43
# [multiping]
44
# env.hosts www.google.com,www.yahoo.com
45
# env.names Google,Yahoo
46
# env.ping_args -A -c 5 -w 2
47
#
48
#%# family=auto
49
#%# capabilities=autoconf
50

    
51
use strict;
52

    
53
my @hosts = exists $ENV{hosts} ? split(/,/, $ENV{hosts}) : 'www.google.com.au';
54
my @names = exists $ENV{names} ? split(/,/, $ENV{names}) : 'Google Australia';
55
my $ping_cmd = exists $ENV{ping} ? $ENV{ping} : 'ping';
56
my $ping_args = exists $ENV{ping_args} ? $ENV{ping_args} : '-c 2 -w 1';
57
my $ping_args2 = exists $ENV{ping_args2} ? $ENV{ping_args2} : '';
58

    
59
if ($#hosts != $#names) {
60
	print "unequal amount of hosts and names\n";
61
	exit 1;
62
}
63

    
64
if ((exists $ARGV[0]) && ($ARGV[0] eq "autoconf")) {
65
	my @ping = `$ping_cmd $ping_args $hosts[0] $ping_args2`;
66
	chomp @ping;
67
	my $ping = join(" ", @ping);
68
	if ($ping =~ m@min/avg/max@) {
69
		print "yes\n";
70
		exit 0;
71
	} else {
72
		print "no\n";
73
		exit 1;
74
	}
75
}
76

    
77
if ((exists $ARGV[0]) && ($ARGV[0] eq "config")) {
78
	print "graph_title Ping times\n";
79
	print "graph_args --base 1000 -o\n";
80
	print "graph_vlabel seconds\n";
81
	print "graph_category network\n";
82
	print "graph_info This graph shows ping RTT statistics.\n";
83
    for (my $site=1; $site<=$#hosts+1; $site++) {
84
		print "site$site.label $names[$site-1]\n";
85
		print "site$site.info Ping RTT statistics for $hosts[$site-1].\n";
86
		print "site$site.draw LINE2\n";
87
		print "site${site}_packetloss.label $names[$site-1] packet loss\n";
88
		print "site${site}_packetloss.graph no\n";
89
	}
90
    exit 0;
91
}
92

    
93
for (my $site=1; $site<=$#hosts+1; $site++) {
94
	my $host = $hosts[$site-1];
95
	my @ping = `$ping_cmd $ping_args $host $ping_args2`;
96
	chomp @ping;
97
	my $ping = join(" ", @ping);
98
	print "site".$site.".value ".($1 / 1000)."\n" if ($ping =~ m@min/avg/max.*\s\d+(?:\.\d+)?/(\d+(?:\.\d+)?)/\d+(?:\.\d+)?@);
99
	print "site".$site."_packetloss.value $1\n" if ($ping =~ /(\d+)% packet loss/);
100
}
101