Created
May 21, 2023 19:57
-
-
Save Lucho00Cuba/70b3dfac87bb59e8595ac2d39a9c4054 to your computer and use it in GitHub Desktop.
Prometheus API cURL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
PROTOCOL="http" | |
PROMETHEUS="192.168.1.203:9090" | |
OPTIONS="-sL" | |
query_http(){ | |
name=$1; request=$2; args=$3 | |
echo $name | |
echo "Requests: curl $OPTIONS -G $request $args 2>/dev/null" | |
sh -c "curl $OPTIONS -G $request $args 2>/dev/null" | jq | |
} | |
query_http "[*] GET JOBS" "$PROTOCOL://$PROMETHEUS/api/v1/label/job/values" | |
query_http "[*] GET LABELS" "$PROTOCOL://$PROMETHEUS/api/v1/labels" | |
job_name="pve" | |
query_http "[*] GET METRICS FOR JOB" "$PROTOCOL://$PROMETHEUS/api/v1/label/__name__/values" "--data-urlencode 'match[]={job=\"$job_name\"}'" | |
metric_a="pve_node_info" | |
metric_b="pve_version_info" | |
query_http "[*] MULTI-METRIC" "$PROTOCOL://$PROMETHEUS/api/v1/series?" "--data-urlencode 'match[]=$metric_a' --data-urlencode 'match[]=$metric_b'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment