軟件需求: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監控設置完成