mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-21 10:39:53 +00:00
Plugin-Gallery: Better 2nd level headings
This commit is contained in:
parent
e10e386b02
commit
d216113740
24 changed files with 5 additions and 5 deletions
51
plugins/ping/fping_
Executable file
51
plugins/ping/fping_
Executable file
|
@ -0,0 +1,51 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Description : Plugin to monitor a server/network availability.
|
||||
# Author : Thomas VIAL
|
||||
# Author URL : http://tvi.al
|
||||
# Usage : ln -s /path/to/fping_ /etc/munin/plugins/fping_www.google.com
|
||||
# Explanation : Will graph connection to www.google.com
|
||||
# Requirements :
|
||||
# * fping
|
||||
#
|
||||
|
||||
target=`basename $0 | sed 's/^fping_//g'`
|
||||
item=`echo $target | sed -e 's/\.//g'`
|
||||
|
||||
#
|
||||
# Config
|
||||
#
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
echo "graph_title ${target} availability"
|
||||
echo "graph_args --base 1000 -r -l 0 -u 100"
|
||||
echo "graph_vlabel Availability in %"
|
||||
echo "graph_category network"
|
||||
echo "graph_info Displays Network Availability"
|
||||
# Failure
|
||||
echo "failure.label Unreachable"
|
||||
echo "failure.draw AREA"
|
||||
echo "failure.colour ff0000"
|
||||
# Success
|
||||
echo "success.label Reachable"
|
||||
echo "success.draw STACK"
|
||||
echo "success.colour 00CC00CC"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#
|
||||
# Let's go!
|
||||
#
|
||||
|
||||
fping -q $target
|
||||
status=$?
|
||||
|
||||
if [ $status -eq 0 ]; then
|
||||
# Success
|
||||
echo "success.value 100"
|
||||
echo "failure.value 0"
|
||||
else
|
||||
# Failure
|
||||
echo "success.value 0"
|
||||
echo "failure.value 100"
|
||||
fi
|
167
plugins/ping/multi_tcp_ping
Executable file
167
plugins/ping/multi_tcp_ping
Executable file
|
@ -0,0 +1,167 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
=head1 NAME
|
||||
|
||||
multi_tcp_ping - Graphs together the TCP ping results for several hosts
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
This plugin is meant to be called from Munin. You should set the
|
||||
'hosts' environment variable from Munin's configuration (i.e.
|
||||
/etc/munin/munin.conf) to specify which hosts and ports to query.
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This plugin expects to receive the following environment variables:
|
||||
|
||||
=over 4
|
||||
|
||||
=item hosts (REQUIRED!)
|
||||
|
||||
Comma-separated list of hosts to query. You can specify the TCP port
|
||||
to connect to on each of the hosts by listing them as host:port - The
|
||||
port defaults to 80. The following is a valid hosts declaration:
|
||||
|
||||
hosts='192.168.0.15, 192.168.0.18:22'
|
||||
|
||||
It will query host 192.168.0.15 on the default port (80), as well as
|
||||
host 192.168.0.18 on port 22.
|
||||
|
||||
=back
|
||||
|
||||
If the connection was opened successfully, it gives as the return
|
||||
value the time it took to establish the connection. If the requested
|
||||
host is not reachable, a hard-wired '-0.01' will be returned. Why
|
||||
-0.01? Because giving a negative value is the best way to easily get
|
||||
-visually- that something failed. Connection establishment times are
|
||||
usually in the 5-500ms range. 100ms will be not too little (and thus
|
||||
invisible), not too much (and thus killing the details in our graphs).
|
||||
|
||||
=head1 DEPENDS ON
|
||||
|
||||
L<Net::Ping>
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
L<munin>, L<munin-node>
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Gunnar Wolf <gwolf@gwolf.org>
|
||||
|
||||
=head1 COPYRIGHT
|
||||
|
||||
|
||||
Copyright 2008 Gunnar Wolf, Instituto de Investigaciones
|
||||
Economicas, UNAM. This plugin is Free Software; you can
|
||||
redistribute it and/or modify it under the terms of the GNU General
|
||||
Public License as published by the Free Software Foundation; version 2
|
||||
dated June, 1991, or any later version (at your choice).
|
||||
|
||||
This program is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
|
||||
USA.
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
# This evil "eval" is to make Travis CI able to test the plugin syntax
|
||||
# without having a perl built with threads.
|
||||
#
|
||||
# Also: The use of interpreter-based threads in perl is officially
|
||||
# discouraged.
|
||||
eval 'use threads; 1;' or die 'Could not use threads';
|
||||
|
||||
use Net::Ping;
|
||||
my (%defaults, @hosts, $cmd_arg);
|
||||
|
||||
%defaults = (port => 80, timeout => 2, unreachable => -0.01);
|
||||
@hosts = get_hosts($ENV{hosts});
|
||||
die "Hosts not set - cannot continue\n" unless @hosts;
|
||||
|
||||
$cmd_arg = $ARGV[0] || '';
|
||||
config() if($cmd_arg eq "config");
|
||||
autoconf() if ($cmd_arg eq 'autoconf');
|
||||
|
||||
for my $host (@hosts) {
|
||||
threads->new(\&ping_host, $host)
|
||||
}
|
||||
|
||||
map {$_->join} threads->list;
|
||||
exit 0;
|
||||
|
||||
sub ping_host {
|
||||
my ($host, $addr, $p, $ret, $time, $ip);
|
||||
$host = shift;
|
||||
$addr = host_label_for($host);
|
||||
|
||||
$p=Net::Ping->new("tcp", $defaults{timeout});
|
||||
$p->hires();
|
||||
$p->{port_num} = $host->[1] || $defaults{port};
|
||||
|
||||
($ret, $time, $ip) = $p->ping($host->[0]);
|
||||
|
||||
$time = $defaults{unreachable} if !$ret;
|
||||
print "${addr}.value $time\n";
|
||||
}
|
||||
|
||||
sub get_hosts {
|
||||
# Hosts are defined in the 'hosts' environment variable. It's a list of
|
||||
# hosts (and optionally ports) - We parse the list and arrange it neatly
|
||||
# to be easily consumed.
|
||||
my ($hostsdef, @hosts);
|
||||
$hostsdef = shift;
|
||||
return unless $hostsdef;
|
||||
|
||||
for my $host (split(/,/, $hostsdef)) {
|
||||
$host =~ s/\s//g;
|
||||
|
||||
$host =~ /^(?:([^:]+))
|
||||
(?::(\d+))?$/x;
|
||||
|
||||
push @hosts, [$1, $2 || $defaults{port}];
|
||||
|
||||
}
|
||||
|
||||
return @hosts;
|
||||
}
|
||||
|
||||
sub config {
|
||||
my @res = ("graph_title TCP connection times",
|
||||
"graph_args --base 1000 -l 0",
|
||||
"graph_vlabel seconds",
|
||||
"graph_category network",
|
||||
"graph_info Shows the time to establish a TCP connection");
|
||||
for my $host (@hosts) {
|
||||
my $addr = host_label_for($host);
|
||||
push @res, "$addr.label $addr";
|
||||
push @res, "$addr.draw LINE2";
|
||||
push @res, "$addr.info Time to establish TCP connection to " .
|
||||
"$host->[0]:$host->[1]";
|
||||
|
||||
}
|
||||
|
||||
print map {"$_\n"} @res;
|
||||
exit 0;
|
||||
}
|
||||
|
||||
sub autoconf {
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
}
|
||||
|
||||
sub host_label_for {
|
||||
my ($ip, $port) = @{$_[0]};
|
||||
# Periods and colonsare not allowed in variable names
|
||||
my $addr = "src_${ip}_${port}";
|
||||
$addr =~ s/\./_/g;
|
||||
return $addr;
|
||||
}
|
106
plugins/ping/multiping
Executable file
106
plugins/ping/multiping
Executable file
|
@ -0,0 +1,106 @@
|
|||
#!/usr/bin/perl -w
|
||||
#
|
||||
# Copyright (C) 2008 Thomas Gutzler (thomas.gutzler@gmail.com)
|
||||
# original shell script by Jimmy Olsen
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; version 2 dated June,
|
||||
# 1991.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
# Plugin to monitor ping times
|
||||
#
|
||||
# Parameters:
|
||||
#
|
||||
# ping_args - Arguments to ping (default "-c 2 -w 1")
|
||||
# ping_args2 - Arguments after the host name (required for Solaris)
|
||||
# ping - Ping program to use
|
||||
# hosts - List of comma-separated hosts to ping (IP address or FQDN)
|
||||
# names - Friendly display name of each host given in the "hosts" parameter (comma-separated list).
|
||||
# If not set, "hosts" elements will be used
|
||||
#
|
||||
# Arguments for Solaris:
|
||||
# ping_args -s
|
||||
# ping_args2 56 2
|
||||
#
|
||||
# Tips for very fast ping replies
|
||||
# (thanks to Alex Davies and Nicolai Langfeldt):
|
||||
# Apparently, old versions of munin can't handle scientific notation of values
|
||||
# so, if you're getting replies like this from your node:
|
||||
# site1.value 5.2e-05
|
||||
# and your graph looks like a flat line, remove the -o argument from graph_args
|
||||
#
|
||||
# Configuration example
|
||||
# [multiping]
|
||||
# env.hosts www.google.com,www.yahoo.com
|
||||
# env.names Google,Yahoo
|
||||
# env.ping_args -A -c 5 -w 2
|
||||
#
|
||||
#%# family=auto
|
||||
#%# capabilities=autoconf
|
||||
|
||||
use strict;
|
||||
|
||||
my @hosts = exists $ENV{hosts} ? split(/,/, $ENV{hosts}) : 'www.google.com.au';
|
||||
my @names = exists $ENV{names} ? split(/,/, $ENV{names}) : @hosts;
|
||||
my $ping_cmd = exists $ENV{ping} ? $ENV{ping} : 'ping';
|
||||
my $ping_args = exists $ENV{ping_args} ? $ENV{ping_args} : '-c 2 -w 1';
|
||||
my $ping_args2 = exists $ENV{ping_args2} ? $ENV{ping_args2} : '';
|
||||
|
||||
if ($#hosts != $#names) {
|
||||
print "unequal amount of hosts and names\n";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
if ((exists $ARGV[0]) && ($ARGV[0] eq "autoconf")) {
|
||||
my @ping = `$ping_cmd $ping_args $hosts[0] $ping_args2`;
|
||||
chomp @ping;
|
||||
my $ping = join(" ", @ping);
|
||||
if ($ping =~ m@min/avg/max@) {
|
||||
print "yes\n";
|
||||
exit 0;
|
||||
} else {
|
||||
print "no\n";
|
||||
exit 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((exists $ARGV[0]) && ($ARGV[0] eq "config")) {
|
||||
print "graph_title Ping times\n";
|
||||
print "graph_args --base 1000 -o\n";
|
||||
print "graph_vlabel seconds\n";
|
||||
print "graph_category network\n";
|
||||
print "graph_info This graph shows ping RTT statistics.\n";
|
||||
for (my $site=1; $site<=$#hosts+1; $site++) {
|
||||
my $item = lc($hosts[$site-1]);
|
||||
$item =~ s/\.//g;
|
||||
print "$item.label $names[$site-1]\n";
|
||||
print "$item.info Ping RTT statistics for $hosts[$site-1].\n";
|
||||
print "$item.draw LINE2\n";
|
||||
print "${item}_packetloss.label $names[$site-1] packet loss\n";
|
||||
print "${item}_packetloss.graph no\n";
|
||||
}
|
||||
exit 0;
|
||||
}
|
||||
|
||||
for (my $site=1; $site<=$#hosts+1; $site++) {
|
||||
my $item = lc($hosts[$site-1]);
|
||||
$item =~ s/\.//g;
|
||||
my $host = $hosts[$site-1];
|
||||
my @ping = `$ping_cmd $ping_args $host $ping_args2`;
|
||||
chomp @ping;
|
||||
my $ping = join(" ", @ping);
|
||||
print $item.".value ".($1 / 1000)."\n" if ($ping =~ m@min/avg/max.*\s\d+(?:\.\d+)?/(\d+(?:\.\d+)?)/\d+(?:\.\d+)?@);
|
||||
print $item."_packetloss.value $1\n" if ($ping =~ /(\d+)% packet loss/);
|
||||
}
|
||||
|
201
plugins/ping/ping
Executable file
201
plugins/ping/ping
Executable file
|
@ -0,0 +1,201 @@
|
|||
#!/usr/bin/perl -w
|
||||
|
||||
=cut
|
||||
|
||||
=head1 NAME
|
||||
|
||||
ping - Plugin to monitor ping times
|
||||
|
||||
=head1 CONFIGURATION
|
||||
|
||||
ping_args - Arguments to ping (default "-c 2 -w 1")
|
||||
ping_args2 - Arguments after the host name (required for Solaris)
|
||||
ping - Ping program to use
|
||||
ping6 - Ping program to use with IPv6
|
||||
hosts - List of comma-separated hosts to ping (IPv4/6 address or FQDN)
|
||||
You can prepend host name with:
|
||||
'A:' - to resolve all IPv4 addresses
|
||||
and create an entry per address (requires 'host' program)
|
||||
'AAAA:' - the same for IPv6 (requires 'host' program)
|
||||
'6:' - do not try to resolve, but use ping6 for this host
|
||||
names - Friendly display name of each host given in the "hosts" parameter (comma-separated list).
|
||||
If not set, "hosts" elements will be used
|
||||
fork - If set to non-zero, fork each ping into parallel process to ping asynchronously
|
||||
|
||||
Configuration example
|
||||
|
||||
[ping*]
|
||||
env.hosts mail.example.org,6:www.example.org,AAAA:search.example.org
|
||||
env.names Mail,Web,Search
|
||||
env.fork yes
|
||||
|
||||
Configuration example for Solaris
|
||||
|
||||
[ping*]
|
||||
env.host www.example.org mail.example.org
|
||||
env.ping_args -s
|
||||
env.ping_args2 56 2
|
||||
|
||||
You can also append '_packetloss' to the plugin filename for packet loss statistics.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
Original Perl script Copyright (C) 2008 Thomas Gutzler (thomas.gutzler@gmail.com)
|
||||
Original Shell script Copyright (C) 2004 Jimmy Olsen
|
||||
|
||||
=head1 LICENSE
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 dated June,
|
||||
1991.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
=head1 MAGIC MARKERS
|
||||
|
||||
#%# family=manual
|
||||
|
||||
=cut
|
||||
|
||||
use strict;
|
||||
use Munin::Plugin;
|
||||
|
||||
my $ping = exists $ENV{ping} ? $ENV{ping} : "ping";
|
||||
my $ping6 = exists $ENV{ping6} ? $ENV{ping6} : "ping6";
|
||||
# Since ping sends a packet every second (-i 1) by default,
|
||||
# we may need 2 total seconds (-w 2) for <1000msec replies
|
||||
my $ping_args = exists $ENV{ping_args} ? $ENV{ping_args} : "-c 2 -w 2";
|
||||
my $ping_args2 = exists $ENV{ping_args2} ? $ENV{ping_args2} : "";
|
||||
my $fork = exists $ENV{fork} ? $ENV{fork} : 0;
|
||||
my $packetloss_mode = ($0 =~ /_packetloss$/);
|
||||
|
||||
my @host_options = exists $ENV{hosts} ? split(/,/, $ENV{hosts}) : "A:www.google.com";
|
||||
|
||||
# bare addresses
|
||||
my @host_addrs = @host_options;
|
||||
|
||||
# ping program to use
|
||||
my @host_ping = ($ping) x @host_options;
|
||||
|
||||
# resolve record type, if specified
|
||||
my @host_resolv = (0) x @host_options;
|
||||
|
||||
my $config_mode = ($ARGV[0] and $ARGV[0] eq 'config');
|
||||
if ($config_mode) {
|
||||
print "graph_title " . ($packetloss_mode ? "Ping packet loss" : "Ping times") . "\n";
|
||||
print "graph_args --base 1000 -l 0\n";
|
||||
print "graph_vlabel " . ($packetloss_mode ? "%" : "seconds") . "\n";
|
||||
print "graph_category network\n";
|
||||
print "graph_info This graph shows ping " . ($packetloss_mode ? "packet loss" : "RTT") . " statistics.\n";
|
||||
}
|
||||
|
||||
for (my $host_option = 0; $host_option < @host_options; ++$host_option) {
|
||||
my $h_addr = $host_options[$host_option];
|
||||
my @config = split(/:/, $h_addr, 2);
|
||||
if ($#config) {
|
||||
my $h_ping = $ping;
|
||||
my $h_resolv = 0;
|
||||
if ($config[0] eq "6") {
|
||||
# user wants this host to be pinged via IPv6
|
||||
$h_ping = $ping6;
|
||||
$h_addr = $config[1];
|
||||
} elsif ($config[0] eq "A") {
|
||||
# user wants this host to be resolved via IPv4
|
||||
$h_resolv = "A";
|
||||
$h_addr = $config[1];
|
||||
} elsif ($config[0] eq "AAAA") {
|
||||
# user wants this host to be resolved as IPv6
|
||||
$h_resolv = "AAAA";
|
||||
$h_addr = $config[1];
|
||||
$h_ping = $ping6;
|
||||
} elsif ($config[0] =~ /^[[:xdigit:]]+$/) {
|
||||
# this is IPv6 addr
|
||||
$h_ping = $ping6;
|
||||
} else {
|
||||
# let 'host' decide what resolve type do we need
|
||||
$h_resolv = $config[0];
|
||||
$h_addr = $config[1];
|
||||
}
|
||||
$host_addrs[$host_option] = $h_addr;
|
||||
$host_resolv[$host_option] = $h_resolv;
|
||||
$host_ping[$host_option] = $h_ping;
|
||||
}
|
||||
}
|
||||
|
||||
# display names
|
||||
my @host_names = exists $ENV{names} ? split(/,/, $ENV{names}) : @host_addrs;
|
||||
|
||||
if (@host_names != @host_addrs) {
|
||||
print "Warning: host names specified does not match addresses\n";
|
||||
}
|
||||
|
||||
# forked children
|
||||
my @children = ();
|
||||
|
||||
for (my $host_i = 0; $host_i < @host_addrs; ++$host_i) {
|
||||
my @h_addrs = ($host_addrs[$host_i]);
|
||||
my $h_ping = $host_ping[$host_i];
|
||||
my $h_resolv = $host_resolv[$host_i];
|
||||
my $h_name = ($host_names[$host_i] or $h_addrs[0]);
|
||||
|
||||
if ($h_resolv) {
|
||||
# we have to resolve the host to (probably multiple) addresses
|
||||
my $h_base_addr = pop @h_addrs;
|
||||
my @host = `host -t $h_resolv $h_base_addr`;
|
||||
chomp @host;
|
||||
for (my $h_host_i = 0; $h_host_i < @host; ++$h_host_i) {
|
||||
my $h_host = $host[$h_host_i];
|
||||
my ($h_addr) = $h_host =~ /address (.*)$/;
|
||||
if ($h_addr) {
|
||||
push @h_addrs, $h_addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (my $h_addr_i = 0; $h_addr_i < @h_addrs; ++$h_addr_i) {
|
||||
my $h_addr = $h_addrs[$h_addr_i];
|
||||
my $h_cur_name = $h_resolv ? $h_name . " ($h_addr)" : $h_name;
|
||||
my $h_norm_name = clean_fieldname($h_cur_name);
|
||||
if ($config_mode) {
|
||||
print "$h_norm_name.min 0\n$h_norm_name.label $h_cur_name\n$h_norm_name.draw LINE2\n";
|
||||
my ( $warning, $critical ) =
|
||||
get_thresholds($h_norm_name);
|
||||
printf "%s.warning %s\n", $h_norm_name, $warning
|
||||
if $warning;
|
||||
printf "%s.critical %s\n", $h_norm_name, $critical
|
||||
if $critical;
|
||||
} else {
|
||||
my $pid = $fork ? fork() : -1;
|
||||
if ($pid <= 0) {
|
||||
# either we can't fork, or don't want to, or we are child
|
||||
my @ping = `$h_ping $ping_args $h_addr $ping_args2`;
|
||||
chomp @ping;
|
||||
my $ping = join(" ", @ping);
|
||||
my $ping_time = "U";
|
||||
my $packet_loss = "U";
|
||||
$ping_time = ($1 / 1000) if ($ping =~ m@min/avg/max.*\s\d+(?:\.\d+)?/(\d+(?:\.\d+)?)/\d+(?:\.\d+)?@);
|
||||
$packet_loss = $1 if ($ping =~ /(\d+)% packet loss/);
|
||||
print "$h_norm_name.value ". ($packetloss_mode ? $packet_loss : $ping_time) . "\n";
|
||||
if ($pid == 0) {
|
||||
# this is a child process, don't forget to exit
|
||||
exit(0);
|
||||
}
|
||||
} else {
|
||||
# in parent
|
||||
push @children, $pid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (my $child_i = 0; $child_i < @children; ++$child_i) {
|
||||
waitpid($children[$child_i], 0);
|
||||
}
|
BIN
plugins/ping/ping-day.png
Normal file
BIN
plugins/ping/ping-day.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
86
plugins/ping/ping-with-ceil
Executable file
86
plugins/ping/ping-with-ceil
Executable file
|
@ -0,0 +1,86 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Copyright (C) 2010 Michele Petrazzo <michele.petrazzo@gmail.com>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; version 2 dated June,
|
||||
# 1991.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Python (2.5+) version of the plugin to monitor ping times.
|
||||
# Evolution from the standard shipped with munin by adding a ceil.
|
||||
#
|
||||
# Thanks to "Jimmy Olsen" for the base.
|
||||
#
|
||||
# Parameters:
|
||||
#
|
||||
# ping_args - Arguments to ping (default "-c 2")
|
||||
# ping_args2 - Arguments after the host name (required for Solaris)
|
||||
# ping - Ping program to use
|
||||
# host - Host to ping
|
||||
#
|
||||
# Arguments for Solaris:
|
||||
# ping_args -s
|
||||
# ping_args2 56 2
|
||||
#
|
||||
|
||||
file_host=`basename $0 | sed 's/^ping_ceil_//g'`
|
||||
host=${host:-${file_host:-www.google.com}}
|
||||
max_ping="250" # Leave empty if not need or an integer (in ms)
|
||||
|
||||
test -z "$ping" && ping="ping"
|
||||
test -z "$ping_args" && ping_args="-c 2"
|
||||
|
||||
cmd="$ping $ping_args $ping_args2"
|
||||
|
||||
if [ "$1" = "config" ]; then
|
||||
echo "graph_title Ping times to $host"
|
||||
echo 'graph_args --base 1000 -l 0'
|
||||
echo 'graph_vlabel seconds'
|
||||
echo 'graph_category network'
|
||||
echo 'graph_info This graph shows ping RTT statistics.'
|
||||
echo "ping.label $host"
|
||||
echo "ping.info Ping RTT statistics for $host."
|
||||
echo 'ping.draw LINE2'
|
||||
echo 'packetloss.label packet loss'
|
||||
echo 'packetloss.graph no'
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
(
|
||||
cat << EOF
|
||||
import os
|
||||
from subprocess import Popen, PIPE
|
||||
bash_cmd = "$cmd"
|
||||
command = bash_cmd.split() + ["$host"]
|
||||
max_ping = float("$max_ping") if "$max_ping" else 0
|
||||
|
||||
try:
|
||||
c = Popen(command, stdout=PIPE, stderr=PIPE)
|
||||
except OSError:
|
||||
print "command error:", command
|
||||
raise
|
||||
|
||||
out, err = c.communicate()
|
||||
|
||||
for line in out.split("\n"):
|
||||
if "packet loss" in line:
|
||||
print "packetloss.value", line.split(",")[2].split()[0].replace("%", "")
|
||||
elif "rtt min/avg/max/mdev" in line:
|
||||
v = float(line.split("=")[1].split("/")[1])
|
||||
v = min(v, max_ping) if max_ping else v
|
||||
print "ping.value", "%.6f" % (v / 1000)
|
||||
|
||||
EOF
|
||||
) | python
|
||||
|
26
plugins/ping/ping_host
Executable file
26
plugins/ping/ping_host
Executable file
|
@ -0,0 +1,26 @@
|
|||
#!/bin/sh
|
||||
|
||||
H=`echo $0 | awk -F_ '{print $2}'`
|
||||
|
||||
if [ "$1" = "config" ] ; then
|
||||
|
||||
echo "graph_title Ping RTT $H"
|
||||
echo "graph_category network"
|
||||
echo "graph_info this graph shows the average RTT of five pings to $H"
|
||||
echo "graph_vlabel ping_rtt"
|
||||
echo "ping_rtt.label ms"
|
||||
echo "ping_rtt.warning 12"
|
||||
echo "ping_rtt.critical 15"
|
||||
echo "ping_loss.warning 40"
|
||||
echo "ping_loss.critical 60"
|
||||
exit
|
||||
fi
|
||||
|
||||
/sbin/ping -W 1 -c 5 $H > /tmp/munin-node-ping-$H
|
||||
|
||||
RTTAVG=`sed -n '2,6p' /tmp/munin-node-ping-$H | sed -e 's/.*time=//g' -e 's/ ms//g' | awk '{ ORS= "" ; print $1 " " }' | sed -e 's#$# + + + + 3 k 4 / p#g' | dc`
|
||||
PKTLOSS=`sed -n 9p /tmp/munin-node-ping-$H | sed -e 's/.*received, //g' -e 's/% packet loss//g'`
|
||||
|
||||
echo "ping_rtt.value $RTTAVG"
|
||||
echo "ping_loss.value $PKTLOSS"
|
||||
|
101
plugins/ping/pinger
Executable file
101
plugins/ping/pinger
Executable file
|
@ -0,0 +1,101 @@
|
|||
#!/bin/bash
|
||||
# This script is intended for use with Munin to monitor
|
||||
# ping response time from hosts and through interfaces specified.
|
||||
# v. 1.1, 12/16/2007
|
||||
# (c) Alex Yanchenko (yanchenko{at}gmail.com), 2007
|
||||
# Distributed under GPL v.3 (http://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
#
|
||||
# The plugin can utilize automatic configuration,
|
||||
# here are the basic steps (require root privileges):
|
||||
# 1. Copy it as /usr/share/munin/plugins/pinger
|
||||
# 2. Make executable: "chmod 755 /usr/share/munin/plugins/pinger"
|
||||
# 3. Customize hosts, interfaces and ping count below
|
||||
# 4. As pinging takes much time, add a
|
||||
# --
|
||||
# [pinger]
|
||||
# timeout 60
|
||||
# --
|
||||
# record to /etc/munin/munin-node.conf to avoid timeouts.
|
||||
# 5. Run "munin-node-configure --shell", you should see smth like
|
||||
# "ln -s /usr/share/munin/plugins/pinger /etc/munin/plugins/pinger"
|
||||
# 6. Run the proposed command to create a link.
|
||||
# 7. To verify, run "munin-node-configure", you should notice the "pinger" record
|
||||
#
|
||||
# Plugin | Used | Suggestions
|
||||
# ------ | ---- | -----------
|
||||
# pinger | yes |
|
||||
#
|
||||
# 8. Restart munin: "/etc/init.d/munin-node restart"
|
||||
# 9. Hold on for 5 minutes at most and watch the graphs appear.
|
||||
#
|
||||
#%# family=contrib
|
||||
#%# capabilities=autoconf
|
||||
|
||||
#----- PROPERTIES START -----#
|
||||
# An array of interfaces to ping through, space-separated.
|
||||
# In case vnstat is installed, interface names will be fetced
|
||||
# from it, 'nicknames'included.
|
||||
INTERFACE=(eth2 eth3)
|
||||
|
||||
# An array of hosts to ping, space-separated.
|
||||
HOST=(dc.volia.com hosting.rbc.ru slicehost.com)
|
||||
|
||||
# Ping count, higher values lead to more precise
|
||||
# results yet take more time
|
||||
PING=3
|
||||
#----- PROPERTIES END -----#
|
||||
|
||||
# Try to get interface name from vnstat, make sure the name is assigned
|
||||
function IF_NAME() {
|
||||
ARG=$1
|
||||
if [[ $(which vnstat &>/dev/null; echo $?) == 0 ]]
|
||||
then
|
||||
IF_NAME="$(vnstat | grep "$ARG" | cut -d" " -f2,3 | cut -d":" -f1)"
|
||||
else
|
||||
IF_NAME="$ARG"
|
||||
fi
|
||||
echo $IF_NAME
|
||||
}
|
||||
|
||||
# Ping given host through a given interface
|
||||
function PINGER() {
|
||||
ping $2 -c${PING} -I$1 | grep "rtt min/avg/max/mdev" | cut -d" " -f4 | cut -d"/" -f2 | cut -d"." -f1
|
||||
}
|
||||
|
||||
case $1 in
|
||||
autoconf)
|
||||
which ping
|
||||
if [[ "$?" = "0" ]]; then
|
||||
echo yes
|
||||
exit 0
|
||||
else
|
||||
echo "no (ping not present)"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
config)
|
||||
cat << EOM
|
||||
graph_title Pinger
|
||||
graph_category network
|
||||
graph_info A nice thingy to ping remote hosts.
|
||||
graph_vlabel msec
|
||||
graph_args --base 1000 --lower-limit 0
|
||||
EOM
|
||||
for (( i=0; i<"${#HOST[*]}"; i++ ))
|
||||
do
|
||||
for (( j=0; j<"${#INTERFACE[*]}"; j++ ))
|
||||
do
|
||||
echo "${j}_${i}.label $(IF_NAME ${INTERFACE[$j]}) - ${HOST[$i]}"
|
||||
done
|
||||
done
|
||||
;;
|
||||
*)
|
||||
for (( i=0; i<"${#HOST[*]}"; i++ ))
|
||||
do
|
||||
for (( j=0; j<"${#INTERFACE[*]}"; j++ ))
|
||||
do
|
||||
echo "${j}_${i}.value $(PINGER ${INTERFACE[$j]} ${HOST[$i]})"
|
||||
done
|
||||
done
|
||||
;;
|
||||
esac
|
Loading…
Add table
Add a link
Reference in a new issue