登录
首页 >  Golang >  Go问答

Prometheus HTTP API请求中的“远程写入接收器”

来源:stackoverflow

时间:2024-02-07 19:06:22 340浏览 收藏

从现在开始,努力学习吧!本文《Prometheus HTTP API请求中的“远程写入接收器”》主要讲解了等等相关知识点,我会在golang学习网中持续更新相关的系列文章,欢迎大家关注并积极留言建议。下面就先一起来看一下本篇正文内容吧,希望能帮到你!

问题内容

我正在尝试找到一个如何在 prometheus 中使用远程写入接收器的工作示例。

链接: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 请求向我的服务器进行身份验证。


正确答案


请注意,不建议通过remote_write协议将应用程序数据发送到Prometheus,因为Prometheus旨在从Prometheus config中指定的目标中抓取指标。当您尝试将指标推送到Prometheus时,这称为pull model又名 push model

如果您需要将应用程序指标推送到 Prometheus,则存在以下选项:

  • 将指标推送至 pushgateway。使用前请先阅读 when to use the pushgateway

  • 将指标推送至 statsd_exporter

  • 通过任何 supported text-based data ingestion protocol 将应用程序指标推送到 VictoriaMetrics(这是一个类似 Prometheus 的替代监控系统):

    • Prometheus 文本阐述格式
    • 石墨
    • 流入线协议
    • OpenTSDB
    • 数据狗
    • JSON
    • CSV

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

以上就是《Prometheus HTTP API请求中的“远程写入接收器”》的详细内容,更多关于的资料请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>