diff options
author | Matthias Rampke <matthias@rampke.de> | 2015-09-26 20:54:49 +0200 |
---|---|---|
committer | Matthias Rampke <mr@soundcloud.com> | 2015-09-28 13:56:22 +0000 |
commit | 7c47338081071dadbfd7583afe580065f877b713 (patch) | |
tree | 5595d8c80007ea592f33468d561602866dd17424 /end-to-end-test.sh | |
parent | 788ac9a8596c513490842d305c0acb41bb5de436 (diff) | |
download | prometheus_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-x | end-to-end-test.sh | 91 |
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 | |||
3 | set +euf +o pipefail | ||
4 | |||
5 | cd "$(dirname $0)" | ||
6 | |||
7 | port="$((10000 + (RANDOM % 10000)))" | ||
8 | tmpdir=$(mktemp -d /tmp/node_exporter_e2e_test.XXXXXX) | ||
9 | |||
10 | skip_re="^(go_|node_exporter_|process_|node_textfile_mtime)" | ||
11 | |||
12 | keep=0; update=0; verbose=0 | ||
13 | while getopts 'hkuv' opt | ||
14 | do | ||
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 | ||
34 | done | ||
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 | |||
46 | echo $! > "${tmpdir}/node_exporter.pid" | ||
47 | |||
48 | finish() { | ||
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 | |||
70 | trap finish EXIT | ||
71 | |||
72 | get() { | ||
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 | |||
85 | sleep 1 | ||
86 | |||
87 | get "127.0.0.1:${port}/metrics" > "${tmpdir}/e2e-output.txt" | ||
88 | |||
89 | diff -u \ | ||
90 | <(grep -E -v "${skip_re}" "collector/fixtures/e2e-output.txt") \ | ||
91 | <(grep -E -v "${skip_re}" "${tmpdir}/e2e-output.txt") | ||