欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Spring Boot使用Druid進行維度的統(tǒng)計和監(jiān)控

 更新時間:2017年04月28日 15:09:34   作者:u014427391  
這篇文章主要介紹了Spring Boot使用Druid進行維度的統(tǒng)計和監(jiān)控,非常不錯,具有參考借鑒價值,需要的朋友可以參考下

Druid

Druid:一款為監(jiān)控而生的數(shù)據(jù)庫連接池框架,整個項目由數(shù)據(jù)庫連接池、插件框架和SQL解析器組成。

Druid功能介于PowerDrill和Dremel之間,它幾乎實現(xiàn)了Dremel的所有功能,并且從PowerDrill吸收一些有趣的數(shù)據(jù)格式。Druid允許以類似Dremel和PowerDrill的方式進行單表查詢,同時還增加了一些新特性,如為局部嵌套數(shù)據(jù)結(jié)構(gòu)提供列式存儲格式、為快速過濾做索引、實時攝取和查詢、高容錯的分布式體系架構(gòu)等。

Spring Boot

spring框架作為JavaEE框架領(lǐng)域的一款重要的開源框架,在企業(yè)應(yīng)用開發(fā)中有著很重要的作用,同時Spring框架及其子框架很多,所以知識量很廣。

Spring Boot:一款Spring框架的子框架,也可以叫微框架,是2014年推出的一款使Spring框架開發(fā)變得容易的框架。學過Spring框架的都知識,Spring框架難以避免地需要配置不少XMl,而使用Spring Boot框架的話,就可以使用注解開發(fā),極大地簡化基于Spring框架的開發(fā)。

Spring Boot充分利用了JavaConfig的配置模式以及“約定優(yōu)于配置”的理念,能夠極大的簡化基于Spring MVC的Web應(yīng)用和REST服務(wù)開發(fā)。

然后通過本文給大家介紹基于IDEA編輯器的Spring Boot項目創(chuàng)建和部署。

Spring Boot使用Druid監(jiān)控

maven配置

要配置spring Boot實現(xiàn)一個Demo的話,只要加入spring-boot-starter(核心模塊)和spring-boot-starter-web(因為這個一個Web項目),可以參考我的配置,這里使用了Spring Boot熱部署,需要去github上搜索jar:springloaded-1.2.4.RELEASE.jar,然后下載放在項目的lib文件夾里,可以參考我的配置

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.example</groupId>
 <artifactId>demo</artifactId>
 <packaging>war</packaging>
 <version>1.0-SNAPSHOT</version>
 <name>demo Maven Webapp</name>
 <properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  <java.version>1.8</java.version>
  <druid.version>1.0.24</druid.version>
  <mysql.version>5.1.27</mysql.version>
  <spring-boot-admin.version>1.4.5</spring-boot-admin.version>
 </properties>
 <parent>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-parent</artifactId>
  <version>1.5.1.RELEASE</version>
  <relativePath/>
 </parent>
 <dependencies>
  <dependency>
   <groupId>junit</groupId>
   <artifactId>junit</artifactId>
   <version>3.8.1</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-test</artifactId>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>de.codecentric</groupId>
   <artifactId>spring-boot-admin-starter-client</artifactId>
   <version>${spring-boot-admin.version}</version>
  </dependency>
  <dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter</artifactId>
  </dependency>
  <dependency>
   <groupId>com.alibaba</groupId>
   <artifactId>druid</artifactId>
   <version>${druid.version}</version>
  </dependency>
  <dependency>
   <groupId>mysql</groupId>
   <artifactId>mysql-connector-java</artifactId>
   <version>${mysql.version}</version>
  </dependency>
 </dependencies>
 <build>
  <plugins>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
   </plugin>
   <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin </artifactId>
    <dependencies>
     <!--springloaded hot deploy -->
     <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>springloaded</artifactId>
      <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/springloaded-1.2.5.RELEASE.jar</systemPath>
     </dependency>
    </dependencies>
    <executions>
     <execution>
      <goals>
       <goal>repackage</goal>
      </goals>
      <configuration>
       <classifier>exec</classifier>
      </configuration>
     </execution>
    </executions>
   </plugin>
  </plugins>
 </build>
</project>

application.properties配置

