Pushgateway 简介
Pushgateway 是 Prometheus 生态中一个重要工具,使用它的原因主要是:
- Prometheus 采用 pull 模式,可能由于不在一个子网或者防火墙原因,导致 Prometheus 无法直接拉取各个 target 数据。
- 在监控业务数据的时候,需要将不同数据汇总, 由 Prometheus 统一收集。
由于以上原因,不得不使用 pushgateway,但在使用之前,有必要了解一下它的一些弊端:
- 将多个节点数据汇总到 pushgateway, 如果 pushgateway 挂了,受影响比多个 target 大。
- Prometheus 拉取状态 up 只针对 pushgateway, 无法做到对每个节点有效。
- Pushgateway 可以持久化推送给它的所有监控数据。
因此,即使你的监控已经下线,prometheus 还会拉取到旧的监控数据,需要手动清理 pushgateway 不要的数据。
Pushgateway使用方法
usage: pushgateway [<flags>]
Flags:
--web.listen-address=":9091" 监听Web界面,API和遥测的地址。
--web.telemetry-path="/metrics" 公开metrics的路径。
--web.external-url= 可从外部访问Pushgateway的URL.
--web.route-prefix="" Web端点内部路由的前缀。 默认为--web.external-url的路径.
--persistence.file="" 归档以保留metrics。 如果为空,则metrics仅保留在内存中.
--persistence.interval=5m 写入持久性文件的最小间隔。
--log.level="info" 仅记录具有给定严重性或更高严重性的消息。 有效级别:[debug, info, warn, error, fatal]
--log.format="logger:stderr" 设置日志目标和格式。 示例:“ logger:syslog?appname = bob&local = 7”或“ logger:stdout?json = true”
--version 显示应用程序版本。
pushgateway每次只向Prometheus返回最后一次推送的数据
- pushgateway并不是将Prometheus的pull改成了push,它只是允许用户向他推送指标信息,并记录。而Prometheus每次从 - pushgateway拉取的数据并不是期间用户推送上来的所有数据,而是最后一次push上来的数据。所以设置推送时间与Prometheus拉取的时间相同(<=)一般是较好的方案。
注意:如果客户端一直没有推送新的指标到pushgateway,那么Prometheus将始终拉取最后push上来的数据。
可以通过命令删除指标:
Delete all metrics in the group identified by {job=“some_job”,instance=“some_instance”}:
curl -X DELETE http://pushgateway.example.org:9091/metrics/job/some_job/instance/some_instance
Delete all metrics in the group identified by {job=“some_job”} (note that this does not include metrics in the {job=“some_job”,instance=“some_instance”} group from the previous example, even if those metrics have the same job label):
curl -X DELETE http://pushgateway.example.org:9091/metrics/job/some_job
Delete all metrics in all groups (requires to enable the admin API via the command line flag --web.enable-admin-api):
curl -X PUT http://pushgateway.example.org:9091/api/v1/admin/wipe
推送到pushgateway的方法
- push:删除原有的所有指标并推送新的指标,对应put方法
- pushadd:更新已有的所有指标,对应post方法
- delete:删除指标,对应delete方法