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 " "${@}"
25 [ ! -d /usr/src ] && run mkdir -p /usr/src
26 [ ! -d /usr/local/bin ] && run mkdir -p /usr/local/bin
30 if [ -d fping-ktsaou.git ]
32 run cd fping-ktsaou.git
35 run git clone https://github.com/ktsaou/fping.git fping-ktsaou.git
36 run cd fping-ktsaou.git
40 run ./configure --prefix=/usr/local
43 if [ -f /usr/local/bin/fping ]
45 run mv -f /usr/local/bin/fping /usr/local/bin/fping.old
47 run mv src/fping /usr/local/bin/fping
48 run chown root:root /usr/local/bin/fping
49 run chmod 4755 /usr/local/bin/fping
51 echo >&2 "All done, you have a compatible fping now at /usr/local/bin/fping."
54 fping="$(which fping 2>/dev/null || command -v fping 2>/dev/null)"
55 if [ "${fping}" != "/usr/local/bin/fping" ]
57 echo >&2 "You have another fping installed at: ${fping}."
58 echo >&2 "Please set:"
60 echo >&2 " fping=\"/usr/local/bin/fping\""
62 echo >&2 "at /etc/netdata/fping.conf"
68 # -----------------------------------------------------------------------------
70 PROGRAM_NAME="$(basename "${0}")"
73 date "+%Y-%m-%d %H:%M:%S"
80 echo >&2 "$(logdate): ${PROGRAM_NAME}: ${status}: ${*}"
104 [ $debug -eq 1 ] && log DEBUG "${@}"
107 # -----------------------------------------------------------------------------
109 # the frequency to send info to netdata
110 # passed by netdata as the first parameter
111 update_every="${1-1}"
113 # the netdata configuration directory
114 # passed by netdata as an environment variable
115 NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
117 # -----------------------------------------------------------------------------
118 # configuration options
119 # can be overwritten at /etc/netdata/fping.conf
121 # the fping binary to use
122 # we need one that can output netdata friendly info (supporting: -N)
123 # if you have multiple versions, put here the full filename of the right one
124 fping="$( which fping 2>/dev/null || command -v fping 2>/dev/null )"
126 # a space separated list of hosts to fping
127 # we suggest to put names here and the IPs of these names in /etc/hosts
130 # the time in milliseconds (1 sec = 1000 ms)
131 # to ping the hosts - by default 5 pings per host per iteration
132 ping_every="$((update_every * 1000 / 5))"
135 fping_opts="-R -b 56 -i 1 -r 0 -t 5000"
137 # -----------------------------------------------------------------------------
138 # load the configuration file
140 if [ ! -f "${NETDATA_CONFIG_DIR}/fping.conf" ]
142 fatal "configuration file '${NETDATA_CONFIG_DIR}/fping.conf' not found - nothing to do."
145 source "${NETDATA_CONFIG_DIR}/fping.conf"
149 fatal "no hosts configued in '${NETDATA_CONFIG_DIR}/fping.conf' - nothing to do."
152 if [ -z "${fping}" -o ! -x "${fping}" ]
154 fatal "command '${fping}' is not executable - cannot proceed."
157 if [ ${ping_every} -lt 20 ]
159 warning "ping every was set to ${ping_every} but 20 is the minimum for non-root users. Setting it to 20 ms."
163 # the fping options we will use
164 options=( -N -l -Q ${update_every} -p ${ping_every} ${fping_opts} ${hosts} )
167 exec "${fping}" "${options[@]}"
169 # if we cannot execute fping, stop
170 fatal "command '${fping} ${options[@]}' failed to be executed."