美文网首页
springboot+dubbo+druid(监控)

springboot+dubbo+druid(监控)

作者: paperss | 来源:发表于2018-05-31 16:59 被阅读0次

一.部署dubbo-admin后台(便于观察)
1.安装/启动zookeeper(略),注意规避8080端口(一些版本的zookeeper启动后会占用8080,网上有解决办法)
2.下载dubbo-admin(地址https://github.com/apache/incubator-dubbo-ops)
3.进入dubbo-admin下运行maven指令打包:mvn package -Dmaven.skip.test=true

dubbo-admin-war.PNG
4.将dubbo-admin-2.0.0.war丢入tomcat(D:\dev\apache-tomcat-8.0.46\webapps),启动后,在..\apache-tomcat-8.0.46\webapps中会生产dubbo-admin-2.0.0的文件夹
image.png
5.访问http://127.0.0.1:8082/dubbo-admin-2.0.0/, 账号/密码: root/root
image.png

二. 项目创建和环境搭建
1.https://www.jianshu.com/p/6361a670ebf7
2.https://www.jianshu.com/p/0837b48d1691

三.整合druid数据源(->mysql)
参考:https://www.cnblogs.com/hlhdidi/p/6350306.html
https://blog.csdn.net/qq_34531925/article/details/78904897 (Druid数据库配置详细介绍)
https://www.cnblogs.com/softidea/p/6071630.html
1.在boot-dubbo-provider模块下的pom.xml中添加依赖

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.10</version>
</dependency>

2.Druid数据源配置

server:
  port: 8071
  context-path: /
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/mytest?useUnicode=true&characterEncoding=UTF-8
    username: root
    password:
    driver-class-name: com.mysql.jdbc.Driver
    platform: mysql
    initialSize: 5
    minIdle: 5
    maxActive: 20
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 300000
    validationQuery: SELECT 1 FROM DUAL
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    poolPreparedStatements: true
    maxPoolPreparedStatementPerConnectionSize: 20
    filters: stat,wall,log4j
    connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
    useGlobalDataSourceStat: true
mybatis:
  mapper-locations: ['mapper/*.xml']

3.建立DruidConfiguration配置类,配置过滤信息(配置完,数据库连接池便实现)

@Configuration
@ConditionalOnClass(value = {MapperScannerConfigurer.class,     
DataSourceTransactionManager.class})
@EnableTransactionManagement(proxyTargetClass = true)
public class MysqlDBConfig {
  @Autowired
  @Qualifier("mysqlDB")
  private DataSource ds;
  @Bean(name = "mysqlDB")
  @ConfigurationProperties(prefix = "spring.datasource")
  public DataSource dataSource() {
      return       
 DataSourceBuilder.create().type(com.alibaba.druid.pool.DruidDataSource.class).build();
   }
 }

4.配置数据库监控
4.1 依赖

     <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>4.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <version>2.0.1.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <version>9.0.6</version>
    </dependency>

4.2 在MysqlDBConfig中新增方法

import javax.sql.DataSource;

import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.http.WebStatFilter;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
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 org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * 
* @ClassName: OracleDBConfig  
* @Description: oracle数据源配置  
* @author liyang  
* @date 2018年5月4日  
*
 */
@Configuration
@ConditionalOnClass(value = {MapperScannerConfigurer.class, DataSourceTransactionManager.class})
@EnableTransactionManagement(proxyTargetClass = true)
public class MysqlDBConfig {

    @Autowired
    @Qualifier("mysqlDB")
    private DataSource ds;

    @Bean(name = "mysqlDB")
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource dataSource() {
        return DataSourceBuilder.create().type(com.alibaba.druid.pool.DruidDataSource.class).build();
    }

    /**
     * druid 监控
     * @return
     */
    @Bean
    public ServletRegistrationBean statViewServle(){
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(),"/druid/*");
        //白名单:
//        servletRegistrationBean.addInitParameter("allow","192.168.1.218,127.0.0.1");
        //IP黑名单 (存在共同时,deny优先于allow) : 如果满足deny的即提示:Sorry, you are not permitted to view this page.
//        servletRegistrationBean.addInitParameter("deny","192.168.1.100");
        //登录查看信息的账号密码.
        servletRegistrationBean.addInitParameter("loginUsername","druid");
        servletRegistrationBean.addInitParameter("loginPassword","12345678");
        //是否能够重置数据.
        servletRegistrationBean.addInitParameter("resetEnable","false");
        return servletRegistrationBean;
    }

    /**
     * druid 监控
     * @return
     */
    @Bean
    public FilterRegistrationBean statFilter(){
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
        //添加过滤规则.
        filterRegistrationBean.addUrlPatterns("/*");
        //添加不需要忽略的格式信息.
        filterRegistrationBean.addInitParameter("exclusions","*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*");
        return filterRegistrationBean;
    }

}

4.3 启动后访问:

码云地址: https://gitee.com/googelchrome/boot-dubbo

相关文章

  • springboot+dubbo+druid(监控)

    一.部署dubbo-admin后台(便于观察)1.安装/启动zookeeper(略),注意规避8080端口(一些版...

  • 监控系统选型Prometheus、TICK、Open-falco

    监控系统选型 Prometheus监控场景: 业务监控、性能监控、容器监控、微服务监控、部分应用监控(能够做的应用...

  • 话说PMC

    PMC过程域是监控PP的执行,计划什么就监控什么。监控一般分为日常监控(每日)、周监控、月监控与里程碑监控。监控的...

  • 前端监控体系建设

    前端监控体系主要分为错误监控、性能监控、业务监控及安全监控三个方面。 一、错误监控 (一)监控范围 js语法错误、...

  • zabbix监控GPU所需监控项

    监控风扇 监控温度 监控内存

  • Linux监控平台介绍、zabbix监控介绍、安装zabbix(

    Linux监控平台介绍 Linux监控平台介绍 zabbix监控介绍 zabbix监控介绍zabbix监控介绍 安...

  • 可用性监控区别

    ping监控与http监控区别: 对于网站可用性监控而言:我们有HTTP监控,ping监控,dns监控。 这几个的...

  • 微服务架构(七)服务调用的监控

    服务调用的监控 监控的对象,指标,维度 监控的对象 客户端监控:功能的监控 接口的监控:接口调用情况的监控 资源监...

  • 监控主机及联网状态

    监控主机及联网状态监控目的监控方法监控思路监控实现一、监控目的掌握在线业务机器及联网的状态 二、监控方法通过采用I...

  • 前端异常监控解决方案研究

    本文出自 Tencent CDC(前端异常监控解决方案研究) 前端监控包括行为监控、异常监控、性能监控等,本文主要...

网友评论

      本文标题:springboot+dubbo+druid(监控)

      本文链接:https://www.haomeiwen.com/subject/jzoqsftx.html