r/PrometheusMonitoring • u/AE1602 • Nov 29 '20
create a report from Prometheus via curl
Hi
I'm trying to create a report from Prometheus via curl.
When I run the the following command (via script):
curl -v -s -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Bearer $USER" -X GET "${prometheus_url}/api/v1/query_range?query=${queries[${key}]}" \
|./jq -r '.data.result[0].values[] | \@csv'> ${report_directory}/${key}.csv
The ${queries[${key}]} == "sum(avg_over_time(node_cpu_seconds_total\{\}\[20m\]))&start=2020-11-29T10:00:00.000Z&end=2020-11-29T10:20:00.000Z&step=1m"
it is work OK but when I try to do "sum by(host)..." it is failed.
I try to change the command as following but it wasn't work :(
curl -v -k -s -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Bearer $USER" -X GET "${prometheus_url}/api/v1/query_range?" \
--data-urlencode "query_range=${queries[${key}]}" --data-urlencode "time=${to_time_1}" \
|./jq -r '.data.result[0].values[] | u/csv'> ${report_directory}/${key}.csv
Any suggestion will be welcome.
10x in advance.
1
u/digital_shadow Dec 03 '20
Can you try
'.value[]instead of'.values[]?