Prometheus 实战
  • 前言
  • 修订记录
  • 如何贡献
  • Prometheus 简介
    • Prometheus 是什么
    • 为什么选择 Prometheus
  • Prometheus 安装
    • 二进制包安装
    • Docker 安装
  • 基础概念
    • 数据模型
    • 指标类型
    • 作业与实例
  • PromQL
    • PromQL 基本使用
    • 与 SQL 对比
  • 数据可视化
    • Web Console
    • Grafana
    • Promlens
  • Prometheus 配置
    • 全局配置
    • 告警配置
    • 规则配置
    • 数据拉取配置
    • 远程可写存储
    • 远程可读存储
    • 服务发现
    • 配置样例
  • 服务发现
    • 静态服务发现
    • 文件服务发现
    • HTTP服务发现
    • Consul服务发现
    • moby服务发现
    • kubernetes服务发现
  • Exporter
    • 文本格式
    • Sample Exporter
    • Node Exporter 安装使用
    • Node Exporter 常用查询
    • 其他 Exporter 介绍
  • Pushgateway
    • Pushgateway 是什么
    • 如何使用 Pushgateway
  • 数据存储
    • Local Store
    • Remote Store
  • 告警/记录规则
    • 如何配置
    • 触发逻辑
  • Alertmanager
    • Alertmanager 是什么
    • 配置详情
    • 通过 Email 接收告警
    • 通过企业微信接收告警
    • 通过 Slack 接收告警
    • 通过 Webhook 接收告警
    • 其他告警接收方案
  • Prometheus 工具
    • Promtool 介绍和使用
    • Client SDK
  • Prometheus 性能调优
    • Metrics 仪表盘
    • 启动参数优化
    • 日志查询
  • Prometheus 与容器
    • Docker
    • Kubernetes
  • 高可用方案探讨
    • Prometheus Server 的高可靠
    • AlertManager 的高可靠
  • 实战练习
    • NodeExporter
    • 配置告警规则
    • Grafana 集成
    • Alertmanager 告警
  • 常见问题收录
    • 如何热加载新配置
    • 如何通过认证后拉取数据
Powered by GitBook
On this page
  • 安装
  • 二进制安装
  • Docker 安装
  • 数据管理

Was this helpful?

  1. Pushgateway

如何使用 Pushgateway

PreviousPushgateway 是什么Next数据存储

Last updated 4 years ago

Was this helpful?

安装

二进制安装

你可以到,选择对应的版本, 以 v0.4.0 为例子,

  • 使用 wget 下载 pushgateway

cd ~/Download
https://github.com/prometheus/pushgateway/releases/download/v0.4.0/pushgateway-0.4.0.linux-amd64.tar.gz
  • 使用 tar 解压缩 pushgateway-0.4.0.linux-amd64.tar.gz

cd ~/Prometheus
tar -xvzf ~/Download/pushgateway-0.4.0.linux-amd64.tar.gz
cd pushgateway-0.4.0.linux-amd64
  • 启动 pushgateway

我们可以使用 ./pushgateway -h 查看运行选项,./pushgateway 运行 pushgateway, 如果看到类似输出,表示启动成功。

INFO[0000] Starting pushgateway (version=0.4.0, branch=master, revision=6ceb4a19fa85ac2d6c2d386c144566fb1ede1f6c)  source=main.go:57
INFO[0000] Build context (go=go1.8.3, user=root@87741d1b66a9, date=20170609-12:26:14)  source=main.go:58
INFO[0000] Listening on :9091.                           source=main.go:102

Docker 安装

docker pull prom/pushgateway

docker run -d -p 9091:9091 prom/pushgateway

数据管理

正常情况我们会使用 Client SDK 推送数据到 pushgateway, 但是我们还可以通过 API 来管理, 例如:

  • 向 {job="some_job"} 添加单条数据:

echo "some_metric 3.14" | curl --data-binary @- http://pushgateway.example.org:9091/metrics/job/some_job
  • 添加更多更复杂数据,通常数据会带上 instance, 表示来源位置:

cat <<EOF | curl --data-binary @- http://pushgateway.example.org:9091/metrics/job/some_job/instance/some_instance
# TYPE some_metric counter
some_metric{label="val1"} 42
# TYPE another_metric gauge
# HELP another_metric Just an example.
another_metric 2398.283
EOF
  • 删除某个组下的某实例的所有数据:

 curl -X DELETE http://pushgateway.example.org:9091/metrics/job/some_job/instance/some_instance
  • 删除某个组下的所有数据:

curl -X DELETE http://pushgateway.example.org:9091/metrics/job/some_job

可以发现 pushgateway 中的数据我们通常按照 job 和 instance 分组分类,所以这两个参数不可缺少。

因为 Prometheus 配置 pushgateway 的时候,也会指定 job 和 instance, 但是它只表示 pushgateway 实例,不能真正表达收集数据的含义。所以在 prometheus 中配置 pushgateway 的时候,需要添加 honor_labels: true 参数, 从而避免收集数据本身的 job 和 instance 被覆盖。

注意,为了防止 pushgateway 重启或意外挂掉,导致数据丢失,我们可以通过 -persistence.file 和 -persistence.interval 参数将数据持久化下来。

我们可以使用 的 Docker 镜像,

下载页面
prom/pushgateway