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

软件需求:git

jdk8+github

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

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

 

第一步:markdown

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

<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>

 

第二步:jvm

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

#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

 

第三步:3d

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

而后再启动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监控设置完成

相关文章
相关标签/搜索