2015-09-26 11:54:49 -07:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2015-10-17 03:31:51 -07:00
|
|
|
set -euf -o pipefail
|
2015-09-26 11:54:49 -07:00
|
|
|
|
2017-09-28 06:06:26 -07:00
|
|
|
enabled_collectors=$(cat << COLLECTORS
|
2017-04-11 08:45:19 -07:00
|
|
|
arp
|
Add bcache collector (#597)
* Add bcache collector for Linux
This collector gathers metrics related to the Linux block cache
(bcache) from sysfs.
* Removed commented out code
* Use project comment style
* Add _sectors to metric name to indicate unit
* Really use project comment style
* Rename bcache.go to bcache_linux.go
* Keep collector namespace clean
Rename:
- metric -> bcacheMetric
- periodStatsToMetrics -> bcachePeriodStatsToMetric
* Shorten slice initialization
* Change label names to backing_device, cache_device
* Remove five minute metrics (keep only total)
* Include units in additional metric names
* Enable bcache collector by default
* Provide metrics in seconds, not nanoseconds
* remove metrics with label "all"
* Add fixtures, update end-to-end for bcache collector
* Move fixtures/sys into tar.gz
This changeset moves the collector/fixtures/sys directory into
collector/fixtures/sys.tar.gz and tweaks the Makefile to unpack the
tarball before tests are run.
The reason for this change is that Windows does not allow colons in a
path (colons are present in some of the bcache fixture files), nor can
it (out of the box) deal with pathnames longer than 260 characters
(which we would be increasingly likely to hit if we tried to replace
colons with longer codes that are guaranteed not the turn up in regular
file names).
* Add ttar: plain text archive, replacement for tar
This changeset adds ttar, a plain text replacement for tar, and uses it
for the sysfs fixture archive. The syntax is loosely based on tar(1).
Using a plain text archive makes it possible to review changes without
downloading and extracting the archive. Also, when working on the repo,
git diff and git log become useful again, allowing a committer to verify
and track changes over time.
The code is written in bash, because bash is available out of the box on
all major flavors of Linux and on macOS. The feature set used is
restricted to bash version 3.2 because that is what Apple is still
shipping.
The programm also works on Windows if bash is installed. Obviously, it
does not solve the Windows limitations (path length limited to 260
characters, no symbolic links) that prompted the move to an archive
format in the first place.
2017-07-06 22:20:18 -07:00
|
|
|
bcache
|
2017-02-07 07:11:22 -08:00
|
|
|
buddyinfo
|
2016-01-14 01:51:11 -08:00
|
|
|
conntrack
|
2017-06-13 02:21:53 -07:00
|
|
|
cpu
|
2016-01-14 01:51:11 -08:00
|
|
|
diskstats
|
2016-12-05 02:37:35 -08:00
|
|
|
drbd
|
2017-01-08 03:58:04 -08:00
|
|
|
edac
|
2016-01-14 01:51:11 -08:00
|
|
|
entropy
|
|
|
|
filefd
|
2016-10-06 08:33:24 -07:00
|
|
|
hwmon
|
2017-02-07 08:46:51 -08:00
|
|
|
infiniband
|
2017-11-02 01:59:46 -07:00
|
|
|
interrupts
|
2017-07-26 06:20:28 -07:00
|
|
|
ipvs
|
2015-11-11 05:02:41 -08:00
|
|
|
ksmd
|
2016-01-14 01:51:11 -08:00
|
|
|
loadavg
|
|
|
|
mdadm
|
|
|
|
meminfo
|
2015-11-13 01:23:21 -08:00
|
|
|
meminfo_numa
|
2016-12-12 13:46:45 -08:00
|
|
|
mountstats
|
2016-01-14 01:51:11 -08:00
|
|
|
netdev
|
|
|
|
netstat
|
2016-11-29 05:32:52 -08:00
|
|
|
nfs
|
2018-02-12 08:56:05 -08:00
|
|
|
nfsd
|
2017-05-23 02:55:50 -07:00
|
|
|
qdisc
|
2016-01-14 01:51:11 -08:00
|
|
|
sockstat
|
|
|
|
stat
|
|
|
|
textfile
|
|
|
|
bonding
|
2018-03-29 08:34:52 -07:00
|
|
|
vmstat
|
2017-01-09 11:37:59 -08:00
|
|
|
wifi
|
2017-04-21 15:19:35 -07:00
|
|
|
xfs
|
2017-01-08 08:17:06 -08:00
|
|
|
zfs
|
2016-01-14 01:51:11 -08:00
|
|
|
COLLECTORS
|
|
|
|
)
|
2017-09-28 06:06:26 -07:00
|
|
|
disabled_collectors=$(cat << COLLECTORS
|
|
|
|
filesystem
|
|
|
|
time
|
|
|
|
timex
|
|
|
|
uname
|
|
|
|
COLLECTORS
|
|
|
|
)
|
2015-09-26 11:54:49 -07:00
|
|
|
cd "$(dirname $0)"
|
|
|
|
|
|
|
|
port="$((10000 + (RANDOM % 10000)))"
|
|
|
|
tmpdir=$(mktemp -d /tmp/node_exporter_e2e_test.XXXXXX)
|
|
|
|
|
2018-01-22 05:02:19 -08:00
|
|
|
skip_re="^(go_|node_exporter_build_info|node_scrape_collector_duration_seconds|process_|node_textfile_mtime_seconds)"
|
2015-09-26 11:54:49 -07:00
|
|
|
|
2018-01-11 04:56:19 -08:00
|
|
|
arch="$(uname -m)"
|
|
|
|
|
|
|
|
case "${arch}" in
|
2018-05-14 06:55:49 -07:00
|
|
|
aarch64|ppc64le) fixture='collector/fixtures/e2e-64k-page-output.txt' ;;
|
2018-01-11 04:56:19 -08:00
|
|
|
*) fixture='collector/fixtures/e2e-output.txt' ;;
|
|
|
|
esac
|
|
|
|
|
2015-09-26 11:54:49 -07: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 12:39:12 -07:00
|
|
|
if [ ! -x ./node_exporter ]
|
|
|
|
then
|
|
|
|
echo './node_exporter not found. Consider running `go build` first.' >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-09-26 11:54:49 -07:00
|
|
|
|
|
|
|
./node_exporter \
|
2017-09-28 06:06:26 -07:00
|
|
|
--path.procfs="collector/fixtures/proc" \
|
|
|
|
--path.sysfs="collector/fixtures/sys" \
|
|
|
|
$(for c in ${enabled_collectors}; do echo --collector.${c} ; done) \
|
|
|
|
$(for c in ${disabled_collectors}; do echo --no-collector.${c} ; done) \
|
2017-08-12 06:07:24 -07:00
|
|
|
--collector.textfile.directory="collector/fixtures/textfile/two_metric_files/" \
|
2017-09-28 06:06:26 -07:00
|
|
|
--collector.wifi.fixtures="collector/fixtures/wifi" \
|
|
|
|
--collector.qdisc.fixtures="collector/fixtures/qdisc/" \
|
2017-08-12 06:07:24 -07:00
|
|
|
--web.listen-address "127.0.0.1:${port}" \
|
|
|
|
--log.level="debug" > "${tmpdir}/node_exporter.log" 2>&1 &
|
2015-09-26 11:54:49 -07:00
|
|
|
|
|
|
|
echo $! > "${tmpdir}/node_exporter.pid"
|
|
|
|
|
|
|
|
finish() {
|
2016-12-21 02:51:53 -08:00
|
|
|
if [ $? -ne 0 -o ${verbose} -ne 0 ]
|
2015-09-26 11:54:49 -07:00
|
|
|
then
|
2016-12-21 02:51:53 -08:00
|
|
|
cat << EOF >&2
|
|
|
|
LOG =====================
|
|
|
|
$(cat "${tmpdir}/node_exporter.log")
|
|
|
|
=========================
|
|
|
|
EOF
|
2015-09-26 11:54:49 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${update} -ne 0 ]
|
|
|
|
then
|
2018-01-11 04:56:19 -08:00
|
|
|
cp "${tmpdir}/e2e-output.txt" "${fixture}"
|
2015-09-26 11:54:49 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ${keep} -eq 0 ]
|
|
|
|
then
|
|
|
|
kill -9 "$(cat ${tmpdir}/node_exporter.pid)"
|
|
|
|
# This silences the "Killed" message
|
2015-10-16 12:39:12 -07:00
|
|
|
set +e
|
2015-09-26 11:54:49 -07:00
|
|
|
wait "$(cat ${tmpdir}/node_exporter.pid)" > /dev/null 2>&1
|
|
|
|
rm -rf "${tmpdir}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
trap finish EXIT
|
|
|
|
|
|
|
|
get() {
|
2016-12-21 10:00:38 -08:00
|
|
|
if command -v curl > /dev/null 2>&1
|
2015-09-26 11:54:49 -07:00
|
|
|
then
|
|
|
|
curl -s -f "$@"
|
2016-12-21 10:00:38 -08:00
|
|
|
elif command -v wget > /dev/null 2>&1
|
2015-09-26 11:54:49 -07:00
|
|
|
then
|
|
|
|
wget -O - "$@"
|
|
|
|
else
|
|
|
|
echo "Neither curl nor wget found"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
sleep 1
|
|
|
|
|
2017-01-06 03:36:26 -08:00
|
|
|
get "127.0.0.1:${port}/metrics" | grep -E -v "${skip_re}" > "${tmpdir}/e2e-output.txt"
|
2015-09-26 11:54:49 -07:00
|
|
|
|
|
|
|
diff -u \
|
2018-01-11 04:56:19 -08:00
|
|
|
"${fixture}" \
|
2018-03-29 08:34:52 -07:00
|
|
|
"${tmpdir}/e2e-output.txt"
|