# 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 { if curl -s --head --request GET "http://$SERVICE_HOST:$OPENSTACK_EXPORTER_PORT/metrics" | grep "200 OK" > /dev/null; then echo "#### Metrics data ####" curl "http://$SERVICE_HOST:$OPENSTACK_EXPORTER_PORT/metrics" else die $LINENO "Couldn't get data from openstack_exporter" fi } # Restore xtrace $_XTRACE_OPENSTACK_EXPORTER