Query Prometheus via curl

Ad-hoc PromQL query from CLI

curl -sG 'http://prometheus:9090/api/v1/query' --data-urlencode 'query=up' | jq .

tool
prometheus30 commands
tags
prometheusmonitoring

More prometheus commands

  • promtool query instant http://prometheus:9090 'up{job="kubelet"}'

    Run an instant PromQL query using promtool

  • curl -sG 'http://prometheus:9090/api/v1/query_range' --data-urlencode 'query=rate(http_requests_total[5m])' --data-urlencode 'start=2024-01-01T00:00:00Z' --data-urlencode 'end=2024-01-01T01:00:00Z' --data-urlencode 'step=60s' | jq .

    Query Prometheus for a time range via HTTP API

  • promtool check rules rules.yml

    Validate Prometheus alert/recording rule files for syntax

  • amtool silence add --alertmanager.url=http://alertmanager:9093 alertname=<name> --duration=2h --comment='Maintenance'

    Create a silence to mute alert notifications during maintenance

  • amtool silence query --alertmanager.url=http://alertmanager:9093

    Show all active silences in Alertmanager

all 30 prometheus commands