日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

springboot 2.3_Spring Boot 应用监控,早发现早

發布時間:2024/7/23 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 springboot 2.3_Spring Boot 应用监控,早发现早 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

小Hub領讀:

服務都需要監控,SpringBoot項目中,你常用哪些監控模塊呢?actuator?admin?


作者:小小____

https://segmentfault.com/a/1190000022945443

當一個 Spring Boot 應用運行的時候,開發者需要對 Spring Boot 應用進行實時監控,獲得項目的報警需求,Spring Boot 提供了,actuator 來幫助開發者獲取應用程序運行時的數據。

在 Spring Boot 中添加端點配置相當的簡單。
只需要添加 spring-boot-starter-actuator
添加相關的依賴

org.springframework.bootspring-boot-starter-actuator2.3.1.RELEASE

常用的端點如下:

常用端點列舉如下,可以一個個詳細試一下:

/info        應用基本信息
/health       健康度信息
/metrics      運行指標
/env        環境變量信息
/loggers      日志相關
/dump       線程相關信息
/trace       請求調用軌跡

這些端點大都是默認開啟的,如果想要開啟一個端點,需要在配置文件中,配置以下內容。

endpoints:
metrics:
sensitive: false

此時 sensitive 是關閉的。

舉個例子:
這里舉個例子,訪問是否在線的接口

localhost:8080/actuator/health

此時瀏覽器的輸出結果為:

端點響應緩存

對于一些不帶參數的端點將會進行緩存。搜索公眾號:MarkerHub,關注回復[vue]獲取前后端入門教程!

management:
endpoint:
auditevents:
cache:
time-to-live: 100s

上方的配置說明了緩存達到 100s

路徑映射

可以對訪問的路徑進行映射。

management:
endpoints:
web:
base-path: /
path-mapping:
health: healthcheck

此時訪問路徑由原先的 localhost:8080/actuator/health 轉變為 localhost:8080/healthcheck

CORS

進行跨域操作。
可以通過配置文件,快速的開啟 CORS 支持。

management:
endpoints:
web:
cors:
allowed-origins: http:
allowed-methods: *

在上方中,允許處理,來自 http://localhost:8091 的任何請求,允許的方法任意。

添加相關的依賴。

de.codecentricspring-boot-admin-starter-server2.2.3

在啟動類上增加相關的注解:

package com.example.demo;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableAdminServer
public class DemoApplication {

public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}

}

配置完成以后,輸入鏈接,進行訪問。

http:

再次添加 client 端

de.codecentricspring-boot-admin-starter-client2.2.3

書寫配置文件

spring:
boot:
admin:
client:
url: http:

此時查看 admin


查看其健康度


(完)

好文章!點個在看!

總結

以上是生活随笔為你收集整理的springboot 2.3_Spring Boot 应用监控,早发现早的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。