当前位置: 首页 > 知识库问答 >
问题:

Prometheus UI,用于spring boot应用程序的Grafana设置

辛承
2023-03-14

我正在使用spring Boot2.0,并在POM中添加了以下依赖项

     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>

    <dependency>
        <groupId>io.micrometer</groupId>
        <artifactId>micrometer-registry-prometheus</artifactId>
    </dependency>

我的application.yml如下所示

   <dependency>  
        <groupId>io.prometheus</groupId>
        <artifactId>simpleclient_spring_boot</artifactId>
        <version>${prometheus.version}</version>
    </dependency>

    <dependency>
        <groupId>io.prometheus</groupId>
        <artifactId>simpleclient_hotspot</artifactId>
        <version>${prometheus.version}</version>
    </dependency>

    <dependency>
        <groupId>io.prometheus</groupId>
        <artifactId>simpleclient_servlet</artifactId>
        <version>${prometheus.version}</version>
    </dependency>

PS:我在谷歌上搜索了一下,尝试添加prometheus.yml,并添加类似@enableprometheusendpoint的注释,但没有任何效果,因为所有的文章都是旧的。

编辑:如果Spring Bootjar托管在不同的主机(Azure/AWS)中,prometheus.yml(metrics_path,targets)并且prometheus服务器托管在不同的主机中,则如何配置prometheus.yml(metrics_path,targets)。

共有1个答案

隗翰海
2023-03-14

如果您使用的是Spring Boot2和micrometer,则不需要添加额外的依赖项,它们是在添加Micrometer-Registry-Prometheus时导入的。如果您能够看到localhost/manage/prometheus上的度量,那么您在spring-boot端的配置是很好的。不需要再配置任何东西。

要查看《普罗米修斯》中的度量标准,您需要:

  1. 安装Prometheus服务器https://Prometheus.io/docs/Prometheus/latest/installation/
  2. 将Prometheus配置为从服务器中刮取(拉取)度量。为此,您需要通过添加一个新作业来修改Prometheus.yml文件(不要忘记在更改yml文件后重新启动Prometheus)
scrape_configs:
  - job_name: 'mySpringBoot'
    metrics_path: '/manage/prometheus'
    static_configs:
      - targets: ['springBootHost:springBootPort']

下面的步骤是直接的,在其他地方有很多文档:

 类似资料:
  • 我已经使用和Jetty在服务器(在8091)中部署了一个Java应用程序。 我需要用普罗米修斯和格拉法纳监控那个应用程序。 config.yaml 我在通常的部署中使用的部署命令:(在这个目录中,存在Jetty) 它很好用..

  • 我试图在SpringMVC中运行SpringBoot应用程序,在SpringMVCPOM中添加SpringBoot应用程序依赖项,并扫描SpringBoot包,但我面临以下问题

  • 这是我使用SpringBoot的第一天,我试图理解体系结构,因此我开始构建一个hello world应用程序: 在我的pom.xml中,在maven-shade-plugin下,我将mainClass声明如下: 文件目标是src/main/java/com/demo/helloworld.java,该文件中的代码是: 我错过了什么?

  • 我需要在Spring-boot应用程序中使用默认的ObjectMapper作为单个实例。我是否可以简单地在应用程序内部@autowire ObjectMapper(在Spring-boot应用程序中默认创建的实例)而不创建@bean(因为我不想更改ObjectMapper的任何功能) https://docs.spring.io/spring-boot/docs/current/reference

  • 设置应用程序 Nest is built with features from both ES6 and ES7 (decorators, async / await). It means, that the easiest way to start adventure with it is to use Babel or TypeScript. In this tutorial I will u

  • 完成干净的构建后,我将war文件复制到Tomcat的文件夹中。但是部署会发生两次,并且在上下文已经存在的情况下以异常结束。我错过了什么? 非常感谢您的帮助。