使用prometheus+grafana监控springboot2项目jvm情况

你。 提交于 2019-11-27 16:01:28

软件需求:

jdk8+

grafana下载地址:https://grafana.com/grafana/download

prometheus下载地址:https://prometheus.io/download/

 

第一步:

mvn的pom.xml引入actuator、prometheus、micrometer

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

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

        <dependency>
            <groupId>io.github.mweirauch</groupId>
            <artifactId>micrometer-jvm-extras</artifactId>
            <version>0.1.2</version>
        </dependency>

 

第二步:

在application.properties配置中,添加prometheus相关配置

#prometheus配置
management.metrics.export.prometheus.enabled=true
management.metrics.export.prometheus.step=1ms
management.metrics.export.prometheus.descriptions=true

management.endpoint.prometheus.enabled=true
management.endpoints.web.exposure.include=health,info,env,prometheus,metrics,httptrace,threaddump,heapdump,springmetrics

 

第三步:

修改prometheus.yml,添加job添加下面代码,其中xxx替换为项目启动路径。

然后再启动prometheus,访问http://localhost:9090,查看targets启动是否正常如下图

  - job_name: 'actuator-demo'
    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    metrics_path: '/xxx/xxx/prometheus'
    static_configs:
    - targets: ['localhost:8888']

 

 

第四步:安装Grafana,默认启动后Grafana地址为:http://localhost:3000/,登录用户名和密码是admin/admin,配置prometheus为database如下图一所示,import配置grafana id = 4701jvm使用情况面板如图二

                                                                                                       (图一)

                                                                                    (图二)

第五步:

查看项目jvm启动情况,到此jvm监控设置完成

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!