pushgateway 部署

 


pushgateway 说明

pushgateway 是采用被动推送的方式,而不是类似于prometheus server主动连接 exporter 获取监控数据。
pushgateway 可以单独运行在一个节点,然后需要自定义监控脚本把需要监控的主动推送给 pushgateway的 API接口,然后 pushgateway 再等待 prometheus server 抓取数据,即 pushgateway 本身没有任何抓取监控数据的功能,目前 pushgateway 只是被动的等待数据从客户端推送过来。

创建 pushgateway 用户

groupadd  -r pushgateway && \
useradd -M -N -g pushgateway  -r -s /bin/false -c "pushgateway service account" pushgateway

pushgateway 下载

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

pushgateway 安装

tar xf pushgateway-1.11.0.linux-amd64.tar.gz -C /usr/local/
ln -sv /usr/local/pushgateway-1.11.0.linux-amd64 /usr/local/pushgateway

创建 pushgateway 数据目录

mkdir /usr/local/pushgateway/data && chown -R pushgateway:pushgateway /usr/local/pushgateway/

pushgateway.service

cat >> /lib/systemd/system/pushgateway.service << EOF
[Unit]
Descripton=pushgateway server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target

[Service]
Restart=on-failure
User=pushgateway
WorkingDirectory=/usr/local/pushgateway
ExecStart=/usr/local/pushgateway/pushgateway  --persistence.file="/usr/local/pushgateway/data/data" --web.listen-address=:19091

[Install]
WantedBy=multi-user.target
EOF

pushgateway 开机自启

systemctl enable pushgateway --now

pushgateway 推送数据

# 推送单个指标(纯文本协议)
echo "http_requests_total{job=\"my_job\"} 42" | curl --data-binary @- http://pushgateway:9091/metrics/job/my_job

# 推送复杂指标(含类型和帮助信息)
cat <<EOF | curl --data-binary @- http://pushgateway:9091/metrics/job/my_job
# TYPE http_requests_total counter
# HELP http_requests_total Total HTTP requests.
http_requests_total{path="/"} 42
EOF

pushgateway 删除指标

删除指定组:
    curl -X DELETE http://pushgateway:9091/metrics/job/my_job/instance/my_instance

清空所有指标(需启用管理 API):
    curl -X PUT http://pushgateway:9091/api/v1/admin/wipe

pushgateway 验证数据

curl http://192.168.174.100:19091/metrics

配置 Prometheus 抓取

scrape_configs:
  - job_name: pushgateway
    honor_labels: true  # 保留推送的 job/instance 标签
    static_configs:
      - targets: ['192.168.174.100:19091']

pushgateway TLS 与认证配置

tls_server_config:
  cert_file: server.crt
  key_file: server.key
basic_auth_users:
  admin: "$2y$12$xxxxxxxxxxxxxxxxxxxxxx"  # bcrypt 哈希密码

pushgateway 使用说明

Flags:
  -h, --[no-]help                显示上下文相关的帮助信息(支持 --help-long 查看完整参数,--help-man 生成手册格式)。
      --[no-]web.systemd-socket  在 Linux 系统上使用 systemd 套接字激活(代替传统的端口监听)。需与 systemd 配置配合使用。
      --web.listen-address=:9091 ...  
                                 指定 Pushgateway 监听的地址和端口,默认 :9091(所有 IPv4/IPv6 地址的 9091 端口)。 
                                 Examples: 
                                     --web.listen-address=:9091:默认监听所有接口的 9091 端口。
                                     --web.listen-address=[::1]:9100:仅监听 IPv6 本地回环地址的 9100 端口。
                                     可重复使用以监听多个地址(如 HTTP 和 HTTPS)。
      --web.config.file=""       指定 Web 配置文件路径,用于启用 TLS 加密或基本认证。 See:
                                 https://github.com/prometheus/exporter-toolkit/blob/master/docs/web-configuration.md
      --web.telemetry-path="/metrics"  
                                 指定暴露监控指标的 HTTP 路径,默认 /metrics。Prometheus 从此路径抓取指标。
      --web.external-url=        设置 Pushgateway 的外部访问 URL(用于生成链接或告警信息)。 --web.external-url=http://pushgateway.example.com:9091
      --web.route-prefix=""      设置内部路由前缀(默认与 --web.external-url 路径一致)。仅在反向代理需要修改路径时使用。
      --[no-]web.enable-lifecycle  
                                 允许通过 HTTP 请求优雅关闭 Pushgateway(发送 PUT /-/quit 触发)。
      --[no-]web.enable-admin-api  
                                 启用管理 API(如清空所有指标 PUT /api/v1/admin/wipe)。
      --persistence.file=""      #数据保存的文件,默认只保存在内存中
      --persistence.interval=5m  #数据持久化的间隔时间
      --[no-]push.disable-consistency-check  
                                 禁用推送指标的一致性检查(同名指标类型冲突或重复标签将不报错)。
      --[no-]push.enable-utf8-names  
                                 允许指标名和标签名包含 UTF-8 字符(需按规则编码,如 U__<encoded_name>)。
      --log.level=info           设置日志级别:debug、info、warn、error。
      --log.format=logfmt        Output format of log messages. One of: [logfmt, json]
      --[no-]version             显示 Pushgateway 的版本信息。

参考文档

https://github.com/prometheus/pushgateway

posted @   小吉猫  阅读(8)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
历史上的今天:
2023-02-27 kubernetes Ingress
点击右上角即可分享
微信分享提示