Firstly, drop off the "-s" from your curl line. Or use "-Ss" if you want
to suppress output in non-error situations, but still see errors when they
occur.
That should give you a visible error message:
curl: (3) URL using bad/illegal format or missing URL
So the problem is that curl itself is rejected the URL as malformed - it's
not even getting to Prometheus.
Then trim it down to see where the problem occurs
"$URL/api/v1/query_range" # this is OK (at least, the request reaches
Prometheus and gives an error about missing start value)
"$URL/api/v1/query_range?query=(sum(rate(container_cpu_usage_seconds_total{pod!=\"\",
container!=\"\"}[1h]))by(namespace))" # this is rejected by curl
"$URL/api/v1/query_range?query=(sum(rate(container_cpu_usage_seconds_total{pod!=\"\",container!=\"\"}[1h]))by(namespace))"
# this is accepted
I needed to remove the space after the comma in the URL.
As for the plus sign: "+" is actually the way to represent a space in a URL
("%20" is another way). If you want to insert a plus sign, then use %2B
With all those changes, that gives:
$ *curl -Ss -g -k -X GET -H "Authorization: Bearer $TOKEN" -H 'Accept:
application/json' -H 'Content-Type: application/json'
"$URL/api/v1/query_range?query=(sum(rate(container_cpu_usage_seconds_total{pod!=\"\",container!=\"\"}[1h]))by(namespace))&start=2022-08-21T07:00:00%2B03:00&end=2022-08-21T09:00:00%2B03:00&step=1h"*
{"status":"success","data":{"resultType":"matrix","result":[]}}
(although you don't actually need the "Content-Type: application/json"
header, since your request has no body)
On Tuesday, 30 August 2022 at 11:18:00 UTC+1 shirley wrote:
> Hello,
>
> I am trying to query Prometheus metrics using curl. From what I read on
> the Prometheus HTTP API, I need to supply start and end times in RFC3339 or
> timestamp format.
>
> The query I want to produce:
> curl -s -g -k -X GET -H "Authorization: Bearer $TOKEN" -H 'Accept:
> application/json' -H 'Content-Type: application/json'
> "$URL/api/v1/query_range?query=(sum(rate(container_cpu_usage_seconds_total{pod!=\"\",
>
> container!=\"\"}[1h]))by(namespace))&start=2022-08-21T07:00:00+03:00&end=2022-08-21T09:00:00+03:00&step=1h"
>
> The following error occurred when I used rfc3339 format: "Cannot parse
> \"2022-08-21T07:00:00 03:00\" to a valid timestamp".
> Any time zone that starts with "-" (for example, -03:00) or the default
> (Z) gives me results. The "+" appears to be converted to a space.
>
> My other attempts were:
> 1. I declared the "+" as a variable (export $var="+")
> 2. I wrote the query under ' ' (I wrote the full URL address)
> I still receive the same error message.
>
>
> Thanks in advance,
> Shirley
>
--
You received this message because you are subscribed to the Google Groups
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/prometheus-users/98d45a19-11e5-49b8-b7f4-57b528ccc073n%40googlegroups.com.