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

软件需求:

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

 

f75076a488100ffeb7bbfa39ecfbbd06d22.jpg

 

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

c84ee92d405cc9bcb40ecfe924fd2a70147.jpg

                                                                                                       (图一)

a582a1c3879d811204c25d7e578e0f5f650.jpg

                                                                                    (图二)

第五步:

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

2a0e6cad84e53108e7dab36027408bde979.jpg

转载于:https://my.oschina.net/u/1017791/blog/3047490

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值