root / plugins / ping / pinger @ d2161137
Historique | Voir | Annoter | Télécharger (3,45 ko)
| 1 |
#!/bin/bash |
|---|---|
| 2 |
# This script is intended for use with Munin to monitor |
| 3 |
# ping response time from hosts and through interfaces specified. |
| 4 |
# v. 1.1, 12/16/2007 |
| 5 |
# (c) Alex Yanchenko (yanchenko{at}gmail.com), 2007
|
| 6 |
# Distributed under GPL v.3 (http://www.gnu.org/licenses/gpl-3.0.txt) |
| 7 |
# |
| 8 |
# The plugin can utilize automatic configuration, |
| 9 |
# here are the basic steps (require root privileges): |
| 10 |
# 1. Copy it as /usr/share/munin/plugins/pinger |
| 11 |
# 2. Make executable: "chmod 755 /usr/share/munin/plugins/pinger" |
| 12 |
# 3. Customize hosts, interfaces and ping count below |
| 13 |
# 4. As pinging takes much time, add a |
| 14 |
# -- |
| 15 |
# [pinger] |
| 16 |
# timeout 60 |
| 17 |
# -- |
| 18 |
# record to /etc/munin/munin-node.conf to avoid timeouts. |
| 19 |
# 5. Run "munin-node-configure --shell", you should see smth like |
| 20 |
# "ln -s /usr/share/munin/plugins/pinger /etc/munin/plugins/pinger" |
| 21 |
# 6. Run the proposed command to create a link. |
| 22 |
# 7. To verify, run "munin-node-configure", you should notice the "pinger" record |
| 23 |
# |
| 24 |
# Plugin | Used | Suggestions |
| 25 |
# ------ | ---- | ----------- |
| 26 |
# pinger | yes | |
| 27 |
# |
| 28 |
# 8. Restart munin: "/etc/init.d/munin-node restart" |
| 29 |
# 9. Hold on for 5 minutes at most and watch the graphs appear. |
| 30 |
# |
| 31 |
#%# family=contrib |
| 32 |
#%# capabilities=autoconf |
| 33 |
|
| 34 |
#----- PROPERTIES START -----# |
| 35 |
# An array of interfaces to ping through, space-separated. |
| 36 |
# In case vnstat is installed, interface names will be fetced |
| 37 |
# from it, 'nicknames'included. |
| 38 |
INTERFACE=(eth2 eth3) |
| 39 |
|
| 40 |
# An array of hosts to ping, space-separated. |
| 41 |
HOST=(dc.volia.com hosting.rbc.ru slicehost.com) |
| 42 |
|
| 43 |
# Ping count, higher values lead to more precise |
| 44 |
# results yet take more time |
| 45 |
PING=3 |
| 46 |
#----- PROPERTIES END -----# |
| 47 |
|
| 48 |
# Try to get interface name from vnstat, make sure the name is assigned |
| 49 |
function IF_NAME() {
|
| 50 |
ARG=$1 |
| 51 |
if [[ $(which vnstat &>/dev/null; echo $?) == 0 ]] |
| 52 |
then |
| 53 |
IF_NAME="$(vnstat | grep "$ARG" | cut -d" " -f2,3 | cut -d":" -f1)" |
| 54 |
else |
| 55 |
IF_NAME="$ARG" |
| 56 |
fi |
| 57 |
echo $IF_NAME |
| 58 |
} |
| 59 |
|
| 60 |
# Ping given host through a given interface |
| 61 |
function PINGER() {
|
| 62 |
ping $2 -c${PING} -I$1 | grep "rtt min/avg/max/mdev" | cut -d" " -f4 | cut -d"/" -f2 | cut -d"." -f1
|
| 63 |
} |
| 64 |
|
| 65 |
case $1 in |
| 66 |
autoconf) |
| 67 |
which ping |
| 68 |
if [[ "$?" = "0" ]]; then |
| 69 |
echo yes |
| 70 |
exit 0 |
| 71 |
else |
| 72 |
echo "no (ping not present)" |
| 73 |
exit 1 |
| 74 |
fi |
| 75 |
;; |
| 76 |
config) |
| 77 |
cat << EOM |
| 78 |
graph_title Pinger |
| 79 |
graph_category network |
| 80 |
graph_info A nice thingy to ping remote hosts. |
| 81 |
graph_vlabel msec |
| 82 |
graph_args --base 1000 --lower-limit 0 |
| 83 |
EOM |
| 84 |
for (( i=0; i<"${#HOST[*]}"; i++ ))
|
| 85 |
do |
| 86 |
for (( j=0; j<"${#INTERFACE[*]}"; j++ ))
|
| 87 |
do |
| 88 |
echo "${j}_${i}.label $(IF_NAME ${INTERFACE[$j]}) - ${HOST[$i]}"
|
| 89 |
done |
| 90 |
done |
| 91 |
;; |
| 92 |
*) |
| 93 |
for (( i=0; i<"${#HOST[*]}"; i++ ))
|
| 94 |
do |
| 95 |
for (( j=0; j<"${#INTERFACE[*]}"; j++ ))
|
| 96 |
do |
| 97 |
echo "${j}_${i}.value $(PINGER ${INTERFACE[$j]} ${HOST[$i]})"
|
| 98 |
done |
| 99 |
done |
| 100 |
;; |
| 101 |
esac |
