简体   繁体   中英

Prometheus curl API query issue

I am trying to construct curl API query to get Json data from Prometheus. The working in Prometheus UI query looks like:

max_over_time(container_memory_usage_bytes{image!="",pod_name=~"somepod-.*"}[7d])

So I am trying with:

curl 'http://127.0.0.1:20001/api/v1/query?query=max_over_time(container_memory_usage_bytes{(pod_name="somepod-.*")})[1d]' | jq

But depending on brackets it always complaining about something like expected or unexpected character.

You want:

curl -g 'http://127.0.0.1:20001/api/v1/query?query=max_over_time(container_memory_usage_bytes{pod_name=~"somepod-.*"}[1d])' | jq

This disables curl's globbing, which gets in the way here.

I use this query below to get a fairly complex query from prometheus and use jq to extract the interesting info then format it as csv

curl -fs --data-urlencode 'query=sort_desc( sum(container_memory_working_set_bytes) by (container_name, namespace) /sum(label_join(kube_pod_container_resource_requests_memory_bytes, "container_name", "", "container")) by (container_name, namespace) > 1)' https://prometheus/api/v1/query | jq -r '.data.result[] | [.metric.container_name, .metric.namespace, .value[1] ] | @csv'

You can view more info at https://learndevops.substack.com/p/hitting-prometheus-api-with-curl

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM