Prometheus 指标不提供路径变量值

Prometheus metrics not give path variable values

来自 spring 引导应用程序的代码示例,它正在生成普罗米修斯指标。

我正在尝试使用 http://localhost:8080/myApi/ABC 访问它。

但在普罗米修斯指标中,它生成的指标为 "uri=/myApi/{refNum}"

Promotheus 指标:

my_example_api_seconds{application="my-application",exception="None", method="GET", outcome="SUCCESS",status="200",uri="/myApi/{refNum}",quantile="0.3",} 14.495514624

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;    
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.spring.autoconfigure.MeterRegistryCustomizer;

@Configuration
public class BeansConfiguration {
@Bean
    MeterRegistryCustomizer<MeterRegistry> meterRegistryMeterRegistryCustomizer(MeterRegistry meterRegistry) {
        return meterRegistry1 -> {
            meterRegistry.config().commonTags("application","my-application");
        };
    }
}

控制器:

import io.micrometer.core.annotation.Timed;
import io.micrometer.core.instrument.MeterRegistry;

   @Timed(
            value="my.example.api",
            percentiles = {0.30,0.50,0.95,0.99}
    )
    @GetMapping(value = "myApi/{refNum}")
    public ResponseEntity<String> fun(@NotNull @PathVariable("refNum") String refNum) {
     ...
    }

Pom.xml

<properties>
  <micrometer.version>1.2.0</micrometer.version>
  <prometheus.registry.version>1.2.0</prometheus.registry.version>
</properties>
<dependencies>
  <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-spring-legacy</artifactId>
            <version>${micrometer.version}</version>
  </dependency>

  <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
            <version>${prometheus.registry.version}</version>
  </dependency>
  <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
            <version>${prometheus.registry.version}</version>
  </dependency>
  <dependency>
            <groupId>io.prometheus</groupId>
            <artifactId>simpleclient_pushgateway</artifactId>
            <version>0.8.0</version>
  </dependency>
</dependencies>

它正在按设计工作。

假设您有一个 @GetMapping(value = "user/{userId}")

的用户端点

如果您要调用 user/1user/2,一直到 user/1000000,您可能希望指标系统记录 1 个指标,所有调用的总计时对于那个单一端点。

要记录单个调用,您需要添加日志消息,而不是度量框架。