How to push metrics to prometheus api/v1/write API endpoint with CURL

2,032 views
Skip to first unread message

ihor.pi...@gmail.com

unread,
Nov 23, 2022, 8:14:02 AM11/23/22
to Prometheus Users
Here is a set of correct metrics 

cat metrics.prom
# HELP http_requests_total The total number of HTTP requests.
# TYPE http_requests_total counter
http_requests_total{method="post",code="200"} 1027 1395066363000
http_requests_total{method="post",code="400"}    3 1395066363000

cat metrics.prom | promtool check metrics



Then it is supposed to be compressed by snappy as the manual said 

The read and write protocols both use a snappy-compressed protocol buffer encoding over HTTP.


So,

snzip metrics.prom


Then 

curl  --header "Content-Type: application/openmetrics-text" \
--header "Content-Encoding: snappy" \
--request POST \
--data-binary "@metrics.prom.sz" \
"http://localhost:9090/api/v1/write"

but unfortunately, the  result is 


snappy: corrupt input

Why is it corrupt?

snzip -d  metrics.prom.sz


gives perfectly fine result.

Brian Candler

unread,
Nov 23, 2022, 12:59:42 PM11/23/22
to Prometheus Users
The read and write protocols both use a snappy-compressed protocol buffer encoding over HTTP.

I think you have tried to use plain text metrics, when they need to be represented in protobuf binary format (and *then* compressed)
Reply all
Reply to author
Forward
0 new messages