Spring Boot 應(yīng)用這些可視化監(jiān)控,一目了然!快來試試吧!
作者:你照亮了我的世界
blog.csdn.net/weixin_44196699/article/details/105010045
1、Spring Boot 應(yīng)用暴露監(jiān)控指標(biāo)【版本 1.5.7.RELEASE】
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
采集應(yīng)用的指標(biāo)信息,我們使用的是prometheus,相應(yīng)的我們引入包:
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient_spring_boot</artifactId> <version>0.0.26</version>
</dependency>
然后,在啟動類 Application.java 添加如下注解:
@SpringBootApplication
@EnablePrometheusEndpoint
@EnableSpringBootMetricsCollector
public class Application {
public static void main(String[] args) { SpringApplication.run(Application.class, args);
}
}
最后,配置默認(rèn)的登錄賬號和密碼,在 application.yml 中:
security:
user:
name:user
password: pwd
啟動應(yīng)用程序后,會看到如下一系列的 Mappings

利用賬號密碼訪問 http://localhost:8080/application/prometheus ,可以看到 Prometheus 格式的指標(biāo)數(shù)據(jù)

2、Prometheus 采集 Spring Boot 指標(biāo)數(shù)據(jù)
$ docker pull prom/prometheus
然后,編寫配置文件 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: /application/prometheus
scheme: http
basic_auth:
username: admin
password: 123456
static_configs:
- targets:
- 192.168.11.54:8099 #此處填寫 Spring Boot 應(yīng)用的 IP + 端口號
接著,啟動 Prometheus :
docker run -d --name prometheus -p 9090:9090
-v D:\test\actuator\prometheus\prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
請注意,
D:\test\actuator\prometheus\prometheus.yml,是我的配置文件存放地址,我們需要將它放到容器里面去,所以用了-v來做文件映射。/etc/prometheus/prometheus.yml這個是容器啟動的時候去取的默認(rèn)配置,這里我是直接覆蓋掉了它。prom/prometheus這是鏡像,如果本地沒有,就回去你設(shè)置好的鏡像倉庫去取。
啟動完成后用docker ps看下是否已經(jīng)啟動成功,之后打開瀏覽器輸入:http://localhost:9090/targets,檢查 Spring Boot 采集狀態(tài)是否正常,如果看到下圖就是成功了。

3、Grafana 可視化監(jiān)控數(shù)據(jù)
$ docker pull grafana/grafana1
然后,啟動 Grafana:
$ docker run --name grafana -d -p 3000:3000 grafana/grafana1
接著,訪問 http://localhost:3000/ 配置 Prometheus 數(shù)據(jù)源:
先配置數(shù)據(jù)源.




prometh采集的數(shù)據(jù)


一步步安裝Jumpserver堡壘機圖文詳解(官方教程版),從此爽歪歪! 零散的MySQL基礎(chǔ)總是記不???看這一篇如何拯救你 相同字符串,但是equals為false?我多年的java白學(xué)了嗎? 華為面試官:為什么 HashMap 的加載因子是0.75? 趣頭條面試題:ThreadLocal是什么?怎么用?為什么用它?有什么缺點 @Autowire和@Resource注解使用的正確姿勢,這些年我一直用錯了??! 強大:MyBatis 流式查詢 華為面試官:為什么 HashMap 的加載因子是0.75? SpringBoot+OAuth2+JWT實現(xiàn)單點登錄SSO完整教程,竟如此簡單優(yōu)雅! Springboot啟動擴展點超詳細(xì)總結(jié),再也不怕面試官問了


