public class PushExqmple {
private static PushGateway pushGateway = PushGateway.builder()
.address("http://push.prometheus-cn-guangzhou.ivolces.com/workspaces/0df18f14-4d18******/api/v1/push")
.basicAuth("my_user", "my_password")
.job("example")
.build();
private static Gauge dataProcessedInBytes = Gauge.builder()
.name("data_processed")
.help("data processed in the last batch job run")
.unit(Unit.BYTES)
.register();
public static void main(String[] args) throws Exception {
try {
long bytesProcessed = processData();
dataProcessedInBytes.set(bytesProcessed);
} finally {
pushGateway.push();
}
}
public static long processData() {
// Imagine a batch job here that processes data
// and returns the number of Bytes processed.
return 42;
}
}
请修改示例中的 workspaceid 和 basic-auth 信息。
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 -d @- << EOF
# TYPE some_metric counter
some_metric{label="val1"} 42
# TYPE another_metric gauge
# HELP another_metric Just an example.
another_metric 2398.283
EOF