[英]Push metrics to Prometheus Pushgateway in Spring Boot
[英]Dynamic metric counter in spring boot - prometheus pushgateway
我有一個 json 格式的傳入事件(到 spring 啟動應用程序),其中包含一個名為“組件”的字段。 我需要創建一個指標計數器並按組件推送到 prometheus pushgateway。 每種類型的組件都應該有單獨的計數器。 如何實現這一目標?
您可以為此實現組件。 Autowire MeterRegistry
private MeterRegistry registry;
並把櫃台地圖放在里面。
private Map<String, Counter> counters = new ConcurrentHashMap<>();
添加方法:
public void increment(String componentName){
Counter counter = counters.get(componentName);
if(counter == null) {
counter = Counter.builder("your.metrics.name").tags("component", componentName).register(registry);
counters.put(tagValue, counter);
}
counter.increment();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.