gpt4 book ai didi

java - Prometheus ServletRegistrationBean 在某些工作区中不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:47:49 33 4
gpt4 key购买 nike

我想监控一些应用程序,我正在使用 Prometheus。它在某些应用程序中运行良好,但是当我尝试在另一个应用程序中实现它时,我遇到了一些问题。它说:

构造函数 ServletRegistrationBean(MetricsServlet, String) 未定义

什么会导致此问题以及如何解决此问题。

这是我的课。

import java.util.Collection;

import org.springframework.boot.actuate.endpoint.PublicMetrics;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.prometheus.client.exporter.MetricsServlet;
import io.prometheus.client.hotspot.DefaultExports;
import io.prometheus.client.spring.boot.SpringBootMetricsCollector;

@Configuration
public class MonitoringConfig {

@Bean
SpringBootMetricsCollector springBootMetricsCollector(Collection<PublicMetrics> publicMetrics) {

SpringBootMetricsCollector springBootMetricsCollector = new SpringBootMetricsCollector(publicMetrics);
springBootMetricsCollector.register();

return springBootMetricsCollector;
}

@Bean
public ServletRegistrationBean servletRegistrationBean() {
DefaultExports.initialize();
return new ServletRegistrationBean(new MetricsServlet(), "/prometheus");
}

}

依赖:

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.moelholm/prometheus-spring-boot-starter -->
<dependency>
<groupId>com.moelholm</groupId>
<artifactId>prometheus-spring-boot-starter</artifactId>
<version>1.0.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.0.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient_hotspot -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_hotspot</artifactId>
<version>0.0.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient_spring_boot -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId>
<version>0.0.25</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient_servlet -->
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_servlet</artifactId>
<version>0.0.25</version>
</dependency>

在某些应用程序中它可以工作,但在一个应用程序中我使用了这个:

构造函数 ServletRegistrationBean(MetricsServlet, String) 未定义

最佳答案

MetricsServlet 应该实现 javax.servlet.Servlet 。确保您的项目/类路径中有该类(即 javax.servlet.Servlet)。包含此类的库的 Maven 依赖项是:

<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>

关于java - Prometheus ServletRegistrationBean 在某些工作区中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49528497/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com