server.context-path=/springbootdemo
#數(shù)據(jù)庫訪問配置
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/myblog
spring.datasource.username=root
spring.datasource.password=root
#數(shù)據(jù)源配置,初始化大小、最小、最大
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
#連接等待超時時間
spring.datasource.maxWait=60000
#配置隔多久進行一次檢測(檢測可以關(guān)閉的空閑連接)
spring.datasource.timeBetweenEvictionRunsMillis=60000
#配置連接在池中的最小生存時間
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false
# 打開PSCache,并且指定每個連接上PSCache的大小
spring.datasource.poolPreparedStatements=true
spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
# 配置監(jiān)控統(tǒng)計攔截的filters,去掉后監(jiān)控界面sql無法統(tǒng)計,'wall'用于防火墻
spring.datasource.filters=stat,wall,log4j
# 通過connectProperties屬性來打開mergeSql功能;慢SQL記錄
spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000

方式一原生的servlet和filter方式

編寫Servlet類:

package com.example.web.servlet;
import com.alibaba.druid.support.http.StatViewServlet;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
/**
 * Created by Administrator on 2017/4/28.
 */
@WebServlet(urlPatterns = "/druid/*",
    initParams = {
        @WebInitParam(name = "allow", value = "192.168.10.25,127.0.0.1"),// IP白名單 (沒有配置或者為空,則允許所有訪問)
        @WebInitParam(name = "deny", value = "192.168.1.73"),// IP黑名單 (存在共同時,deny優(yōu)先于allow)
        @WebInitParam(name = "loginUsername", value = "admin"),// 用戶名
        @WebInitParam(name = "loginPassword", value = "123"),// 密碼
        @WebInitParam(name = "resetEnable", value = "false")// 禁用HTML頁面上的“Reset All”功能)
    }
)
public class DruidStatViewServlet extends StatViewServlet{
}

Filter類:

package com.example.web.filter;
import com.alibaba.druid.support.http.WebStatFilter;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;
/**
 * Created by Administrator on 2017/4/28.
 */
@WebFilter(filterName="druidWebStatFilter",urlPatterns="/*",
    initParams={
        @WebInitParam(name="exclusions",value="*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*")// 忽略資源
    }
)
public class DruidWebStatFilter extends WebStatFilter{
}

然后,需要在Spring Boot啟動類里設(shè)置Servlet自動掃描,不然會出現(xiàn)404頁面找不到錯誤,使用

@ServletComponentScan注解

package com;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer;
import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.scheduling.annotation.EnableAsync;
@SpringBootApplication
@ServletComponentScan
@EnableAsync
public class Application implements EmbeddedServletContainerCustomizer {
  public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
  }
  @Override
  public void customize(ConfigurableEmbeddedServletContainer configurableEmbeddedServletContainer) {
    configurableEmbeddedServletContainer.setPort(8087);
  }
}

方式二使用代碼注冊Servlet和Filter

package com.example.config;
import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
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;
/**
 * Created by Administrator on 2017/4/28.
 */
