在Prometheus中的'remote write receiver' HTTP API请求

huangapple go评论109阅读模式
英文:

'remote write receiver' HTTP API request in Prometheus

问题

我正在尝试找到一个使用Prometheus中的remote write接收器的工作示例。

链接:https://prometheus.io/docs/prometheus/latest/querying/api/#remote-write-receiver

我能够向端点发送请求(POST /api/v1/write),并且可以与服务器进行身份验证。然而,我不知道需要以什么格式发送数据。

官方文档表示数据需要使用Protobuf格式并进行snappy编码。我知道它们的库。我有一些指标需要发送到Prometheus的http:localhost:1234/api/v1/write。我正在尝试导出的指标是从指标端点(http://127.0.0.1:9187/metrics)中获取的,格式如下:

# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 1.11e-05
go_gc_duration_seconds{quantile="0.25"} 2.4039e-05
go_gc_duration_seconds{quantile="0.5"} 3.4507e-05
go_gc_duration_seconds{quantile="0.75"} 5.7043e-05
go_gc_duration_seconds{quantile="1"} 0.002476999
go_gc_duration_seconds_sum 0.104596342
go_gc_duration_seconds_count 1629

目前,我可以通过Golang中的POST请求与我的服务器进行身份验证。

英文:

I am trying to find a working example of how to use the remote write receiver in Prometheus.

Link : https://prometheus.io/docs/prometheus/latest/querying/api/#remote-write-receiver

I am able to send a request to the endpoint ( POST /api/v1/write ) and can authenticate with the server. However, I have no idea in what format I need to send the data over.

The official documentation says that the data needs to be in Protobuf format and snappy encoded. I know the libraries for them. I have a few metrics i need to send over to prometheus http:localhost:1234/api/v1/write.
The metrics i am trying to export are scraped from a metrics endpoint (http://127.0.0.1:9187/metrics ) and looks like this :

# HELP go_gc_duration_seconds A summary of the pause duration of garbage collection cycles.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 1.11e-05
go_gc_duration_seconds{quantile="0.25"} 2.4039e-05
go_gc_duration_seconds{quantile="0.5"} 3.4507e-05
go_gc_duration_seconds{quantile="0.75"} 5.7043e-05
go_gc_duration_seconds{quantile="1"} 0.002476999
go_gc_duration_seconds_sum 0.104596342
go_gc_duration_seconds_count 1629

As of now, i can authenticate with my server via a POST request in Golang.

答案1

得分: 1

请注意,不建议通过remote_write协议将应用程序数据发送到Prometheus,因为Prometheus的设计是从在Prometheus配置中指定的目标中抓取指标。这被称为拉模型,而你正在尝试将指标推送到Prometheus,也就是推模型

如果你需要将应用程序指标推送到Prometheus,可以考虑以下选项:

与Prometheus的remote_write协议相比,所有这些协议都更容易实现和调试,因为这些协议都是基于文本的,而Prometheus的remote_write协议是一种二进制协议(基本上是通过HTTP发送的snappy压缩的protobuf消息)。

英文:

Please note that it isn't recommended to send application data to Prometheus via remote_write protocol, since Prometheus is designed to scrape metrics from the targets specified in Prometheus config. This is known as pull model, while you are trying to push metrics to Prometheus aka push model.

If you need pushing application metrics to Prometheus, then the following options exist:

  • Pushing metrics to pushgateway. Please read when to use the pushgateway before using it.

  • Pushing metrics to statsd_exporter.

  • Pushing application metrics to VictoriaMetrics (this is an alternative Prometheus-like monitoring system) via any supported text-based data ingestion protocol:

    • Prometheus text exposition format
    • Graphite
    • Influx line protocol
    • OpenTSDB
    • DataDog
    • JSON
    • CSV

    All these protocols are much easier to implement and debug comparing to Prometheus remote_write protocol, since these protocols are text-based, while Prometheus remote_write protocol is a binary protocol (basically, it is snappy-compressed protobuf messages sent over HTTP).

huangapple
  • 本文由 发表于 2022年6月4日 06:13:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/72495611.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定