Example #1
0
  /**
   * 参数定义: com.alibaba.druid.log.LogFilter=filter com.alibaba.druid.log.LogFilter.p1=prop-value
   * com.alibaba.druid.log.LogFilter.p2=prop-value
   *
   * @param url
   * @return
   * @throws SQLException
   */
  private DataSourceProxyImpl getDataSource(String url, Properties info) throws SQLException {
    DataSourceProxyImpl dataSource = proxyDataSources.get(url);

    if (dataSource == null) {
      DataSourceProxyConfig config = parseConfig(url, info);

      Driver rawDriver = createDriver(config.getRawDriverClassName());

      DataSourceProxyImpl newDataSource = new DataSourceProxyImpl(rawDriver, config);

      {
        String property = System.getProperty("druid.filters");
        if (property != null && property.length() > 0) {
          for (String filterItem : property.split(",")) {
            FilterManager.loadFilter(config.getFilters(), filterItem);
          }
        }
      }
      {
        int dataSourceId = createDataSourceId();
        newDataSource.setId(dataSourceId);

        for (Filter filter : config.getFilters()) {
          filter.init(newDataSource);
        }
      }

      DataSourceProxy oldDataSource = proxyDataSources.putIfAbsent(url, newDataSource);
      if (oldDataSource == null) {
        if (config.isJmxOption()) {
          JMXUtils.register("com.alibaba.druid:type=JdbcStat", JdbcStatManager.getInstance());
        }
      }

      dataSource = proxyDataSources.get(url);
    }
    return dataSource;
  }
Example #2
0
  public Map<String, Object> getData() throws JMException {
    Map<String, Object> map = new HashMap<String, Object>();

    // 0 - 4
    map.put("ID", id);
    map.put("DataSource", dataSource);
    map.put("SQL", sql);
    map.put("ExecuteCount", getExecuteCount());
    map.put("ErrorCount", getErrorCount());

    // 5 - 9
    map.put("TotalTime", getExecuteMillisTotal());
    map.put("LastTime", getExecuteLastStartTime());
    map.put("MaxTimespan", getExecuteMillisMax());
    map.put("LastError", JMXUtils.getErrorCompositeData(this.getExecuteErrorLast()));
    map.put("EffectedRowCount", getUpdateCount());

    // 10 - 14
    map.put("FetchRowCount", getFetchRowCount());
    map.put("MaxTimespanOccurTime", getExecuteNanoSpanMaxOccurTime());
    map.put("BatchSizeMax", getExecuteBatchSizeMax());
    map.put("BatchSizeTotal", getExecuteBatchSizeTotal());
    map.put("ConcurrentMax", getConcurrentMax());

    // 15 -
    map.put("RunningCount", getRunningCount()); // 15
    map.put("Name", getName()); // 16
    map.put("File", getFile()); // 17

    Throwable lastError = this.executeErrorLast;
    if (lastError != null) {
      map.put("LastErrorMessage", lastError.getMessage()); // 18
      map.put("LastErrorClass", lastError.getClass().getName()); // 19

      map.put("LastErrorStackTrace", IOUtils.getStackTrace(lastError)); // 20
      map.put("LastErrorTime", new Date(executeErrorLastTime)); // 21
    } else {
      map.put("LastErrorMessage", null);
      map.put("LastErrorClass", null);
      map.put("LastErrorStackTrace", null);
      map.put("LastErrorTime", null);
    }

    map.put("DbType", dbType); // 22
    map.put("URL", null); // 23
    map.put("InTransactionCount", getInTransactionCount()); // 24

    map.put("Histogram", this.getHistogramValues()); // 25
    map.put("LastSlowParameters", lastSlowParameters); // 26
    map.put("ResultSetHoldTime", getResultSetHoldTimeMilis()); // 27
    map.put("ExecuteAndResultSetHoldTime", this.getExecuteAndResultSetHoldTimeMilis()); // 28
    map.put("FetchRowCountHistogram", this.getFetchRowCountHistogramValues()); // 29

    map.put("EffectedRowCountHistogram", this.getUpdateCountHistogramValues()); // 30
    map.put(
        "ExecuteAndResultHoldTimeHistogram",
        this.getExecuteAndResultHoldTimeHistogramValues()); // 31
    map.put("EffectedRowCountMax", getUpdateCountMax()); // 32
    map.put("FetchRowCountMax", getFetchRowCountMax()); // 33
    map.put("ClobOpenCount", getClobOpenCount()); // 34

    map.put("BlobOpenCount", getBlobOpenCount()); // 35
    map.put("ReadStringLength", getReadStringLength()); // 36
    map.put("ReadBytesLength", getReadBytesLength()); // 37
    map.put("InputStreamOpenCount", getInputStreamOpenCount()); // 38
    map.put("ReaderOpenCount", getReaderOpenCount()); // 39

    return map;
  }
