来自 Spring Boot 应用程序的代码示例,它正在生成普罗米修斯指标。
我正在尝试使用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>