我正在使用 prometheus 简单客户端通过 Spring Boot 应用程序在我的系统中收集指标
void insertBatchJob(String request , String[] labelNames, String[] labelValues,String counter) throws Exception {
CollectorRegistry registry = new CollectorRegistry();
Gauge inprogressRequests ;
if( !gaugeRegiseryMap.containsKey(request) ) {
inprogressRequests = Gauge.build()
.name(request).labelNames(labelNames).help(request).register();
gaugeRegiseryMap.put(request,inprogressRequests);
}else{
inprogressRequests = gaugeRegiseryMap.get(request);
}
try {
inprogressRequests.labels(labelValues[labelValues.length-4],
labelValues[labelValues.length-2],
labelValues[labelValues.length-3],
labelValues[labelValues.length-1]).set(Double.parseDouble(counter));
registry.register(inprogressRequests);
} finally {
PushGateway pg = new PushGateway("127.0.0.1:9091");
pg.pushAdd(registry, request);
}
}
以下代码正在运行,但是当我通过包含标签值的数组时更改 inprogressRequests.labels() 即
`
void insertBatchJob(String request , String[] labelNames, String[] labelValues,String counter) throws Exception {
CollectorRegistry registry = new CollectorRegistry();
Gauge inprogressRequests ;
if( !gaugeRegiseryMap.containsKey(request) ) {
inprogressRequests = Gauge.build()
.name(request).labelNames(labelNames).help(request).register();
gaugeRegiseryMap.put(request,inprogressRequests);
}else{
inprogressRequests = gaugeRegiseryMap.get(request);
}
try {
inprogressRequests..labels(labelValues).set(Double.parseDouble(counter));
registry.register(inprogressRequests);
} finally {
PushGateway pg = new PushGateway("127.0.0.1:9091");
pg.pushAdd(registry, request);
}
}`
同样给我错误-
来自http://127.0.0.1:9091/metrics/job/loop6_2的响应代码为 400,响应正文:推送的指标无效或与现有指标不一致:收集的指标。
这是我第一次使用 prometheus ,如果有人可以分享这一点会很好。