Example #3
0
  public static CompositeType getCompositeType() throws JMException {

    if (COMPOSITE_TYPE != null) {
      return COMPOSITE_TYPE;
    }

    OpenType<?>[] indexTypes =
        new OpenType<?>[] {
          // 0 - 4
          SimpleType.LONG, //
          SimpleType.STRING, //
          SimpleType.STRING, //
          SimpleType.LONG, //
          SimpleType.LONG, //

          // 5 - 9
          SimpleType.LONG, //
          SimpleType.DATE, //
          SimpleType.LONG, //
          JMXUtils.getThrowableCompositeType(), //
          SimpleType.LONG, //
          //

          // 10 - 14
          SimpleType.LONG, //
          SimpleType.DATE, //
          SimpleType.LONG, //
          SimpleType.LONG, //
          SimpleType.LONG, //
          //

          // 15 - 19
          SimpleType.LONG, //
          SimpleType.STRING, //
          SimpleType.STRING, //
          SimpleType.STRING, //
          SimpleType.STRING, //
          //

          // 20 - 24
          SimpleType.STRING, //
          SimpleType.DATE, //
          SimpleType.STRING, //
          SimpleType.LONG, //
          SimpleType.STRING, //

          // 25 - 29
          new ArrayType<Long>(SimpleType.LONG, true), //
          SimpleType.STRING, //
          SimpleType.LONG, //
          SimpleType.LONG, //
          new ArrayType<Long>(SimpleType.LONG, true), //

          // 30 - 34
          new ArrayType<Long>(SimpleType.LONG, true), //
          new ArrayType<Long>(SimpleType.LONG, true), //
          SimpleType.LONG, //
          SimpleType.LONG, //
          SimpleType.LONG, //

          // 35 -
          SimpleType.LONG, //
          SimpleType.LONG, //
          SimpleType.LONG, //
          SimpleType.LONG, //
          SimpleType.LONG, //
        };

    String[] indexNames = {
      // 0 - 4
      "ID", //
      "DataSource", //
      "SQL", //
      "ExecuteCount", //
      "ErrorCount", //

      // 5 - 9
      "TotalTime", //
      "LastTime", //
      "MaxTimespan", //
      "LastError", //
      "EffectedRowCount", //

      // 10 - 14
      "FetchRowCount", //
      "MaxTimespanOccurTime", //
      "BatchSizeMax", //
      "BatchSizeTotal", //
      "ConcurrentMax", //

      // 15 - 19
      "RunningCount", //
      "Name", //
      "File", //
      "LastErrorMessage", //
      "LastErrorClass", //

      // 20 - 24
      "LastErrorStackTrace", //
      "LastErrorTime", //
      "DbType", //
      "InTransactionCount", //
      "URL", //

      // 25 - 29
      "Histogram", //
      "LastSlowParameters", //
      "ResultSetHoldTime", //
      "ExecuteAndResultSetHoldTime", //
      "FetchRowCountHistogram", //

      // 30 - 34
      "EffectedRowCountHistogram", //
      "ExecuteAndResultHoldTimeHistogram", //
      "EffectedRowCountMax", //
      "FetchRowCountMax", //
      "ClobOpenCount",

      // 35 -
      "BlobOpenCount", //
      "ReadStringLength", //
      "ReadBytesLength", //
      "InputStreamOpenCount", //
      "ReaderOpenCount", //

      //
    };
    String[] indexDescriptions = indexNames;
    COMPOSITE_TYPE =
        new CompositeType(
            "SqlStatistic", "Sql Statistic", indexNames, indexDescriptions, indexTypes);

    return COMPOSITE_TYPE;
  }