add fping.plugin; fixes #1122
Costa Tsaousis (ktsaou) committed
Oct 16, 2016 at 03:35 UTC
fafe61cadac193f1f00b42cdc027af7cc3bf1fed
2 files changed
+86
plugins.d/Makefile.am
+1
@@ -13,6 +13,7 @@ dist_plugins_SCRIPTS = \
13
cgroup-name.sh \
14
charts.d.dryrun-helper.sh \
15
charts.d.plugin \
16
+ fping.plugin \
17
node.d.plugin \
18
python.d.plugin \
19
tc-qos-helper.sh \
plugins.d/fping.plugin
new
+85
@@ -0,0 +1,85 @@
1
+#!/usr/bin/env bash
2
+
3
+me="${0}"
4
+
5
+# the frequency to send info to netdata
6
+# passed by netdata as the first parameter
7
+update_every="${1-1}"
8
+
9
+# the netdata configuration directory
10
+# passed by netdata as an environment variable
11
+NETDATA_CONFIG_DIR="${NETDATA_CONFIG_DIR-/etc/netdata}"
12
+
13
+# -----------------------------------------------------------------------------
14
+
15
+# This plugin requires a special version of fping.
16
+# Get it from https://github.com/ktsaou/fping
17
+# and build it, like this:
18
+#
19
+# cd /usr/src
20
+# git clone https://github.com/ktsaou/fping.git fping-netdata.git
21
+# cd fping-netdata.git
22
+# ./autogen.sh
23
+# ./configure --prefix=/usr/local
24
+# make
25
+# cp src/fping /usr/local/bin/
26
+# chown root:root /usr/local/bin/fping
27
+# chmod 4755 /usr/local/bin/fping
28
+#
29
+# Then, create /etc/netdata/fping.conf
30
+# and set the configuration options given below
31
+
32
+# -----------------------------------------------------------------------------
33
+# configuration options
34
+# can be overwritten at /etc/netdata/fping.conf
35
+
36
+# the fping binary to use
37
+# we need one that can output netdata friendly info
38
+fping="$(which fping || command -v fping)"
39
+
40
+# a space separated list of hosts to fping
41
+hosts=""
42
+
43
+# the time in milliseconds (1 sec = 1000 ms)
44
+# to ping the hosts - by default 2 pings per iteration
45
+ping_every="$((update_every * 1000 / 2))"
46
+
47
+# how many retries to make if a host does not respond
48
+retries=1
49
+
50
+# -----------------------------------------------------------------------------
51
+
52
+# load the configuration file
53
+if [ ! -f "${NETDATA_CONFIG_DIR}/fping.conf" ]
54
+then
55
+ echo >&2 "${me}: configuration file '${NETDATA_CONFIG_DIR}/fping.conf' not found - nothing to do."
56
+ echo "DISABLE"
57
+ exit 1
58
+fi
59
+
60
+source "${NETDATA_CONFIG_DIR}/fping.conf"
61
+
62
+if [ -z "${hosts}" ]
63
+then
64
+ echo >&2 "${me}: no hosts configued in '${NETDATA_CONFIG_DIR}/fping.conf' - nothing to do."
65
+ echo "DISABLE"
66
+ exit 1
67
+fi
68
+
69
+if [ -z "${fping}" -o ! -x "${fping}" ]
70
+then
71
+ echo >&2 "${me}: command '${fping}' is not executable - cannot proceed."
72
+ echo "DISABLE"
73
+ exit 1
74
+fi
75
+
76
+# the fping options we will use
77
+options=( -N -l -R -Q ${update_every} -p ${ping_every} -r ${retries} ${hosts} )
78
+
79
+# execute fping
80
+exec "${fping}" "${options[@]}"
81
+
82
+# if we cannot execute fping, stop
83
+echo >&2 "${me}: command '${fping} ${options[@]}' failed to be executed."
84
+echo "DISABLE"
85
+exit 1