From 3e3de2bd709dc881678208c487b792ff3c8ab91e Mon Sep 17 00:00:00 2001 From: "Chandan Kumar (raukadah)" Date: Tue, 18 Feb 2025 13:15:43 +0530 Subject: [PATCH] Use prometheus api to get metrics names in check_data Currently check_data is using prometheus metrics to check where prometheus is working or not. Let's use prometheus HTTP API[1] to query the list of metrics. It will make sure, we are pushing data to the prometheus. Links: [1]. https://prometheus.io/docs/prometheus/latest/querying/api/ Change-Id: I9fd4e4aced915f8090afbf7e65f07aca8db64e3f Signed-off-by: Chandan Kumar (raukadah) --- devstack/lib/node_exporter | 2 +- devstack/lib/prometheus | 12 +++++++----- devstack/plugin.sh | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/devstack/lib/node_exporter b/devstack/lib/node_exporter index f84e179..d4ce1f4 100644 --- a/devstack/lib/node_exporter +++ b/devstack/lib/node_exporter @@ -68,7 +68,7 @@ function wait_for_data { # Adding sleep time so that metrics is pushed by node exporter sleep 60 } -function check_data { +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" diff --git a/devstack/lib/prometheus b/devstack/lib/prometheus index 86a7a1a..10b325a 100644 --- a/devstack/lib/prometheus +++ b/devstack/lib/prometheus @@ -11,7 +11,7 @@ PROMETHEUS_PORT=${PROMETHEUS_PORT:-9090} function pre_install_prometheus { # Install OS packages - install_package wget tar + install_package wget tar jq } function install_prometheus { @@ -94,10 +94,12 @@ function wait_for_data { sleep 60 } -function check_data { - if curl -s --head --request GET "http://$HOST_IP:$PROMETHEUS_PORT/metrics" | grep "200 OK" > /dev/null; then - echo "#### Metrics data ####" - curl "http://$HOST_IP:$PROMETHEUS_PORT/metrics" +function check_data_prometheus { + local url="http://$HOST_IP:$PROMETHEUS_PORT/api/v1/label/__name__/values" + + if curl -s --head --request GET "$url" | grep "200 OK" > /dev/null; then + echo "#### List of metrics names ####" + curl -s "$url" | jq -r '.data[]' else die $LINENO "Couldn't get data from prometheus" fi diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 4a464db..5377c50 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -36,7 +36,7 @@ if is_service_enabled prometheus; then start_prometheus echo_summary "Give time to prometheus to scrape data" wait_for_data - check_data + check_data_prometheus fi if [[ "$1" == "unstack" ]]; then @@ -80,7 +80,7 @@ if is_service_enabled node_exporter; then start_node_exporter echo_summary "Give time to node_exporter to push metrics" wait_for_data - check_data + check_data_node_exporter fi if [[ "$1" == "unstack" ]]; then