【云原生监控】Prometheus之PushGateway

Prometheus之PushGateway

文章目录

介绍作用

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

资源列表

操作系统 配置 主机名 IP
CentOS 7.9 2C4G prometheus-server 192.168.93.101
CentOS 7.9 2C4G node-exporter 192.168.93.102
CentOS 7.9 2C4G grafana 192.168.93.103
CentOS 7.9 2C4G push-gateway 192.168.93.104

基础环境

  • 关闭防火墙
bash 复制代码
systemctl stop firewalld
systemctl disable firewalld
  • 关闭内核安全机制
bash 复制代码
setenforce 0
sed -i "s/^SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config
  • 修改主机名
bash 复制代码
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、下载软件包

bash 复制代码
wget https://github.com/prometheus/pushgateway/releases/download/v1.6.1/pushgateway-1.6.1.linux-amd64.tar.gz

1.2、解压软件包

bash 复制代码
[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启动文件

bash 复制代码
[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、创建日志目录

bash 复制代码
[root@push-gateway ~]# mkdir -p /prometheus/data/

1.5、加载并启动

bash 复制代码
[root@push-gateway ~]# systemctl daemon-reload 
[root@push-gateway ~]# systemctl enable pushgatway.service --now

1.6、监控端口

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

1.7、访问PushGateway

二、 配置Prometheus抓取PushGateway数据

bash 复制代码
[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"]  # 监控的地址
bash 复制代码
# 刷新Prometheus服务
[root@prometheus-server ~]# curl -X POST http://192.168.93.101:9090/-/reload
  • 浏览器查看,Prometheus抓取PushGatway数据联通了,但是还没有数据

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

bash 复制代码
[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

相关推荐
●VON1 天前
重生之我在大学自学鸿蒙开发第九天-《分布式流转》
学习·华为·云原生·harmonyos·鸿蒙
安当加密1 天前
云原生时代的数据库字段加密:在微服务与 Kubernetes 中实现合规与敏捷的统一
数据库·微服务·云原生
qq_264220891 天前
K8s存储-PV与PVC
云原生·容器·kubernetes
努力向前的JF(s1hjf)2 天前
雷达点云数据展示在webviz(ROS1)
云原生·eureka
没有bug.的程序员2 天前
云原生与分布式架构的完美融合:从理论到生产实践
java·分布式·微服务·云原生·架构
AWS官方合作商2 天前
AWS WAF 深度体验:全新控制台,开启云原生WAF与CloudFront无缝联防新纪元
云原生·aws
m0_736927042 天前
从被动救火到主动预警,用 Prometheus + Alertmanager 跑通告警闭环
prometheus
tianyuanwo2 天前
虚拟机监控全攻略:从基础到云原生实战
linux·云原生·虚机监控
递归尽头是星辰2 天前
Docker容器化核心知识体系:从入门到实践
docker·云原生·devops·容器化·镜像构建
天才奇男子2 天前
用户管理,权限管理
linux·云原生