久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

使用SpringBoot簡單了解Druid的監控系統的配置方法

瀏覽:5日期:2023-05-14 11:33:12

Druid 介紹

說起 Druid,大家首先想到的是阿里的 Druid 數據庫連接池 Apache Druid 具有以下特點: 亞秒級 OLAP 查詢,包括多維過濾、Ad-hoc 的屬性分組、快速聚合數據等等。

實時的數據消費,真正做到數據攝入實時、查詢結果實時。高效的多租戶能力,最高可以做到幾千用戶同時在線查詢。擴展性強,支持 PB 級數據、千億級事件快速處理,支持每秒數千查詢并發。極高的高可用保障,支持滾動升級。

Druid監控系統作用

查看慢SQL [ 可進行對 SQL 優化 ] 是否有惡意攻擊 并發時的數量 事務的提交 JDBC執行的次數 訪問時URL的監控 請求的次數等等…

下面是Druid 的監控系統首頁截圖, 只需要簡單配置就可以使用

使用SpringBoot簡單了解Druid的監控系統的配置方法

開始配置

首先創建一個SpringBoot的項目

需用引入以下幾個工具

如圖

使用SpringBoot簡單了解Druid的監控系統的配置方法

在 pom.xml 文件中引入druid連接池的依賴

<dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> <version>1.1.10</version></dependency>

resources下新創建一個在 application.yml 文件, 指定使用druid的連接池

spring: datasource: # Springboot默認會使用自帶的 HikariDataSource password: root username: root url: jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai driver-class-name: com.mysql.cj.jdbc.Driver type: com.alibaba.druid.pool.DruidDataSource # 指定使用 druid 的連接池

創建一個DruidConfig.java配置類

package com.springboot.druid.config;import com.alibaba.druid.pool.DruidDataSource;import com.alibaba.druid.support.http.StatViewServlet;import com.alibaba.druid.support.http.WebStatFilter;import org.springframework.boot.context.properties.ConfigurationProperties;import org.springframework.boot.web.servlet.FilterRegistrationBean;import org.springframework.boot.web.servlet.ServletRegistrationBean;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import java.util.Arrays;import java.util.HashMap;import java.util.Map;/** * 對 Druid 的監控配置對象注入到容器中 * Created by YongXin Xue on 2020/06/04 15:18 */@Configurationpublic class DruidConfig { /** * * @return */ @Bean // 當前類如果是組件類,對象創建時容器也會調用此方法將方法的返回值注入到容器中 @ConfigurationProperties(prefix = 'spring.datasource') // 加載配置文件中的配置設置給返回的對象 public DruidDataSource getDataSoures(){ return new DruidDataSource(); } /** * 配置一個管理后臺的Servlet [ 配置Druid的監控系統 ] * 訪問時默認會生成一個頁面 * @return */ @Bean public ServletRegistrationBean statViewServlet() { // 當前 Druid 的后臺監控系統的訪問地址 /druid/* ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), '/druid/*'); Map<String, String> initParams = new HashMap<>(); initParams.put('loginUsername', 'admin'); initParams.put('loginPassword', 'admin'); // 默認就是允許所有訪問 initParams.put('allow', ''); initParams.put('deny', '192.168.15.21');//ip黑名單 bean.setInitParameters(initParams); return bean; } /** * 配置一個web監控的filter:訪問靜態資源一定沒有sql操作 * @return */ @Bean public FilterRegistrationBean webStatFilter() { FilterRegistrationBean bean = new FilterRegistrationBean(); bean.setFilter(new WebStatFilter()); Map<String, String> initParams = new HashMap<>(); //排除過濾 initParams.put('exclusions', '*.jpg,*.avi,*.js,*.css,/druid/*'); bean.setInitParameters(initParams); bean.setUrlPatterns(Arrays.asList('/*')); return bean; }}

配置完成后, 運行主程序在瀏覽器輸入本機的地址加自己配置的tomcat端口加/druid/既可以打開druid的后臺監控系統了

如圖

使用SpringBoot簡單了解Druid的監控系統的配置方法

趕緊來寫兩行代碼測測性能吧 !!

總結

到此這篇關于使用SpringBoot簡單了解Druid的監控系統的配置方法的文章就介紹到這了,更多相關springboot druid 監控系統內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 新干县| 金塔县| 大同县| 孟州市| 长寿区| 涪陵区| 洛浦县| 栾城县| 柘荣县| 黄山市| 盖州市| 望都县| 天水市| 仁怀市| 从江县| 中牟县| 肥东县| 湟中县| 镇巴县| 东平县| 丰原市| 内黄县| 博湖县| 英山县| 博乐市| 徐水县| 商丘市| 民勤县| 宾川县| 巴林左旗| 隆安县| 客服| 蛟河市| 桑植县| 涟水县| 文登市| 广西| 常德市| 正镶白旗| 马关县| 清丰县|