@Configuration
public class DruidConfiguration {
  /**
   * 注冊ServletRegistrationBean
   * @return
   */
  @Bean
  public ServletRegistrationBean registrationBean() {
    ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid1/*");
    /** 初始化參數(shù)配置,initParams**/
    //白名單
    bean.addInitParameter("allow", "127.0.0.1");
    //IP黑名單 (存在共同時,deny優(yōu)先于allow) : 如果滿足deny的話提示:Sorry, you are not permitted to view this page.
    bean.addInitParameter("deny", "192.168.1.73");
    //登錄查看信息的賬號密碼.
    bean.addInitParameter("loginUsername", "admin2");
    bean.addInitParameter("loginPassword", "123");
    //是否能夠重置數(shù)據(jù).
    bean.addInitParameter("resetEnable", "false");
    return bean;
  }
  /**
   * 注冊FilterRegistrationBean
   * @return
   */
  @Bean
  public FilterRegistrationBean druidStatFilter() {
    FilterRegistrationBean bean = new FilterRegistrationBean(new WebStatFilter());
    //添加過濾規(guī)則.
    bean.addUrlPatterns("/*");
    //添加不需要忽略的格式信息.
    bean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid2/*");
    return bean;
  }
}

項目監(jiān)控

然后輸入url訪問,我的項目訪問路徑:http://localhost:8087/springbootdemo/druid/login.html,這個需要自己修改,我的Context配置為springbootdemo,端口配置為8087,這些可以參考我上一篇博客

這里寫圖片描述

通過平臺進行監(jiān)控 

這里寫圖片描述

以上所述是小編給大家介紹的Spring Boot使用Druid進行維度的統(tǒng)計和監(jiān)控,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • 解決idea爆紅 cant resolve symbol String的問題解析

    解決idea爆紅 cant resolve symbol String的問題解析

    連著出差幾個禮拜沒有使用idea開發(fā)工具,突然一天打開電腦發(fā)現(xiàn)idea里的代碼全部爆紅,懵逼不如所措,很多朋友建議我按住Alt+回車設(shè)置jdk就能解決,但是仍然報錯,經(jīng)過幾個小時的倒騰最終解決,遇到此問題的朋友參考下本文吧
    2021-06-06
  • java使用des加密解密示例分享

    java使用des加密解密示例分享

    java使用des加密解密示例,適合java語言的所有平臺,與.net等平臺的加密解密兼容
    2014-02-02
  • 23種設(shè)計模式(3) java原型模式

    23種設(shè)計模式(3) java原型模式

    這篇文章主要為大家詳細介紹了23種設(shè)計模式之java原型模式,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-11-11
  • java  多線程的三種構(gòu)建方法

    java 多線程的三種構(gòu)建方法

    這篇文章主要介紹了java 多線程的三種構(gòu)建方法的相關(guān)資料,這里提供三種實現(xiàn)方法,希望大家能夠掌握,很重要的基礎(chǔ)知識,需要的朋友可以參考下
    2017-09-09
  • 詳解springcloud 基于feign的服務(wù)接口的統(tǒng)一hystrix降級處理

    詳解springcloud 基于feign的服務(wù)接口的統(tǒng)一hystrix降級處理

    這篇文章主要介紹了詳解springcloud 基于feign的服務(wù)接口的統(tǒng)一hystrix降級處理,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-06-06
  • Spring Security使用Lambda DSL配置流程詳解

    Spring Security使用Lambda DSL配置流程詳解

    Spring Security 5.2 對 Lambda DSL 語法的增強,允許使用lambda配置HttpSecurity、ServerHttpSecurity,重要提醒,之前的配置方法仍然有效。lambda的添加旨在提供更大的靈活性,但是用法是可選的。讓我們看一下HttpSecurity的lambda配置與以前的配置樣式相比
    2023-02-02
  • Java?數(shù)據(jù)庫連接池DBPool?介紹

    Java?數(shù)據(jù)庫連接池DBPool?介紹

    這篇文章主要給大家分享了Java?數(shù)據(jù)庫連接池DBPool?介紹,<BR>DBPool是一個高效的易配置的數(shù)據(jù)庫連接池。它除了支持連接池應(yīng)有的功能之外,還包括了一個對象池使你能夠開發(fā)一個滿足自已需求的數(shù)據(jù)庫連接池,下面一起來看看文章內(nèi)容的詳細介紹吧,需要的朋友可以參考一下
    2021-11-11
  • Java中數(shù)組復制的三種方式小結(jié)

    Java中數(shù)組復制的三種方式小結(jié)

    在Java中,數(shù)組復制是一種常見的操作,它允許開發(fā)人員在不修改原始數(shù)組的情況下創(chuàng)建一個新的數(shù)組,本文就來介紹三種方法,具有一定的參考價值,感興趣的可以了解一下
    2024-02-02
  • Java數(shù)據(jù)庫連接_jdbc-odbc橋連接方式(詳解)

    Java數(shù)據(jù)庫連接_jdbc-odbc橋連接方式(詳解)

    下面小編就為大家?guī)硪黄狫ava數(shù)據(jù)庫連接_jdbc-odbc橋連接方式(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08
  • 基于Protobuf動態(tài)解析在Java中的應(yīng)用 包含例子程序

    基于Protobuf動態(tài)解析在Java中的應(yīng)用 包含例子程序

    下面小編就為大家?guī)硪黄赑rotobuf動態(tài)解析在Java中的應(yīng)用 包含例子程序。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-07-07

最新評論