- 文档首页
托管 Prometheus
最佳实践
Prometheus 数据采集与接入
使用 Pushgateway 推送数据
Prometheus 数据采集与接入
使用 Pushgateway 推送数据
使用 Pushgateway 推送数据
本文介绍如何使用托管 Prometheus 提供的 Pushgateway 功能推送数据。
背景介绍
托管 Prometheus 支持社区 Prometehus Pushgateway 协议,使用步骤如下:
- 获取 Pushgateway URL:通过托管 Prometheus 控制台获取 Push 地址。
- 上报数据:使用 curl 命令或者开源 SDK 实现数据推送。
前提条件
已创建托管 Prometheus 工作区。详情请参见 创建工作区。 步骤一:获取 Pushgateway URL
-
- 在左侧导航栏,选择 概览,然后在 地址信息 区域获取 Push Gateway URL。
-
步骤二:上报数据
兼容社区开源 Prometheus SDK 使用 Pushgateway 协议上报,以下提供 Golang、JAVA 和 curl 命令示例,其他语言请参见社区文档。
注意
目前仅支持 Text Format 和 Protobuf Delimited 两种数据层协议,暂不支持 Protobuf Text、Protobuf Compact-Text 和 OpenMetrics 等协议,开源的 SDK 一般默认是 Protobuf Delimited 协议。
Golang SDK
JAVA SDK
使用 Curl 命令
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/push"
New("http://push.prometheus-cn-guangzhou.ivolces.com/workspaces/0df18f14-4d18******/api/v1/push", "push_job").
BasicAuth("username", "password").
Grouping("label_1", "value_1")
testCounter := prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "push_test_counter",
Help: "push test demo counter",
testCounter.WithLabelValues("test").Add(20)
if err := pusher.Collector(testCounter).Push(); err != nil {
fmt.Println(err.Error())
public class PushExqmple {
private static PushGateway pushGateway = PushGateway.builder()
.address("push.prometheus-cn-guangzhou.ivolces.com/workspaces/0df18f14-4d18******/api/v1/push")
.basicAuth("my_user", "my_password")
private static Gauge dataProcessedInBytes = Gauge.builder()
.help("data processed in the last batch job run")
public static void main(String[] args) throws Exception {
long bytesProcessed = processData();
dataProcessedInBytes.set(bytesProcessed);
public static long processData() {
curl -H "Content-Type: text/plain; version=0.0.4; charset=utf-8" -u "username:password" http://push.prometheus-cn-guangzhou.ivolces.com/workspaces/0df18f******/api/v1/push/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.
步骤三:查询数据
登录 VMP 服务控制台查询上报的结果。写入成功后需要等待 30s 才能查到最新的数据。
最近更新时间:2025.09.03 15:13:02