forked from netdata/netdata
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfping.plugin
More file actions
executable file
·122 lines (93 loc) · 2.78 KB
/
fping.plugin
File metadata and controls
executable file
·122 lines (93 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/env bash
# netdata
# real-time performance and health monitoring, done right!
# (C) 2016 Costa Tsaousis <[email protected]>
# GPL v3+
#
# This plugin requires a special version of fping.
# Get it from https://github.com/ktsaou/fping
# and build it, like this:
#
# cd /usr/src
# git clone https://github.com/ktsaou/fping.git fping-netdata.git
# cd fping-netdata.git
# ./autogen.sh
# ./configure --prefix=/usr/local
# make
# cp src/fping /usr/local/bin/
# chown root:root /usr/local/bin/fping
# chmod 4755 /usr/local/bin/fping
#
# Then, create /etc/netdata/fping.conf
# and set the configuration options given below
export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
export LC_ALL=C
# -----------------------------------------------------------------------------
PROGRAM_NAME="$(basename "${0}")"
logdate() {
date "+%Y-%m-%d %H:%M:%S"
}
log() {
local status="${1}"
shift
echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
}
warning() {
log WARNING "${@}"
}
error() {
log ERROR "${@}"
}
info() {
log INFO "${@}"
}
fatal() {
log FATAL "${@}"
echo "DISABLE"
exit 1
}
debug=0
debug() {
[ $debug -eq 1 ] && log DEBUG "${@}"
}
# -----------------------------------------------------------------------------
# the frequency to send info to netdata
# passed by netdata as the first parameter
update_every="${1-1}"
# the netdata configuration directory
# passed by netdata as an environment variable
NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
# -----------------------------------------------------------------------------
# configuration options
# can be overwritten at /etc/netdata/fping.conf
# the fping binary to use
# we need one that can output netdata friendly info
fping="$(which fping || command -v fping)"
# a space separated list of hosts to fping
hosts=""
# the time in milliseconds (1 sec = 1000 ms)
# to ping the hosts - by default 2 pings per iteration
ping_every="$((update_every * 1000 / 2))"
# how many retries to make if a host does not respond
retries=1
# -----------------------------------------------------------------------------
# load the configuration file
if [ ! -f "${NETDATA_CONFIG_DIR}/fping.conf" ]
then
fatal "configuration file '${NETDATA_CONFIG_DIR}/fping.conf' not found - nothing to do."
fi
source "${NETDATA_CONFIG_DIR}/fping.conf"
if [ -z "${hosts}" ]
then
fatal "no hosts configued in '${NETDATA_CONFIG_DIR}/fping.conf' - nothing to do."
fi
if [ -z "${fping}" -o ! -x "${fping}" ]
then
fatal "command '${fping}' is not executable - cannot proceed."
fi
# the fping options we will use
options=( -N -l -R -Q ${update_every} -p ${ping_every} -r ${retries} ${hosts} )
# execute fping
exec "${fping}" "${options[@]}"
# if we cannot execute fping, stop
fatal "command '${fping} ${options[@]}' failed to be executed."