2015-09-26 18:54:49 +00:00
#!/usr/bin/env bash
2015-10-17 10:31:51 +00:00
set -euf -o pipefail
2015-09-26 18:54:49 +00:00
2024-10-19 18:34:34 +00:00
# Allow setting GOHOSTOS for debugging purposes.
GOHOSTOS = ${ GOHOSTOS :- $( go env GOHOSTOS) }
# Allow setting arch for debugging purposes.
arch = ${ arch :- $( uname -m) }
maybe_flag_search_scope( ) {
local collector = $1
os_aux_os = ""
if [ [ $GOHOSTOS = ~ ^( freebsd| openbsd| netbsd| solaris| dragonfly) $ ] ] ; then
os_aux_os = " ${ collector } _bsd.go "
fi
echo " ${ collector } _common.go ${ collector } .go ${ collector } _ ${ GOHOSTOS } .go ${ collector } _ ${ GOHOSTOS } _ ${ arch } .go ${ os_aux_os } "
}
supported_collectors( ) {
local collectors = $1
local supported = ""
for collector in ${ collectors } ; do
for filename in $( maybe_flag_search_scope " ${ collector } " ) ; do
file = " collector/ ${ filename } "
if ./tools/tools match ${ file } > /dev/null 2>& 1; then
if grep -h -E -o -- "registerCollector\(" ${ file } > /dev/null 2>& 1; then
supported = " ${ supported } ${ collector } "
fi
break
fi
done
done
echo " ${ supported } " | tr ' ' '\n' | sort | uniq
}
2017-09-28 13:06:26 +00:00
enabled_collectors = $( cat << COLLEC TORS
2017-04-11 15:45:19 +00: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-07 05:20:18 +00:00
bcache
2022-07-25 14:32:43 +00:00
bonding
2020-02-19 14:48:51 +00:00
btrfs
2017-02-07 15:11:22 +00:00
buddyinfo
2022-06-24 15:15:31 +00:00
cgroups
2022-07-25 14:32:43 +00:00
conntrack
2017-06-13 09:21:53 +00:00
cpu
2019-02-19 16:22:54 +00:00
cpufreq
2023-07-01 12:21:49 +00:00
cpu_vulnerabilities
2016-01-14 09:51:11 +00:00
diskstats
2021-12-01 10:13:43 +00:00
dmi
2016-12-05 10:37:35 +00:00
drbd
2017-01-08 11:58:04 +00:00
edac
2016-01-14 09:51:11 +00:00
entropy
2020-07-13 13:30:19 +00:00
fibrechannel
2016-01-14 09:51:11 +00:00
filefd
2016-10-06 15:33:24 +00:00
hwmon
2017-02-07 16:46:51 +00:00
infiniband
2017-11-02 08:59:46 +00:00
interrupts
2017-07-26 13:20:28 +00:00
ipvs
2015-11-11 13:02:41 +00:00
ksmd
2021-09-28 08:24:18 +00:00
lnstat
2016-01-14 09:51:11 +00:00
loadavg
mdadm
meminfo
2015-11-13 09:23:21 +00:00
meminfo_numa
2016-12-12 21:46:45 +00:00
mountstats
2016-01-14 09:51:11 +00:00
netdev
netstat
2016-11-29 13:32:52 +00:00
nfs
2018-02-12 16:56:05 +00:00
nfsd
2019-04-18 10:19:20 +00:00
pressure
2022-07-25 14:32:43 +00:00
processes
2017-05-23 09:55:50 +00:00
qdisc
2020-01-17 12:32:16 +00:00
rapl
2019-07-10 07:16:24 +00:00
schedstat
2022-05-13 07:19:19 +00:00
slabinfo
2016-01-14 09:51:11 +00:00
sockstat
2023-05-25 13:09:32 +00:00
softirqs
2016-01-14 09:51:11 +00:00
stat
2022-07-14 16:51:55 +00:00
sysctl
2016-01-14 09:51:11 +00:00
textfile
2022-07-25 14:32:43 +00:00
thermal_zone
2022-06-16 09:05:02 +00:00
udp_queues
2018-03-29 15:34:52 +00:00
vmstat
2024-03-09 09:00:06 +00:00
watchdog
2017-01-09 19:37:59 +00:00
wifi
2023-12-03 16:10:59 +00:00
xfrm
2017-04-21 22:19:35 +00:00
xfs
2017-01-08 16:17:06 +00:00
zfs
2020-12-23 12:49:21 +00:00
zoneinfo
2016-01-14 09:51:11 +00:00
COLLECTORS
)
2024-10-19 18:34:34 +00:00
supported_enabled_collectors = $( supported_collectors " ${ enabled_collectors } " )
2017-09-28 13:06:26 +00:00
disabled_collectors = $( cat << COLLEC TORS
2024-03-08 14:06:03 +00:00
selinux
2017-09-28 13:06:26 +00:00
filesystem
timex
uname
COLLECTORS
)
2024-10-19 18:34:34 +00:00
supported_disabled_collectors = $( supported_collectors " ${ disabled_collectors } " )
2015-09-26 18:54:49 +00:00
cd " $( dirname $0 ) "
port = " $(( 10000 + ( RANDOM % 10000 )) ) "
tmpdir = $( mktemp -d /tmp/node_exporter_e2e_test.XXXXXX)
2021-07-20 11:47:08 +00:00
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)"
2015-09-26 18:54:49 +00:00
2018-01-11 12:56:19 +00:00
case " ${ arch } " in
2024-10-19 18:34:34 +00:00
aarch64| ppc64le) fixture_metrics = 'collector/fixtures/e2e-64k-page-output.txt' ; ;
*) fixture_metrics = 'collector/fixtures/e2e-output.txt' ; ;
2018-01-11 12:56:19 +00:00
esac
2022-06-26 07:41:21 +00:00
# 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
2015-09-26 18:54:49 +00: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"
2024-10-19 18:34:34 +00:00
echo " -u: update fixture_metrics"
2015-09-26 18:54:49 +00:00
echo " -v: verbose output"
exit 1
; ;
esac
done
2015-10-16 19:39:12 +00:00
if [ ! -x ./node_exporter ]
then
echo './node_exporter not found. Consider running `go build` first.' >& 2
exit 1
fi
2015-09-26 18:54:49 +00:00
2024-10-19 18:34:34 +00:00
collector_flags = $( cat << FLAGS
${ cpu_info_collector }
--collector.arp.device-exclude= nope
--collector.bcache.priorityStats
--collector.cpu.info.bugs-include= ${ cpu_info_bugs }
--collector.cpu.info.flags-include= ${ cpu_info_flags }
--collector.hwmon.chip-include= ( applesmc| coretemp| hwmon4| nct6779)
--collector.netclass.ignore-invalid-speed
--collector.netclass.ignored-devices= ( dmz| int)
--collector.netdev.device-include= lo
--collector.qdisc.device-include= ( wlan0| eth0)
--collector.qdisc.fixtures= collector/fixtures/qdisc/
--collector.stat.softirq
--collector.sysctl.include-info= kernel.seccomp.actions_avail
--collector.sysctl.include= fs.file-nr
--collector.sysctl.include= fs.file-nr:total,current,max
--collector.sysctl.include= kernel.threads-max
--collector.textfile.directory= collector/fixtures/textfile/two_metric_files/
--collector.wifi.fixtures= collector/fixtures/wifi
--no-collector.arp.netlink
FLAGS
)
# Handle supported --[no-]collector.<name> flags. These are not hardcoded.
_filtered_collector_flags = ""
for flag in ${ collector_flags } ; do
collector = $( echo " ${ flag } " | cut -d"." -f2)
# If the flag is associated with an enabled-by-default collector, include it.
enabled_by_default = 0
for filename in $( maybe_flag_search_scope " ${ collector } " ) ; do
file = " collector/ ${ filename } "
if grep -h -E -o -- "registerCollector\(.*, defaultEnabled" ${ file } > /dev/null 2>& 1; then
_filtered_collector_flags = " ${ _filtered_collector_flags } ${ flag } "
enabled_by_default = 1
break
fi
done
if [ ${ enabled_by_default } -eq 1 ] ; then
continue
fi
# If the flag is associated with an enabled-list collector, include it.
if echo " ${ supported_enabled_collectors } ${ supported_disabled_collectors } " | grep -q -w " ${ collector } " ; then
_filtered_collector_flags = " ${ _filtered_collector_flags } ${ flag } "
fi
done
# Handle supported --[no-]collector.<name>.<collector> flags. These are hardcoded and matched by the expression below.
filtered_collector_flags = ""
# Check flags of all supported collectors further down their sub-collectors (beyond the 2nd ".").
for flag in ${ _filtered_collector_flags } ; do
# Iterate through all possible files where the flag may be defined.
flag_collector = " $( echo " ${ flag } " | cut -d"." -f2) "
for filename in $( maybe_flag_search_scope " ${ flag_collector } " ) ; do
file = " collector/ ${ filename } "
# Move to next iteration if the current file is not included under the build context.
if ! ./tools/tools match " $file " > /dev/null 2>& 1; then
continue
fi
# Flag has the format: --[no-]collector.<name>.<collector>.
if [ -n " $( echo ${ flag } | cut -d"." -f3) " ] ; then
# Check if the flag is used in the file.
trimmed_flag = $( echo " ${ flag } " | tr -d "\"' " | cut -d"=" -f1 | cut -c 3-)
if [ [ $trimmed_flag = ~ ^no- ] ] ; then
trimmed_flag = $( echo $trimmed_flag | cut -c 4-)
fi
if grep -h -E -o -- " kingpin.Flag\(\" ${ trimmed_flag } " ${ file } > /dev/null 2>& 1; then
filtered_collector_flags = " ${ filtered_collector_flags } ${ flag } "
else
continue
fi
# Flag has the format: --[no-]collector.<name>.
else
# Flag is supported by the host.
filtered_collector_flags = " ${ filtered_collector_flags } ${ flag } "
fi
done
done
# Check for ignored flags.
ignored_flags = ""
for flag in ${ collector_flags } ; do
flag = $( echo " ${ flag } " | tr -d " " )
if ! echo " ${ filtered_collector_flags } " | grep -q -F -- " ${ flag } " > /dev/null 2>& 1; then
ignored_flags = " ${ ignored_flags } ${ flag } "
fi
done
echo "ENABLED COLLECTORS======="
echo " ${ supported_enabled_collectors : 1 } " | tr ' ' '\n' | sort
echo "========================="
echo "DISABLED COLLECTORS======"
echo " ${ supported_disabled_collectors : 1 } " | tr ' ' '\n' | sort
echo "========================="
echo "IGNORED FLAGS============"
echo " ${ ignored_flags : 1 } " | tr ' ' '\n' | sort | uniq
echo "========================="
2015-09-26 18:54:49 +00:00
./node_exporter \
2021-08-19 10:26:53 +00:00
--path.rootfs= "collector/fixtures" \
2017-09-28 13:06:26 +00:00
--path.procfs= "collector/fixtures/proc" \
--path.sysfs= "collector/fixtures/sys" \
2022-06-16 09:05:02 +00:00
--path.udev.data= "collector/fixtures/udev/data" \
2024-10-19 18:34:34 +00:00
$( for c in ${ supported_enabled_collectors } ; do echo --collector.${ c } ; done ) \
$( for c in ${ supported_disabled_collectors } ; do echo --no-collector.${ c } ; done ) \
${ filtered_collector_flags } \
2017-08-12 13:07:24 +00:00
--web.listen-address " 127.0.0.1: ${ port } " \
--log.level= "debug" > " ${ tmpdir } /node_exporter.log " 2>& 1 &
2015-09-26 18:54:49 +00:00
echo $! > " ${ tmpdir } /node_exporter.pid "
2024-10-19 18:34:34 +00:00
generated_metrics = " ${ tmpdir } /e2e-output.txt "
2024-12-21 05:02:22 +00:00
for os in freebsd openbsd netbsd solaris dragonfly darwin; do
2024-10-19 18:34:34 +00:00
if [ " ${ GOHOSTOS } " = " ${ os } " ] ; then
generated_metrics = " ${ tmpdir } /e2e-output- ${ GOHOSTOS } .txt "
fixture_metrics = " ${ fixture_metrics : :- 4 } - ${ GOHOSTOS } .txt "
fi
done
2015-09-26 18:54:49 +00:00
finish( ) {
2016-12-21 10:51:53 +00:00
if [ $? -ne 0 -o ${ verbose } -ne 0 ]
2015-09-26 18:54:49 +00:00
then
2016-12-21 10:51:53 +00:00
cat << EOF >& 2
LOG = = = = = = = = = = = = = = = = = = = = =
$( cat " ${ tmpdir } /node_exporter.log " )
= = = = = = = = = = = = = = = = = = = = = = = = =
EOF
2015-09-26 18:54:49 +00:00
fi
if [ ${ update } -ne 0 ]
then
2024-10-19 18:34:34 +00:00
cp " ${ generated_metrics } " " ${ fixture_metrics } "
2015-09-26 18:54:49 +00:00
fi
if [ ${ keep } -eq 0 ]
then
kill -9 " $( cat ${ tmpdir } /node_exporter.pid) "
# This silences the "Killed" message
2015-10-16 19:39:12 +00:00
set +e
2015-09-26 18:54:49 +00:00
wait " $( cat ${ tmpdir } /node_exporter.pid) " > /dev/null 2>& 1
rm -rf " ${ tmpdir } "
fi
}
trap finish EXIT
get( ) {
2016-12-21 18:00:38 +00:00
if command -v curl > /dev/null 2>& 1
2015-09-26 18:54:49 +00:00
then
curl -s -f " $@ "
2016-12-21 18:00:38 +00:00
elif command -v wget > /dev/null 2>& 1
2015-09-26 18:54:49 +00:00
then
wget -O - " $@ "
else
echo "Neither curl nor wget found"
exit 1
fi
}
sleep 1
2024-10-19 18:34:34 +00:00
get " 127.0.0.1: ${ port } /metrics " | grep --text -E -v " ${ skip_re } " > " ${ generated_metrics } "
2025-02-15 08:31:59 +00:00
# The following ignore-list is only applicable to the VMs used to run E2E tests on platforms for which containerized environments are not available.
# However, owing to this, there are some non-deterministic metrics that end up generating samples, unlike their containerized counterparts, for e.g., node_network_receive_bytes_total.
2024-10-19 18:34:34 +00:00
non_deterministic_metrics = $( cat << METRICS
node_boot_time_seconds
2024-12-21 05:02:22 +00:00
node_cpu_frequency_hertz
2024-10-19 18:34:34 +00:00
node_cpu_seconds_total
2024-12-21 05:02:22 +00:00
node_disk_io_time_seconds_total
node_disk_read_bytes_total
node_disk_read_sectors_total
node_disk_read_time_seconds_total
node_disk_reads_completed_total
node_disk_write_time_seconds_total
node_disk_writes_completed_total
node_disk_written_bytes_total
node_disk_written_sectors_total
2024-10-19 18:34:34 +00:00
node_exec_context_switches_total
node_exec_device_interrupts_total
node_exec_forks_total
2024-12-21 05:02:22 +00:00
node_exec_software_interrupts_total
2024-10-19 18:34:34 +00:00
node_exec_system_calls_total
node_exec_traps_total
2024-12-21 05:02:22 +00:00
node_interrupts_total
2024-10-19 18:34:34 +00:00
node_load1
node_load15
node_load5
node_memory_active_bytes
node_memory_buffer_bytes
2024-12-21 05:02:22 +00:00
node_memory_cache_bytes
node_memory_compressed_bytes
2024-10-19 18:34:34 +00:00
node_memory_free_bytes
node_memory_inactive_bytes
2024-12-21 05:02:22 +00:00
node_memory_internal_bytes
2024-10-19 18:34:34 +00:00
node_memory_laundry_bytes
2024-12-21 05:02:22 +00:00
node_memory_purgeable_bytes
node_memory_size_bytes
node_memory_swapped_in_bytes_total
node_memory_swapped_out_bytes_total
2024-10-19 18:34:34 +00:00
node_memory_wired_bytes
2025-02-15 08:31:59 +00:00
node_netstat_tcp_receive_packets_total
node_netstat_tcp_transmit_packets_total
node_network_receive_bytes_total
2024-12-21 05:02:22 +00:00
node_network_receive_multicast_total
node_network_transmit_multicast_total
2024-10-19 18:34:34 +00:00
METRICS
)
# Remove non-deterministic metrics from the generated metrics file (as we run their workflows in VMs).
2024-12-21 05:02:22 +00:00
for os in freebsd openbsd netbsd solaris dragonfly darwin; do
2024-10-19 18:34:34 +00:00
if [ " ${ GOHOSTOS } " = " ${ os } " ] ; then
for metric in ${ non_deterministic_metrics } ; do
sed -i " / ${ metric } /d " " ${ generated_metrics } "
done
fi
done
2015-09-26 18:54:49 +00:00
diff -u \
2024-10-19 18:34:34 +00:00
" ${ fixture_metrics } " \
" ${ generated_metrics } "