【云原生监控】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

相关推荐
分布式存储与RustFS16 小时前
旧 ledger 堆满 Bookie 磁盘:用 Pulsar 分层存储把冷数据卸进 RustFS
运维·云原生·开源·对象存储·分布式存储·s3·性能基准
分布式存储与RustFS19 小时前
Dify 容器一重建知识库就空了:把上传文件和密钥一起存进 RustFS
运维·云原生·开源·对象存储·分布式存储·s3·性能基准
JasonChen@6661 天前
prometheus静态监控static_config案例二(8)
grafana·prometheus
如夏倾城1 天前
入侵检测系统(IDS)原理、部署模式与 IPS/防火墙对比
大数据·网络·人工智能·网络安全·云原生·架构·kubernetes
Z21-X1 天前
云原生运维学习笔记:Kubernetes Volume 与 Secret 实验
运维·笔记·学习·云原生·kubernetes
分布式存储与RustFS2 天前
桶里的文件想当目录使:用 ZeroFS 把 RustFS 挂成一棵 POSIX 树
运维·云原生·开源·对象存储·分布式存储·s3·性能基准
分布式存储与RustFS2 天前
向量表别堆本地盘:用 LanceDB 把数据集建在 RustFS 上
运维·云原生·开源·对象存储·分布式存储·s3·性能基准
mengge.cloud2 天前
Python基础保姆级!从入门到入土
开发语言·python·云原生·pygame
阿里云云原生2 天前
阿里云 AI 网关 x 联想百应:构建 Token Plan 平台&词元宝 Token Key 产品,让模型服务走向规模化运营
云原生
阿里云云原生3 天前
基于阿里云 AgentLoop 构建 Agent 进化数据飞轮闭环,让线上 Trace 沉淀为可复用经验
云原生