软件需求:
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监控设置完成