基于spring boot 基礎(chǔ)上搭建
1.先添加 pom 依賴
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId>
<version>0.1.0</version>
</dependency>
啟動(dòng)類添加注解
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
配置文件添加
# 默認(rèn)賬號(hào)密碼
managment.security.enabled=false
spring.application.name=microservice-prometheus
2.安裝prometheus
本文中安裝的為Windows 版本,如需Linux,下載鏈接:https://prometheus.io/download/
下載直接解壓即可
修改配置文件prometheus.yml
global:
scrape_interval: 10s
scrape_timeout: 10s
evaluation_interval: 10m
scrape_configs:
- job_name: spring-boot
scrape_interval: 5s
scrape_timeout: 5s
metrics_path: /prometheus
scheme: http
basic_auth:
username: user
password: pwd
static_configs:
- targets:
- 127.0.0.1:9393 #此處填寫 Spring Boot 應(yīng)用的 IP + 端口號(hào)
啟動(dòng) prometheus.exe 即可
啟動(dòng)成功后 打開http://localhost:9090/targets
即可看見(jiàn):

1563437867(1).jpg
3.安裝grafana
同上都是使用Windows版本,下載 戳:https://grafana.com/grafana/download?platform=windows
安裝就不多說(shuō)了,雙擊,選安裝地址即可
啟動(dòng)grafana:
進(jìn)入D:\grafana\grafana\bin目錄下雙擊 grafana-server.exe
啟動(dòng)后訪問(wèn):http://127.0.0.1:3000/
配置數(shù)據(jù)源:

2.png

3.png
添加一個(gè)dashboard,配置單個(gè)指標(biāo)的可視化監(jiān)控面板:

4.png
填寫指標(biāo)點(diǎn):

6.png
提示,此處填寫需要監(jiān)控的指標(biāo)不能任意填寫,只能填已有的指標(biāo)點(diǎn),具體的可以監(jiān)控的指標(biāo)在 Prometheus 的首頁(yè)看到,即 http://localhost:9090/graph

7.png
或在explore 上找到:

5.jpg
多配置幾個(gè)指標(biāo)之后,即可有如下效果:

8.jpg
到這里大概配置就結(jié)束可以使用了