# Pushgateway 安装和使用
## 安装
### 二进制安装
你可以到[下载页面](https://github.com/prometheus/pushgateway/releases/tag/v0.4.0),选择对应的版本,
以 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 安装
我们可以使用 [prom/pushgateway](https://registry.hub.docker.com/u/prom/pushgateway/) 的 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` 参数将数据持久化下来。
- 前言
- 修订记录
- 如何贡献
- Prometheus 简介
- Prometheus 是什么?
- 为什么选择 Prometheus?
- Prometheus 安装
- 二进制包安装
- Docker 安装
- 基础概念
- 数据模型
- Metric types
- 作业与实例
- PromQL
- PromQL 基本使用
- 与 SQL 对比
- 数据可视化
- Web Console
- Grafana
- Prometheus 配置
- 全局配置
- 告警配置
- 规则配置
- 数据拉取配置
- 远程可写存储
- 远程可读存储
- 服务发现
- 配置样例
- Exporter
- 文本格式
- Golang Sample Exporter
- Python Sample Exporter
- Node Exporter 安装使用
- Node Exporter 常用查询
- 其他 Exporter 介绍
- Pushgateway
- Pushgateway 是什么?
- 如何使用 Pushgateway?
- 数据存储
- Memory Store
- Local Store
- Remote Store
- Rule
- 如何配置
- Rule 触发逻辑
- Aleretmanager
- Aleretmanager 是什么?
- 如何实现告警分组和去噪
- 通过 Email 接收告警
- 通过 OneAlert 管理告警
- 通过 Webhooks 接收告警
- 其他告警接收方案
- 使用 Prometheus 实现主机运行状态监控的完整演示
- Target 配置
- Rule 配置
- Alertmanager 配置
- 演示功能
- Prometheus Tool
- Promu 介绍和使用
- Client SDK
- Prometheus 性能调优
- 通过 Metrics 查看 Prometheus 运行状态
- 通过日志分析 Prometheus 运行状态
- 通过调整启动参数优化性能
- Prometheus 与 JVM 监控
- JVM Exporter 安装
- JVM 数据查询
- Prometheus 与容器监控
- Docker 监控
- Rocket 监控
- Prometheus 与容器编排
- Kubernetes
- Docker Swarm
- Prometheus 与 DevOps
- 如何从 0 开发一个 exporter
- 使用 Webhooks 开发一个 alert receiver
- 产品化
- 高可用方案探讨
- 集群方案
- 主从方案
- v2.0 功能洞见
- 新功能
- 新存储架构
- 常见问题收录
- 如何热加载新配置?
- 为什么重启 Prometheus 过后,数据无法查询?
- 如何删除 Pushgateway 的数据?
- 为什么内存使用这么高?
- 为什么有数据丢失?
- Prometheus 如何通过认证后拉取数据?
