Prometheus API

30 views
Skip to first unread message

Thomas Will

unread,
Jun 18, 2020, 10:02:43 AM6/18/20
to Prometheus Users
Hello fellas, I am running this command on my cluster. 

Command = curl "localhost:9090/api/v1/series?match[]=metric_name{instanceAlias="node0002"}"
Error          = {"status":"error","errorType":"bad_data","error":"parse error at char 110: could not parse remaining input \"=node0002\"..."}

Can anyone please point out my mistake here.

Thanks,
Thomas Will

Mat Arye

unread,
Jun 18, 2020, 10:18:10 AM6/18/20
to Prometheus Users


On Thursday, June 18, 2020 at 10:02:43 AM UTC-4, Thomas Will wrote:
Hello fellas, I am running this command on my cluster. 

Command = curl "localhost:9090/api/v1/series?match[]=metric_name{instanceAlias="node0002"}"

I think this may be a quoting issue. You are double-quoting the entire url ("localhost:9090/api/v1/series?match[]=metric_name{instanceAlias="node0002"}") but not escaping the quote round node0002

Thomas Will

unread,
Jun 18, 2020, 10:39:22 AM6/18/20
to Prometheus Users
@Mat Arye I am still getting the same error if I remove double quotes around curl command. Can you please make changes in that command how exactly it should be?

Brian Candler

unread,
Jun 18, 2020, 10:42:12 AM6/18/20
to Prometheus Users
1. Use curl -g to stop it interpreting special characters, like curly braces
2. If you want double quotes inside double quotes, then they must be preceded by a backslash: \"

It's simpler to use single quotes on the outside:

curl -g 'localhost:9090/api/v1/series?match[]=metric_name{instanceAlias="node0002"}'

You may also find it easier to use "promtool query" (and you get prettier output too)

/opt/prometheus/promtool query instant http://localhost:9090 'metric_name{instanceAlias="node0002"}'

Brian Candler

unread,
Jun 18, 2020, 10:44:35 AM6/18/20
to Prometheus Users
Sorry, it was a series query, so promtool query would be:

/opt/prometheus/promtool query series http://localhost:9090 --match 'metric_name{instanceAlias="node0002"}'

Thomas Will

unread,
Jun 18, 2020, 10:50:19 AM6/18/20
to Prometheus Users
Thanks, Brian, Mat for helping me. If I need to add more parameters to search, e.g = job=jmx_exporter, will this work then?
curl -g 'localhost:9090/api/v1/series?match[]=metric_name{job='jmx_exporter' && instanceAlias="node0002"}'

Brian Candler

unread,
Jun 18, 2020, 2:41:33 PM6/18/20
to Prometheus Users
No, you need to use the PromQL syntax when selecting on multiple labels:

metric_name{job="jmx_exporter",instanceAlias="node0002"}

Thomas Will

unread,
Jun 18, 2020, 4:38:21 PM6/18/20
to Prometheus Users
thank you :)
Reply all
Reply to author
Forward
0 new messages