java – Micrometer相当于Prometheus的标签
作者:互联网
我正在将Spring Boot应用程序从Spring Boot 1(使用Prometheus Simpleclient)转换为Spring Boot 2(使用Micrometer).
我很难将Spring Boot 1和Prometheus的标签转换为Micrometer中的概念.例如(与普罗米修斯):
private static Counter requestCounter =
Counter.build()
.name("sent_requests_total")
.labelNames("method", "path")
.help("Total number of rest requests sent")
.register();
...
requestCounter.labels(request.getMethod().name(), path).inc();
千分尺的标签似乎与普罗米修斯的标签不同:所有值都必须预先声明,而不仅仅是键.
可以使用普罗米修斯的弹簧(引导)和千分尺标签吗?
解决方法:
进一步的挖掘表明,只有微米标签的键必须预先声明 – 但构造函数确实需要成对的键/值;价值无关紧要.并且在使用度量标准时必须指定密钥.
这有效:
private static final String COUNTER_BATCHMANAGER_SENT_REQUESTS = "batchmanager.sent.requests";
private static final String METHOD_TAG = "method";
private static final String PATH_TAG = "path";
private final Counter requestCounter;
...
requestCounter = Counter.builder(COUNTER_BATCHMANAGER_SENT_REQUESTS)
.description("Total number of rest requests sent")
.tags(METHOD_TAG, "", PATH_TAG, "")
.register(meterRegistry);
...
Metrics.counter(COUNTER_BATCHMANAGER_SENT_REQUESTS, METHOD_TAG, methodName, PATH_TAG, path)
.increment();
标签:java,spring-boot-2,metrics,prometheus,micrometer 来源: https://codeday.me/bug/20190527/1162457.html