Prometheus Query and API call

Viewed 4082

I am able to search directly from Prometheus UI for a query and it works fine:

K_MacInfo{macAddr="B0:11:12:FD:D1:A8"} offset 5m.

However, when I tried running it directly in the server using a curl command, I am getting the syntax wrong and getting error message.

curl http://localhost:9090/api/v1/queryquery=K_MacInfo{macAddr="B0:11:12:FD:D1:A8"}

Also not sure how to add the offset part here. Could you guide me to understand what I am doing wrong here?

1 Answers

Your URL is somewhat malformed and you need to properly urlencode the query parameter. curl can do that for you:

curl -G \
--data-urlencode 'query=K_MacInfo{macAddr="B0:11:12:FD:D1:A8"} offset 5m' \
http://localhost:9090/api/v1/query
Related