mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-03 15:31:05 +01:00
6eafa51fa8
* Implement commonalities and linux support for ARP collection * Add ARP collector to fixtures and run as part of e2e tests * Bubble up scanner errors * Use single return values where it makes sense * Add missing annotation * Move arp_common into arp_linux * Add license header to arp_linux.go * Address initial feedback * Use strings.Fields instead of strings.Split * Deal with scanner.Err() rather than throwing away errors * Check for scan errors in-line before interacting with the entries map * Don't interact with potentially empty text from scan * Check for scan errors outside the scan loop * Add comment about moving procfs parsing * Add more direct comment * Update initialism style to match go style guide * Put function args on the same line * Add TODO in front of comment about procfs extraction * Guard against strings.Fields returning an empty slice * Be more defensive about ARP table format and use upcase more broadly * Enable the ARP collector by default * Add ARP collector to the README * Remove 'entry'
130 lines
2.4 KiB
Bash
Executable File
130 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euf -o pipefail
|
|
|
|
collectors=$(cat << COLLECTORS
|
|
arp
|
|
buddyinfo
|
|
conntrack
|
|
diskstats
|
|
drbd
|
|
edac
|
|
entropy
|
|
filefd
|
|
hwmon
|
|
infiniband
|
|
ksmd
|
|
loadavg
|
|
mdadm
|
|
meminfo
|
|
meminfo_numa
|
|
mountstats
|
|
netdev
|
|
netstat
|
|
nfs
|
|
sockstat
|
|
stat
|
|
textfile
|
|
bonding
|
|
megacli
|
|
wifi
|
|
zfs
|
|
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)"
|
|
|
|
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 \
|
|
-collector.procfs="collector/fixtures/proc" \
|
|
-collector.sysfs="collector/fixtures/sys" \
|
|
-collectors.enabled="$(echo ${collectors} | tr ' ' ',')" \
|
|
-collector.textfile.directory="collector/fixtures/textfile/two_metric_files/" \
|
|
-collector.megacli.command="collector/fixtures/megacli" \
|
|
-collector.wifi="collector/fixtures/wifi" \
|
|
-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" "collector/fixtures/e2e-output.txt"
|
|
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 \
|
|
"collector/fixtures/e2e-output.txt" \
|
|
"${tmpdir}/e2e-output.txt"
|