我已经在一个千分尺方法中检测了我的代码,如下所示:
SimpleMeterRegistry registry = new SimpleMeterRegistry();
Gauge
.builder("greeting_service_gauge", new AtomicInteger(new Random().nextInt(10)), AtomicInteger::get)
.register(registry);
我还添加了一些其他指标。
其他指标会出现在 prometheus 端点上,但此仪表指标不会。
我在这里遗漏了什么?
答案 0 :(得分:0)
您正在将仪表注册到 public class MyContextLocator implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
System.out.println("Inside setApplicationContext");
applicationContext = context;
}
public static ApplicationContext getApplicationContext() {
return applicationContext;
}
}
。相反,您应该将指标注册到 Prometheus 注册表(或 CompositeMeterRegistry)
如果这是一个 Spring 项目,您可以注入 SimpleMeterRegistry
。或者使用全局 MeterRegistry
来获取复合的。
Metrics.globalRegistry