千分尺相当于普罗米修斯的标签

Rei*_*der 4 java metrics spring-boot prometheus micrometer

我正在将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();
Run Code Online (Sandbox Code Playgroud)

千分尺的标签似乎与普罗米修斯的标签不同:所有都必须预先声明,而不仅仅是.

可以使用普罗米修斯的弹簧(引导)和千分尺标签吗?

Rei*_*der 9

进一步的挖掘表明,只有微米标签的必须预先声明 - 但构造函数确实需要成对的键/值; 价值无关紧要.并且在使用度量标准时必须指定密钥.

这有效:

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();
Run Code Online (Sandbox Code Playgroud)

  • 千分尺的标签与普罗米修斯的钥匙/标签相同.与Prometheus将度量标准注册为静态变量的要求相比,Micrometer可以避免这种情况.作为回报,您可以同时声明键/标签.因此,如果您愿意,可以避免第一个"空"度量标准声明,并保留第二个"Metrics.counter"调用.如果你想保留描述,可以将`register`调用内联.在这种情况下,千分尺是宽容的(与Prometheus相比),实际上Prometheus对标签的查找方式大致相同. (4认同)