为了账号安全,请及时绑定邮箱和手机立即绑定

如何在非 Spring Boot 应用程序中设置普罗米修斯端点

如何在非 Spring Boot 应用程序中设置普罗米修斯端点

喵喵时光机 2021-09-12 15:32:00
我想向我的应用程序添加一个路径“localhost:8080/metrics”,以便Counter使用 Prometheus查看我的变量。我读到了一个 spring 启动应用程序,我需要主类上的唯一注释。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@EnableSpringBootMetricsCollectorpublic class Application {    public static void main(String[] args) {        SpringApplication.run(Application.class, args);    }}如何在没有@SpringBootApplication.可以通过注册多个servlet来实现吗?
查看完整描述

1 回答

?
慕仙森

TA贡献1827条经验 获得超8个赞

您可能希望将 Prometheus servlet 添加到您的应用程序中。


我将给出文档中引用的 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。


查看完整回答
反对 回复 2021-09-12
  • 1 回答
  • 0 关注
  • 116 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信