我为Prometheus和Actuactor添加了依赖项:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
<version>${micrometer-registry-prometheus.version}</version>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>${micrometer-registry-prometheus.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>
但是,如果我转到端点 / actuator / promehteus ,即使我也从Spring中添加了 log4j2 依赖关系,也无法使用 log4j2_events_total 指标启动启动器,我是否为此缺少一些其他配置?
答案 0 :(得分:1)
尝试一下,我创建了一个新项目,并且在添加以下依赖项后为我工作。确保添加 spring-boot-starter-web 依赖性,并从中排除 spring-boot-starter-logging ,以避免SLF4J: Class path contains multiple SLF4J bindings.
错误。
<!-- ########################################### -->
<!-- spring Management dependencies for Actuator -->
<!-- ########################################### -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<!-- ####################### -->
<!-- log4j dependencies -->
<!-- ####################### -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Add Log4j2 Dependency -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
您可以在以下位置找到示例项目:- https://github.com/ishivesh/demo-processor