其他分享
首页 > 其他分享> > prometheus之pushgateway

prometheus之pushgateway

作者:互联网

Pushgateway 是 Prometheus 生态中一个重要工具,使用它的原因主要是:

Prometheus 采用 pull 模式,可能由于不在一个子网或者防火墙原因,导致 Prometheus 无法直接拉取各个 target 数据。
在监控业务数据的时候,需要将不同数据汇总, 由 Prometheus 统一收集。

由于以上原因,不得不使用 pushgateway,但在使用之前,有必要了解一下它的一些弊端:

将多个节点数据汇总到 pushgateway, 如果 pushgateway 挂了,受影响比多个 target 大。
Prometheus 拉取状态 up 只针对 pushgateway, 无法做到对每个节点有效。
Pushgateway 可以持久化推送给它的所有监控数据。
因此,即使你的监控已经下线,prometheus 还会拉取到旧的监控数据,需要手动清理 pushgateway 不要的数据。

服务端:
在prometheus服务端安装pushgateway后,在prometheus配置文件添加对pushgateway的引用,

- job_name: 'pushgateway'          #任务名
  honor_labels: true                        #避免收集数据本身的 job 和 instance 被覆盖
  static_configs:                            #静态配置方式,因为目前就一个 PushGateway
     - targets: ['127.0.0.1:9091']     #pushgateway的端口

这样prometheus主动拉取pushgateway的数据,pushgateway被动收取node节点推送过来的metrics。
客户端:

除了要安装node服务外,还要加一条curl 127.0.0.1:9100/metrics | curl --data-binary @- http://1.1.1.1:9091/metrics/job/job-name/的命令,具体含义是:将自身metrics的值通过后面的固定命令发送给pushgateway的主机,后面的job-name为自定义任务名字,后面可以再添加一个 instance/<INSTANCE_NAME> 实例名称标签,来方便区分各个指标。

标签:prometheus,Prometheus,metrics,job,pushgateway,数据
来源: https://blog.51cto.com/u_13377829/2776775