aboutsummaryrefslogtreecommitdiff
path: root/end-to-end-test.sh
diff options
context:
space:
mode:
authorMatthias Rampke <matthias@rampke.de>2015-09-26 20:54:49 +0200
committerMatthias Rampke <mr@soundcloud.com>2015-09-28 13:56:22 +0000
commit7c47338081071dadbfd7583afe580065f877b713 (patch)
tree5595d8c80007ea592f33468d561602866dd17424 /end-to-end-test.sh
parent788ac9a8596c513490842d305c0acb41bb5de436 (diff)
downloadprometheus_node_collector-7c47338081071dadbfd7583afe580065f877b713.tar.bz2
prometheus_node_collector-7c47338081071dadbfd7583afe580065f877b713.tar.xz
prometheus_node_collector-7c47338081071dadbfd7583afe580065f877b713.zip
Add an end-to-end test.
This test runs a selection of collectors against the fixtures and compares the output to a reference. The uname and filesystem collectors are disabled because they use system calls that cannot be fixtured easily.
Diffstat (limited to 'end-to-end-test.sh')
-rwxr-xr-xend-to-end-test.sh91
1 files changed, 91 insertions, 0 deletions
diff --git a/end-to-end-test.sh b/end-to-end-test.sh
new file mode 100755
index 0000000..fdfe480
--- /dev/null
+++ b/end-to-end-test.sh
@@ -0,0 +1,91 @@
1#!/usr/bin/env bash
2
3set +euf +o pipefail
4
5cd "$(dirname $0)"
6
7port="$((10000 + (RANDOM % 10000)))"
8tmpdir=$(mktemp -d /tmp/node_exporter_e2e_test.XXXXXX)
9
10skip_re="^(go_|node_exporter_|process_|node_textfile_mtime)"
11
12keep=0; update=0; verbose=0
13while getopts 'hkuv' opt
14do
15 case "$opt" in
16 k)
17 keep=1
18 ;;
19 u)
20 update=1
21 ;;
22 v)
23 verbose=1
24 set -x
25 ;;
26 *)
27 echo "Usage: $0 [-k] [-u] [-v]"
28 echo " -k: keep temporary files and leave node_exporter running"
29 echo " -u: update fixture"
30 echo " -v: verbose output"
31 exit 1
32 ;;
33 esac
34done
35
36
37./node_exporter \
38 -collector.procfs="collector/fixtures/proc" \
39 -collector.sysfs="collector/fixtures/sys" \
40 -collectors.enabled="diskstats,filefd,loadavg,mdadm,meminfo,netdev,netstat,sockstat,stat,textfile,bonding,megacli" \
41 -collector.textfile.directory="collector/fixtures/textfile/two_metric_files/" \
42 -collector.megacli.command="collector/fixtures/megacli" \
43 -web.listen-address "127.0.0.1:${port}" \
44 -log.level="debug" > "${tmpdir}/node_exporter.log" 2>&1 &
45
46echo $! > "${tmpdir}/node_exporter.pid"
47
48finish() {
49 if [ ${verbose} -ne 0 ]
50 then
51 echo "LOG ====================="
52 cat "${tmpdir}/node_exporter.log"
53 echo "========================="
54 fi
55
56 if [ ${update} -ne 0 ]
57 then
58 cp "${tmpdir}/e2e-output.txt" "collector/fixtures/e2e-output.txt"
59 fi
60
61 if [ ${keep} -eq 0 ]
62 then
63 kill -9 "$(cat ${tmpdir}/node_exporter.pid)"
64 # This silences the "Killed" message
65 wait "$(cat ${tmpdir}/node_exporter.pid)" > /dev/null 2>&1
66 rm -rf "${tmpdir}"
67 fi
68}
69
70trap finish EXIT
71
72get() {
73 if which curl > /dev/null 2>&1
74 then
75 curl -s -f "$@"
76 elif which wget > /dev/null 2>&1
77 then
78 wget -O - "$@"
79 else
80 echo "Neither curl nor wget found"
81 exit 1
82 fi
83}
84
85sleep 1
86
87get "127.0.0.1:${port}/metrics" > "${tmpdir}/e2e-output.txt"
88
89diff -u \
90 <(grep -E -v "${skip_re}" "collector/fixtures/e2e-output.txt") \
91 <(grep -E -v "${skip_re}" "${tmpdir}/e2e-output.txt")