2015-09-26 20:54:49 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2015-10-17 12:31:51 +02:00
|
|
|
set -euf -o pipefail
|
2015-09-26 20:54:49 +02:00
|
|
|
|
2016-01-14 10:51:11 +01:00
|
|
|
collectors=$(cat << COLLECTORS
|
2017-04-11 17:45:19 +02:00
|
|
|
arp
|
2017-02-07 16:11:22 +01:00
|
|
|
buddyinfo
|
2016-01-14 10:51:11 +01:00
|
|
|
conntrack
|
2017-06-13 11:21:53 +02:00
|
|
|
cpu
|
2016-01-14 10:51:11 +01:00
|
|
|
diskstats
|
2016-12-05 11:37:35 +01:00
|
|
|
drbd
|
2017-01-08 12:58:04 +01:00
|
|
|
edac
|
2016-01-14 10:51:11 +01:00
|
|
|
entropy
|
|
|
|
filefd
|
2016-10-06 17:33:24 +02:00
|
|
|
hwmon
|
2017-02-07 17:46:51 +01:00
|
|
|
infiniband
|
2015-11-11 14:02:41 +01:00
|
|
|
ksmd
|
2016-01-14 10:51:11 +01:00
|
|
|
loadavg
|
|
|
|
mdadm
|
|
|
|
meminfo
|
2015-11-13 10:23:21 +01:00
|
|
|
meminfo_numa
|
2016-12-12 22:46:45 +01:00
|
|
|
mountstats
|
2016-01-14 10:51:11 +01:00
|
|
|
netdev
|
|
|
|
netstat
|
2016-11-29 14:32:52 +01:00
|
|
|
nfs
|
2017-05-23 11:55:50 +02:00
|
|
|
qdisc
|
2016-01-14 10:51:11 +01:00
|
|
|
sockstat
|
|
|
|
stat
|
|
|
|
textfile
|
|
|
|
bonding
|
|
|
|
megacli
|
2017-01-09 20:37:59 +01:00
|
|
|
wifi
|
2017-04-22 00:19:35 +02:00
|
|
|
xfs
|
2017-01-08 17:17:06 +01:00
|
|
|
zfs
|
2016-01-14 10:51:11 +01:00
|
|
|
COLLECTORS
|
|
|
|
)
|
2015-09-26 20:54:49 +02:00
|
|
|
cd "$(dirname $0)"
|
|
|
|
|
|
|
|
port="$((10000 + (RANDOM % 10000)))"
|
|
|
|
tmpdir=$(mktemp -d /tmp/node_exporter_e2e_test.XXXXXX)
|
|
|
|
|
2017-03-16 18:21:00 +01:00
|
|
|
skip_re="^(go_|node_exporter_build_info|node_scrape_collector_duration_seconds|process_|node_textfile_mtime)"
|
2015-09-26 20:54:49 +02:00
|
|
|
|
|
|
|
keep=0; update=0; verbose=0
|
|
|
|
while getopts 'hkuv' opt
|
|
|
|
do
|
|
|
|
case "$opt" in
|
|
|
|
k)
|
|
|
|
keep=1
|
|
|
|
;;
|
|
|
|
u)
|
|
|
|
update=1
|
|
|
|
;;
|
|
|
|
v)
|
|
|
|
verbose=1
|
|
|
|
set -x
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: $0 [-k] [-u] [-v]"
|
|
|
|
echo " -k: keep temporary files and leave node_exporter running"
|
|
|
|
echo " -u: update fixture"
|
|
|
|
echo " -v: verbose output"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2015-10-16 21:39:12 +02:00
|
|
|
if [ ! -x ./node_exporter ]
|
|
|
|
then
|
|
|
|
echo './node_exporter not found. Consider running `go build` first.' >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-09-26 20:54:49 +02:00
|
|
|
|
|
|
|
./node_exporter \
|
|
|
|
-collector.procfs="collector/fixtures/proc" \
|
|
|
|
-collector.sysfs="collector/fixtures/sys" \
|
2016-01-14 10:51:11 +01:00
|
|
|
-collectors.enabled="$(echo ${collectors} | tr ' ' ',')" \
|
2015-09-26 20:54:49 +02:00
|
|
|
-collector.textfile.directory="collector/fixtures/textfile/two_metric_files/" \
|
|
|
|
-collector.megacli.command="collector/fixtures/megacli" \
|
2017-01-09 20:37:59 +01:00
|
|
|
-collector.wifi="collector/fixtures/wifi" \
|
2017-05-23 11:55:50 +02:00
|
|
|
-collector.qdisc="collector/fixtures/qdisc/" \
|
2015-09-26 20:54:49 +02:00
|
|
|
-web.listen-address "127.0.0.1:${port}" \
|
|
|
|
-log.level="debug" > "${tmpdir}/node_exporter.log" 2>&1 &
|
|
|
|
|
|
|
|
echo $! > "${tmpdir}/node_exporter.pid"
|
|
|
|
|
|
|
|
finish() {
|
2016-12-21 11:51:53 +01:00
|
|
|
if [ $? -ne 0 -o ${verbose} -ne 0 ]
|
2015-09-26 20:54:49 +02:00
|
|
|
then
|
2016-12-21 11:51:53 +01:00
|
|
|
cat << EOF >&2
|
|
|
|
LOG =====================
|
|
|
|
$(cat "${tmpdir}/node_exporter.log")
|
|
|
|
=========================
|
|
|
|
EOF
|
2015-09-26 20:54:49 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${update} -ne 0 ]
|
|
|
|
then
|
|
|
|
cp "${tmpdir}/e2e-output.txt" "collector/fixtures/e2e-output.txt"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${keep} -eq 0 ]
|
|
|
|
then
|
|
|
|
kill -9 "$(cat ${tmpdir}/node_exporter.pid)"
|
|
|
|
# This silences the "Killed" message
|
2015-10-16 21:39:12 +02:00
|
|
|
set +e
|
2015-09-26 20:54:49 +02:00
|
|
|
wait "$(cat ${tmpdir}/node_exporter.pid)" > /dev/null 2>&1
|
|
|
|
rm -rf "${tmpdir}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
trap finish EXIT
|
|
|
|
|
|
|
|
get() {
|
2016-12-21 19:00:38 +01:00
|
|
|
if command -v curl > /dev/null 2>&1
|
2015-09-26 20:54:49 +02:00
|
|
|
then
|
|
|
|
curl -s -f "$@"
|
2016-12-21 19:00:38 +01:00
|
|
|
elif command -v wget > /dev/null 2>&1
|
2015-09-26 20:54:49 +02:00
|
|
|
then
|
|
|
|
wget -O - "$@"
|
|
|
|
else
|
|
|
|
echo "Neither curl nor wget found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
|
2017-01-06 12:36:26 +01:00
|
|
|
get "127.0.0.1:${port}/metrics" | grep -E -v "${skip_re}" > "${tmpdir}/e2e-output.txt"
|
2015-09-26 20:54:49 +02:00
|
|
|
|
|
|
|
diff -u \
|
2017-01-06 12:36:26 +01:00
|
|
|
"collector/fixtures/e2e-output.txt" \
|
|
|
|
"${tmpdir}/e2e-output.txt"
|