Mercurial > code > home > repos > mqtt_metrics
view victoriametrics_write.py @ 10:2a507e679d0d default tip
add zigbee covnerters
author | drewp@bigasterisk.com |
---|---|
date | Mon, 12 Aug 2024 13:15:07 -0700 |
parents | a640efa9fb01 |
children |
line wrap: on
line source
import httpx import logging log = logging.getLogger() class MetricsWriter: # todo: this could merge quick writes, keep the connection open, etc. agentImportUrl = "http://victoriametrics-forever-vmagent/m/forever/vmagent/api/v1/import" def write(self, t, metricEvent): # To see inserted data, try this: # curl http://`khost victoriametrics-vmselect`/m/vmselect/select/0/prometheus/api/v1/export -d 'match[]=vm_http_request_errors_total' labelDict = dict((x['labelName'], x['labelValue']) for x in metricEvent['labels']) promBody = { "metric": { "__name__": metricEvent['name'] } | labelDict, "values": [metricEvent['value']], "timestamps": [int(t * 1000)], } # log.info(promBody) req = httpx.post( self.agentImportUrl, json=promBody, headers={'content-type': 'application/stream+json'}, ) req.raise_for_status()