在github 上下載springboot 項目地址:
https://github.com/hgwz/jmeter-springboot-server
1在springboot項目中配置prometheus 的依賴
在pom.xml 文件依賴如下:
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.github.mweirauch</groupId>
<artifactId>micrometer-jvm-extras</artifactId>
<version>0.1.2</version>
</dependency>
2在application中加入如下配置
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
3重啟下springboot項目加載配置項
4在瀏覽器中輸入http://localhost:8089/actuator/prometheus 查看是否有對應的數據,如果有說明配置成功
5配置prometheus 的jvm信息節點
信息如下:
- job_name: 'prometheus1'
metrics_path: '/actuator/prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:8089']
這里特別注意 metrics_path 后面的信息值必須要有空格 ,否則prometheus 啟動報錯
重啟下prometheus
在瀏覽器中輸入http://localhost:9090/targets
可以查看對應配置節點信息
在grafana中展示prometheus 采集的數據點
啟動garafana,然后在瀏覽器中輸入localhost:3000
輸入用戶名密碼(admin/admin)
dashboard 直接導入9568 或者去官網查詢
按照條件查找到的結果9568
在garafana中配置prometheus 的數據源
到這基本配置結束