我想向我的應用程序添加一個路徑“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。
添加回答
舉報
0/150
提交
取消
