作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在我的应用程序中添加一个路径“localhost:8080/metrics”,以便使用 Prometheus 查看我的变量的 Counter
。我读到,对于 spring boot 应用程序,我需要对主类进行唯一注释。
package hello;
import io.prometheus.client.spring.boot.EnablePrometheusEndpoint;
import io.prometheus.client.spring.boot.EnableSpringBootMetricsCollector;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
如何在没有 @SpringBootApplication
的非 Spring Boot 应用程序中获得相同的结果。
是否可以通过注册多个servlet来实现?
最佳答案
您可能希望将 Prometheus servlet 添加到您的应用程序中。
我将给出在 the documentation 中引用的 Jetty 服务器的示例:
Server server = new Server(1234);
ServletContextHandler context = new ServletContextHandler();
context.setContextPath("/");
server.setHandler(context);
context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
依赖关系io.prometheus.simpleclient_spring_boot
是 Spring Boot 集成。相反,您应该查看核心库 io.prometheus.simpleclient
.
关于java - 如何在非 spring boot 应用程序中设置 prometheus 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52256259/
我是一名优秀的程序员,十分优秀!