mirror of
https://github.com/prometheus/node_exporter.git
synced 2024-12-22 08:26:07 +01:00
c4102f1175
* add sys/class/net parsing from procfs and expose its metrics Signed-off-by: Jan Klat <jenik@klatys.cz> * change code to use int pointers per procfs change, move netclass to separate collector, change metric naming Signed-off-by: Jan Klat <jenik@klatys.cz> * bump year in licence, remove redundant newline, correct fixtures Signed-off-by: Jan Klat <jenik@klatys.cz> * fix style Signed-off-by: Jan Klat <jenik@klatys.cz> * change carrier changes to counter type Signed-off-by: Jan Klat <jenik@klatys.cz> * fix e2e output Signed-off-by: Jan Klat <jenik@klatys.cz> * add fixtures Signed-off-by: Jan Klat <jenik@klatys.cz> * update vendor, use fixtures correctly Signed-off-by: Jan Klat <jenik@klatys.cz> * change fixtures (device in /sys/class/net should be symlinked) Signed-off-by: Jan Klat <jenik@klatys.cz> * correct fixtures for 64k page, updated readme Signed-off-by: Jan Klat <jenik@klatys.cz>
154 lines
2.9 KiB
Bash
Executable File
154 lines
2.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -euf -o pipefail
|
|
|
|
enabled_collectors=$(cat << COLLECTORS
|
|
arp
|
|
bcache
|
|
buddyinfo
|
|
conntrack
|
|
cpu
|
|
diskstats
|
|
drbd
|
|
edac
|
|
entropy
|
|
filefd
|
|
hwmon
|
|
infiniband
|
|
interrupts
|
|
ipvs
|
|
ksmd
|
|
loadavg
|
|
mdadm
|
|
meminfo
|
|
meminfo_numa
|
|
mountstats
|
|
netdev
|
|
netstat
|
|
nfs
|
|
nfsd
|
|
qdisc
|
|
sockstat
|
|
stat
|
|
textfile
|
|
bonding
|
|
vmstat
|
|
wifi
|
|
xfs
|
|
zfs
|
|
processes
|
|
COLLECTORS
|
|
)
|
|
disabled_collectors=$(cat << COLLECTORS
|
|
filesystem
|
|
time
|
|
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)"
|
|
|
|
arch="$(uname -m)"
|
|
|
|
case "${arch}" in
|
|
aarch64|ppc64le) fixture='collector/fixtures/e2e-64k-page-output.txt' ;;
|
|
*) fixture='collector/fixtures/e2e-output.txt' ;;
|
|
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.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) \
|
|
--collector.textfile.directory="collector/fixtures/textfile/two_metric_files/" \
|
|
--collector.wifi.fixtures="collector/fixtures/wifi" \
|
|
--collector.qdisc.fixtures="collector/fixtures/qdisc/" \
|
|
--collector.netclass.ignored-devices="(bond0|dmz|int)" \
|
|
--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"
|