prometheus-pushgateway安装

背景

当prometheus的server与target不在同一网段网络不通,无法直接拉取target数据,需要使用pushgateway作为数据中转点。

弊端

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

实验环境

以下pushgateway分别prometheus exporter互通,其他都不通
prometheus 10.2.1.11
pushgateway 10.3.1.11
exporter 10.2.1.11

部署

pushgateway

下载安装包 pushgateway-0.8.0.linux-amd64.tar.gz (https://prometheus.io/download/#pushgateway/ )

tar -xvf pushgateway-0.8.0.linux-amd64.tar.gz -C /usr/local
mv /usr/local/pushgateway-0.8.0.linux-amd64  /usr/local/pushgateway

启动服务

 cd /usr/local/pushgateway/
./pushgateway &

prometheus

新增job pushgateway

vim /usr/local/prometheus/prometheus.yml
  - job_name: 'pushgateway'
    scrape_interval: 30s
    honor_labels: true  #加上此配置exporter节点上传数据中的一些标签将不会被pushgateway节点的相同标签覆盖
    static_configs:
      - targets: ['10.3.1.11:9091']
        labels:
          instance: pushgateway

查看target状态:

exporter

安装好node_exporter,此处不多介绍
传送监控数据到pushgateway节点
对于传过去的监控项会添加此处定义的标签 job=test instance=10.2.1.11 hostname=ip-10-2-1-11

curl 127.0.0.1:9100/metrics|curl --data-binary @- http://10.3.1.11:9091/metrics/job/test/instance/10.2.1.11/hostname/ip-10-2-1-11

此处也可以传送自定义的监控项值,以及自定义监控脚本抓取的值

echo "logic_cpu  5" |curl --data-binary @- http://10.3.1.11:9091/metrics/job/test/instance/10.2.1.11/hostname/ip-10-2-1-11

删除某个实例的数据:

curl -X DELETE http://10.3.1.11:9091/metrics/job/test/instance/10.2.1.11/hostname/ip-10-2-1-11
原文地址:https://www.cnblogs.com/huandada/p/10932953.html