自学内容网 自学内容网

【云原生监控】Prometheus之PushGateway

Prometheus之PushGateway

介绍作用

  • PushGateway为Promethus整体监控方案的功能组件之一,并作为一个独立的工具存在。它主要用于Prometheus无法直接拿到监控指标的场景,如监控源位于防火墙之后,Prometheus无法穿透防火墙,目标服务器没有可抓取监控数据的端点等多种情况。在类似的场景中,可通过部署PushGateway的方式解决问题。
  • 当部署该组件后,监控源通过主动发送监控数据到PushGateway,再又Prometheus定时获取信息,实现资源的状态监控。

资源列表

操作系统配置主机名IP
CentOS 7.92C4Gprometheus-server192.168.93.101
CentOS 7.92C4Gnode-exporter192.168.93.102
CentOS 7.92C4Ggrafana192.168.93.103
CentOS 7.92C4Gpush-gateway192.168.93.104

基础环境

  • 关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
  • 关闭内核安全机制
setenforce 0
sed -i "s/^SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config
  • 修改主机名
hostnamectl set-hostname prometheus-server
hostnamectl set-hostname node-exporter
hostnamectl set-hostname grafana
hostnamectl set-hostname push-gateway

一、部署PushGateway

  • PushGatway可以随便找一台机器单独部署或者和Prometheus或node-exporter部署在一起,用来接收数据

1.1、下载软件包

wget https://github.com/prometheus/pushgateway/releases/download/v1.6.1/pushgateway-1.6.1.linux-amd64.tar.gz

1.2、解压软件包

[root@push-gateway ~]# tar -zxvf pushgateway-1.6.1.linux-amd64.tar.gz -C /usr/local/bin/ pushgateway-1.6.1.linux-amd64/pushgateway --strip-components=1

1.3、编辑配置systemctl启动文件

[root@push-gateway ~]# cat > /etc/systemd/system/pushgatway.service <<EOF
[Unit]
Description=Pushgateway
After=network.target

[Service]
ExecStart=/usr/local/bin/pushgateway  \
  --web.listen-address=:9091 \
  --persistence.file=/prometheus/data/pushgatway.log \
  --persistence.interval=5m \
  --log.level=info \
  --log.format=json

[Install]
WantedBy=multi-user.target
EOF

1.4、创建日志目录

[root@push-gateway ~]# mkdir -p /prometheus/data/

1.5、加载并启动

[root@push-gateway ~]# systemctl daemon-reload 
[root@push-gateway ~]# systemctl enable pushgatway.service --now

1.6、监控端口

  • PushGateway默认监听9090端口
[root@push-gateway ~]# netstat -anpt | grep 9091
tcp6       0      0 :::9091                 :::*                    LISTEN      8307/pushgateway

1.7、访问PushGateway

  • 访问地址:http://192.168.93.104:9091
    在这里插入图片描述

二、 配置Prometheus抓取PushGateway数据

[root@prometheus-server ~]# vim /usr/local/prometheus/prometheus.yml
# 添加如下内容
  - job_name: "prometheus-pushgateway"  # 监控的名字
      honor_labels: true   # 解决pushgateway组件的标签和prometheus服务标签冲突,false(默认),将标签加上前缀"exporter_",不覆盖。true,覆盖原来的标签
      static_configs:  # 静态配置发现目标
        - targets: ["192.168.93.104:9091"]  # 监控的地址
# 刷新Prometheus服务
[root@prometheus-server ~]# curl -X POST http://192.168.93.101:9090/-/reload
  • 浏览器查看,Prometheus抓取PushGatway数据联通了,但是还没有数据
    在这里插入图片描述

三、被监控服务推送数据到PushGateway

[root@node-exporter ~]# echo "user_num 22" | curl --data-binary @-  http://192.168.93.104:9091/metrics/job/xinjizhiwa_user/instance/192.168.93.102


# 参数说明
echo "key value" | curl --data-binary @- http://pushgatway的ip:端口号/metrics/job/自定义job名称/instance/被监控节点的ip地址

四、查看是否推送数据

  • 查看PushGateway是否有数据
    在这里插入图片描述

  • 查看PushGateway是否把数据推送到Prometheus
    在这里插入图片描述


原文地址:https://blog.csdn.net/weixin_73059729/article/details/142301481

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!