Chandan Kumar (raukadah) 489d13fc17 Use get_extra_file for downloading node_exporter/prometheus tarballs
DevStack provides get_extra_file[1] to download node_exporter/prometheus tarballs
and cache them in ci for further use.

Let's reuse the same instead of wget the binary.
This CR also adds cleanup phase under unstack step.

Links:
[1]. https://github.com/openstack/devstack/blob/master/functions#L50-L79

Closes-Bug: #2102666

Change-Id: I858eea3584794fdc10e45c9f80bfacdabdd537e2
Signed-off-by: Chandan Kumar (raukadah) <chkumar@redhat.com>
2025-03-25 11:18:30 +05:30

97 lines
3.2 KiB
Plaintext

# lib/node_exporter
# Functions to control the installation and configuration of node_exporter
# Save trace setting
_XTRACE_NODE_EXPORTER=$(set +o | grep xtrace)
set +o xtrace
NODE_EXPORTER_BINARY="/usr/local/bin/node_exporter"
NODE_EXPORTER_SYSTEMD_SERVICE="devstack@node-exporter.service"
NODE_EXPORTER_PORT=${NODE_EXPORTER_PORT:-9100}
function pre_install_node_exporter {
# Install OS packages
install_package wget tar
}
function install_node_exporter {
local ne_tarball=node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64.tar.gz
local ne_url=https://github.com/prometheus/node_exporter/releases/download/v${NODE_EXPORTER_VERSION}/${ne_tarball}
# Download node_exporter
local ne_dest
ne_dest=`get_extra_file ${ne_url}`
# Extract the tarball
tar xzf ${ne_dest} -C $DEST
# Move binaries to /usr/local/bin
sudo mv $DEST/node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64/node_exporter /usr/local/bin/
# Set ownership
sudo chown $(whoami):$(whoami) ${NODE_EXPORTER_BINARY}
}
function init_node_exporter {
node_exporter_cmd=${NODE_EXPORTER_BINARY}
node_exporter_cmd+=" --collector.systemd"
node_exporter_cmd+=" --collector.systemd.unit-include=(edpm_.*|ovs.*|openvswitch|virt.*|rsyslog)\.service"
node_exporter_cmd+=" --web.disable-exporter-metrics"
node_exporter_cmd+=" --no-collector.dmi --no-collector.entropy --no-collector.thermal_zone --no-collector.time"
node_exporter_cmd+=" --no-collector.timex --no-collector.uname --no-collector.stat --no-collector.hwmon"
node_exporter_cmd+=" --no-collector.os --no-collector.selinux --no-collector.textfile --no-collector.powersupplyclass"
node_exporter_cmd+=" --no-collector.pressure --no-collector.rapl"
if [[ $NODE_EXPORTER_COLLECTOR_EXCLUDE != "" ]]; then
collector_list=$(echo $NODE_EXPORTER_COLLECTOR_EXCLUDE | tr "," "\n")
for COLLECTOR in ${collector_list[@]}
do
node_exporter_cmd+=" --no-collector.${COLLECTOR}"
done
fi
write_user_unit_file $NODE_EXPORTER_SYSTEMD_SERVICE "$node_exporter_cmd" "" "$STACK_USER"
enable_service $NODE_EXPORTER_SYSTEMD_SERVICE
}
function start_node_exporter {
start_service $NODE_EXPORTER_SYSTEMD_SERVICE
}
function stop_node_exporter {
stop_service $NODE_EXPORTER_SYSTEMD_SERVICE
}
function cleanup_node_exporter {
stop_node_exporter
disable_service $NODE_EXPORTER_SYSTEMD_SERVICE
# Remove systemd unit files
local unitfile="$SYSTEMD_DIR/$NODE_EXPORTER_SYSTEMD_SERVICE"
sudo rm -f $unitfile
$SYSTEMCTL daemon-reload
# Remove Node Exporter binaries
sudo rm -rf $NODE_EXPORTER_BINARY
# Remove untar location
sudo rm -rf $DEST/node_exporter-${NODE_EXPORTER_VERSION}.linux-amd64
}
function wait_for_data {
# Adding sleep time so that metrics is pushed by node exporter
sleep 60
}
function check_data_node_exporter {
if curl -s --head --request GET "http://$HOST_IP:$NODE_EXPORTER_PORT/metrics" | grep "200 OK" > /dev/null; then
echo "#### Metrics data ####"
curl "http://$HOST_IP:$NODE_EXPORTER_PORT/metrics"
else
die $LINENO "Couldn't get data from node_exporter"
fi
}
# Restore xtrace
$_XTRACE_NODE_EXPORTER