forked from prometheus/node_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
end-to-end-test.sh
executable file
·201 lines (182 loc) · 4.25 KB
/
end-to-end-test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env bash
set -euf -o pipefail
enabled_collectors=$(cat << COLLECTORS
arp
bcache
bonding
btrfs
buddyinfo
cgroups
conntrack
cpu
cpufreq
cpu_vulnerabilities
diskstats
dmi
drbd
edac
entropy
fibrechannel
filefd
hwmon
infiniband
interrupts
ipvs
ksmd
lnstat
loadavg
mdadm
meminfo
meminfo_numa
mountstats
netdev
netstat
nfs
nfsd
pressure
processes
qdisc
rapl
schedstat
selinux
slabinfo
sockstat
softirqs
stat
sysctl
textfile
thermal_zone
udp_queues
vmstat
wifi
xfrm
xfs
zfs
zoneinfo
COLLECTORS
)
disabled_collectors=$(cat << COLLECTORS
filesystem
timex
uname
COLLECTORS
)
cd "$(dirname $0)"
port="$((10000 + (RANDOM % 10000)))"
tmpdir=$(mktemp -d /tmp/node_exporter_e2e_test.XXXXXX)
skip_re="^(go_|node_exporter_build_info|node_scrape_collector_duration_seconds|process_|node_textfile_mtime_seconds|node_time_(zone|seconds)|node_network_(receive|transmit)_(bytes|packets)_total)"
arch="$(uname -m)"
case "${arch}" in
aarch64|ppc64le) fixture='collector/fixtures/e2e-64k-page-output.txt' ;;
*) fixture='collector/fixtures/e2e-output.txt' ;;
esac
# Only test CPU info collection on x86_64.
case "${arch}" in
x86_64)
cpu_info_collector='--collector.cpu.info'
cpu_info_bugs='^(cpu_meltdown|spectre_.*|mds)$'
cpu_info_flags='^(aes|avx.?|constant_tsc)$'
;;
*)
cpu_info_collector='--no-collector.cpu.info'
cpu_info_bugs=''
cpu_info_flags=''
;;
esac
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
if [ ! -x ./node_exporter ]
then
echo './node_exporter not found. Consider running `go build` first.' >&2
exit 1
fi
./node_exporter \
--path.rootfs="collector/fixtures" \
--path.procfs="collector/fixtures/proc" \
--path.sysfs="collector/fixtures/sys" \
--path.udev.data="collector/fixtures/udev/data" \
$(for c in ${enabled_collectors}; do echo --collector.${c} ; done) \
$(for c in ${disabled_collectors}; do echo --no-collector.${c} ; done) \
--collector.textfile.directory="collector/fixtures/textfile/two_metric_files/" \
--collector.wifi.fixtures="collector/fixtures/wifi" \
--collector.qdisc.fixtures="collector/fixtures/qdisc/" \
--collector.qdisc.device-include="(wlan0|eth0)" \
--collector.arp.device-exclude="nope" \
--no-collector.arp.netlink \
--collector.hwmon.chip-include="(applesmc|coretemp|hwmon4|nct6779)" \
--collector.netclass.ignored-devices="(dmz|int)" \
--collector.netclass.ignore-invalid-speed \
--collector.netdev.device-include="lo" \
--collector.bcache.priorityStats \
"${cpu_info_collector}" \
--collector.cpu.info.bugs-include="${cpu_info_bugs}" \
--collector.cpu.info.flags-include="${cpu_info_flags}" \
--collector.stat.softirq \
--collector.sysctl.include="kernel.threads-max" \
--collector.sysctl.include="fs.file-nr" \
--collector.sysctl.include="fs.file-nr:total,current,max" \
--collector.sysctl.include-info="kernel.seccomp.actions_avail" \
--web.listen-address "127.0.0.1:${port}" \
--log.level="debug" > "${tmpdir}/node_exporter.log" 2>&1 &
echo $! > "${tmpdir}/node_exporter.pid"
finish() {
if [ $? -ne 0 -o ${verbose} -ne 0 ]
then
cat << EOF >&2
LOG =====================
$(cat "${tmpdir}/node_exporter.log")
=========================
EOF
fi
if [ ${update} -ne 0 ]
then
cp "${tmpdir}/e2e-output.txt" "${fixture}"
fi
if [ ${keep} -eq 0 ]
then
kill -9 "$(cat ${tmpdir}/node_exporter.pid)"
# This silences the "Killed" message
set +e
wait "$(cat ${tmpdir}/node_exporter.pid)" > /dev/null 2>&1
rm -rf "${tmpdir}"
fi
}
trap finish EXIT
get() {
if command -v curl > /dev/null 2>&1
then
curl -s -f "$@"
elif command -v wget > /dev/null 2>&1
then
wget -O - "$@"
else
echo "Neither curl nor wget found"
exit 1
fi
}
sleep 1
get "127.0.0.1:${port}/metrics" | grep -E -v "${skip_re}" > "${tmpdir}/e2e-output.txt"
diff -u \
"${fixture}" \
"${tmpdir}/e2e-output.txt"