Files
devstack-plugin-prometheus/devstack/lib/openstack_exporter
Douglas Viroel 428b9050c1 Fix exporter URL to support multinode deployments
A previous change (cf2d127) set SERVICE_HOST for constructing
exporter URLs, but SERVICE_HOST references to the controller
node IP. This breaks multinode deployments where exporters are
running on subnodes, as the health checks would try to reach the
controller instead of the local node.

This change properly checks SERVICE_IP_VERSION and uses HOST_IPV6
for IPv6 environments or HOST_IP for IPv4, ensuring the URL points
to the correct node where the exporter is actually running.

Additionally, IPv6 addresses are wrapped in square brackets as
required for URLs (e.g., http://[2001:db8::1]:9100/metrics).

A common get_host_ip_for_url function is introduced in lib/common
to centralize IP version handling and avoid code duplication across
all exporter modules.

Assisted-By: Claude (claude-sonnet-4-5)

Closes-Bug: #2141918
Change-Id: Icff76c7dc52d6444aa1c049dd6eada27016f4166
Signed-off-by: Douglas Viroel <viroel@gmail.com>
2026-03-04 13:42:43 -03:00

89 lines
2.6 KiB
Plaintext

# lib/openstack_exporter
# Functions to control the installation and configuration of openstack_exporter
# Save trace setting
_XTRACE_OPENSTACK_EXPORTER=$(set +o | grep xtrace)
set +o xtrace
OPENSTACK_EXPORTER_BINARY="/usr/local/bin/openstack_exporter"
OPENSTACK_EXPORTER_SYSTEMD_SERVICE="devstack@openstack-exporter.service"
OPENSTACK_EXPORTER_PORT=${OPENSTACK_EXPORTER_PORT:-9180}
function pre_install_openstack_exporter {
# Install OS packages
install_package wget tar
}
function install_openstack_exporter {
local oe_tarball=openstack-exporter_${OPENSTACK_EXPORTER_VERSION}_linux_amd64.tar.gz
local oe_url=https://github.com/openstack-exporter/openstack-exporter/releases/download/v${OPENSTACK_EXPORTER_VERSION}/${oe_tarball}
# Download openstack_exporter
local oe_dest
oe_dest=`get_extra_file ${oe_url}`
# Extract the tarball
tar xzf ${oe_dest} -C $DEST
# Move binaries to /usr/local/bin
sudo mv $DEST/openstack-exporter ${OPENSTACK_EXPORTER_BINARY}
# Set ownership
sudo chown $(whoami):$(whoami) ${OPENSTACK_EXPORTER_BINARY}
}
function init_openstack_exporter {
export OS_COMPUTE_API_VERSION=2.87
openstack_exporter_cmd=${OPENSTACK_EXPORTER_BINARY}
openstack_exporter_cmd+=" --os-client-config /etc/openstack/clouds.yaml devstack-admin"
write_user_unit_file $OPENSTACK_EXPORTER_SYSTEMD_SERVICE "$openstack_exporter_cmd" "" "$STACK_USER" "OS_COMPUTE_API_VERSION=2.1"
enable_service $OPENSTACK_EXPORTER_SYSTEMD_SERVICE
}
function start_openstack_exporter {
start_service $OPENSTACK_EXPORTER_SYSTEMD_SERVICE
}
function stop_openstack_exporter {
stop_service $OPENSTACK_EXPORTER_SYSTEMD_SERVICE
}
function cleanup_openstack_exporter {
stop_openstack_exporter
disable_service $OPENSTACK_EXPORTER_SYSTEMD_SERVICE
# Remove systemd unit files
local unitfile="$SYSTEMD_DIR/$OPENSTACK_EXPORTER_SYSTEMD_SERVICE"
sudo rm -f $unitfile
$SYSTEMCTL daemon-reload
# Remove OpenStack Exporter binaries
sudo rm -rf $OPENSTACK_EXPORTER_BINARY
# Remove untar location
sudo rm -rf $DEST/openstack-exporter
}
function wait_for_data {
# Adding sleep time so that metrics is pushed by openstack exporter
sleep 60
}
function check_data_openstack_exporter {
local host_ip
host_ip=$(get_host_ip_for_url)
if curl -s --head --request GET "http://$host_ip:$OPENSTACK_EXPORTER_PORT/metrics" | grep "200 OK" > /dev/null; then
echo "#### Metrics data ####"
curl "http://$host_ip:$OPENSTACK_EXPORTER_PORT/metrics"
else
die $LINENO "Couldn't get data from openstack_exporter"
fi
}
# Restore xtrace
$_XTRACE_OPENSTACK_EXPORTER