How to call remote write API with proper snappy format from java/python/postman application

2.2k views Asked by At

I have been trying to call remote_write() function of Prometheus via java/python/postman. I have configured a Prometheus server with remote receiver configuration and I have another Prometheus agent running from where I am trying to make an API call to do remote_write().

I have been getting the below error and I believe we need to do a snappy compression and call the APIs?

Any samples or help on how we can call this /api/v1/write API via java or python or maybe via postman by doing a snappy compression ?

Sample I am trying:

curl --location --request POST 'http://<prometheus-host>/api/v1/write' \
--header 'Content-Type: text/plain' \
--data-raw 'metrics_app_20221201091829_0000_driver_BlockManager_memory_diskSpaceUsed_MB_Number{type="gauges"} 0

Error:

snappy: corrupt input
1

There are 1 answers

0
yonatan On

snappy is a kind of compression.
try this (python code):

import snappy
import requests

requests.post(
    "http://<prometheus-host>/api/v1/write",
    auth=(username, password),
    data=snappy.compress(payload),
    headers=headers,
)

* should probably pip install python-snappy