4 # real-time performance and health monitoring, done right!
5 # (C) 2016 Costa Tsaousis <costa@tsaousis.gr>
8 # This plugin requires a latest version of fping.
9 # You can compile it from source, by running me with option: install
11 export PATH="${PATH}:/sbin:/usr/sbin:/usr/local/sbin"
14 if [ "${1}" = "install" ]
16 [ "${UID}" != 0 ] && echo >&2 "Please run me as root. This will install a single binary file: /usr/local/bin/fping." && exit 1
20 printf >&2 "%q " "${@}"
26 local curl="$(which curl 2>/dev/null || command -v curl 2>/dev/null)"
27 [ ! -z "${curl}" ] && run curl -s -L "${1}" && return 0
29 local wget="$(which wget 2>/dev/null || command -v wget 2>/dev/null)"
30 [ ! -z "${wget}" ] && run wget -q -O - "${1}" && return 0
32 echo >&2 "Cannot find 'curl' or 'wget' in this system." && exit 1
35 [ ! -d /usr/src ] && run mkdir -p /usr/src
36 [ ! -d /usr/local/bin ] && run mkdir -p /usr/local/bin
42 run rm -rf fping-3.15 || exit 1
45 download 'https://github.com/schweikert/fping/archive/3.15.tar.gz' | run tar -zxvpf -
46 [ $? -ne 0 ] && exit 1
47 run cd fping-3.15 || exit 1
49 #if [ -d fping-ktsaou.git ]
51 # run cd fping-ktsaou.git
54 # run git clone https://github.com/ktsaou/fping.git fping-ktsaou.git
55 # run cd fping-ktsaou.git
59 run ./configure --prefix=/usr/local
62 if [ -f /usr/local/bin/fping ]
64 run mv -f /usr/local/bin/fping /usr/local/bin/fping.old
66 run mv src/fping /usr/local/bin/fping
67 run chown root:root /usr/local/bin/fping
68 run chmod 4755 /usr/local/bin/fping
70 echo >&2 "All done, you have a compatible fping now at /usr/local/bin/fping."
73 fping="$(which fping 2>/dev/null || command -v fping 2>/dev/null)"
74 if [ "${fping}" != "/usr/local/bin/fping" ]
76 echo >&2 "You have another fping installed at: ${fping}."
77 echo >&2 "Please set:"
79 echo >&2 " fping=\"/usr/local/bin/fping\""
81 echo >&2 "at /etc/netdata/fping.conf"
87 # -----------------------------------------------------------------------------
89 PROGRAM_NAME="$(basename "${0}")"
92 date "+%Y-%m-%d %H:%M:%S"
99 echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
123 [ $debug -eq 1 ] && log DEBUG "${@}"
126 # -----------------------------------------------------------------------------
128 # store in ${plugin} the name we run under
129 # this allows us to copy/link fping.plugin under a different name
130 # to have multiple fping plugins running with different settings
131 plugin="${PROGRAM_NAME/.plugin/}"
134 # -----------------------------------------------------------------------------
136 # the frequency to send info to netdata
137 # passed by netdata as the first parameter
138 update_every="${1-1}"
140 # the netdata configuration directory
141 # passed by netdata as an environment variable
142 NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
144 # -----------------------------------------------------------------------------
145 # configuration options
146 # can be overwritten at /etc/netdata/fping.conf
148 # the fping binary to use
149 # we need one that can output netdata friendly info (supporting: -N)
150 # if you have multiple versions, put here the full filename of the right one
151 fping="$( which fping 2>/dev/null || command -v fping 2>/dev/null )"
153 # a space separated list of hosts to fping
154 # we suggest to put names here and the IPs of these names in /etc/hosts
157 # the time in milliseconds (1 sec = 1000 ms)
158 # to ping the hosts - by default 5 pings per host per iteration
159 ping_every="$((update_every * 1000 / 5))"
162 fping_opts="-R -b 56 -i 1 -r 0 -t 5000"
164 # -----------------------------------------------------------------------------
165 # load the configuration file
167 if [ ! -f "${NETDATA_CONFIG_DIR}/${plugin}.conf" ]
169 fatal "configuration file '${NETDATA_CONFIG_DIR}/${plugin}.conf' not found - nothing to do."
172 source "${NETDATA_CONFIG_DIR}/${plugin}.conf"
176 fatal "no hosts configued in '${NETDATA_CONFIG_DIR}/${plugin}.conf' - nothing to do."
179 if [ -z "${fping}" -o ! -x "${fping}" ]
181 fatal "command '${fping}' is not found or is not executable - cannot proceed."
184 if [ ${ping_every} -lt 20 ]
186 warning "ping every was set to ${ping_every} but 20 is the minimum for non-root users. Setting it to 20 ms."
190 # the fping options we will use
191 options=( -N -l -Q ${update_every} -p ${ping_every} ${fping_opts} ${hosts} )
194 exec "${fping}" "${options[@]}"
196 # if we cannot execute fping, stop
197 fatal "command '${fping} ${options[@]}' failed to be executed."