格式化并增加sandzhang提交后StatViewServlet缺失的方法。

This commit is contained in:
septer
2012-08-10 14:46:04 +08:00
parent aa9a3e51e2
commit 9e2aa378a8
6 changed files with 308 additions and 269 deletions
@@ -16,189 +16,187 @@ import com.alibaba.druid.pool.DruidDataSource;
public class DruidDataSourceStatDefaultStrategy implements DruidDataSourceStatStrategy {
private Set<DruidDataSource> getDruidDataSourceInstances() {
return DruidDataSourceStatManager.getDruidDataSourceInstances();
}
private Set<DruidDataSource> getDruidDataSourceInstances() {
return DruidDataSourceStatManager.getDruidDataSourceInstances();
}
public void resetDataSourceStat() {
DruidDataSourceStatManager.getInstance().reset();
}
public void resetDataSourceStat() {
DruidDataSourceStatManager.getInstance().reset();
}
public void resetSqlStat() {
JdbcStatManager.getInstance().reset();
}
public void resetSqlStat() {
JdbcStatManager.getInstance().reset();
}
public void resetAll() {
resetSqlStat();
resetDataSourceStat();
}
public void resetAll() {
resetSqlStat();
resetDataSourceStat();
}
private JdbcSqlStat getSqlStatById(Integer id) {
public JdbcSqlStat getSqlStatById(Integer id) {
for (DruidDataSource ds : getDruidDataSourceInstances()) {
JdbcSqlStat sqlStat = ds.getDataSourceStat().getSqlStat(id);
if (sqlStat != null) return sqlStat;
}
return null;
}
for (DruidDataSource ds : getDruidDataSourceInstances()) {
JdbcSqlStat sqlStat = ds.getDataSourceStat().getSqlStat(id);
if (sqlStat != null)
return sqlStat;
}
return null;
}
public Map<String, Object> getDataSourceStatData(Integer id) {
if (id == null) {
return null;
}
DruidDataSource datasource = getDruidDataSourceById(id);
return datasource == null ? null : dataSourceToMapData(datasource);
}
public Map<String, Object> getDataSourceStatData(Integer id) {
if (id == null) {
return null;
}
DruidDataSource datasource = getDruidDataSourceById(id);
return datasource == null ? null : dataSourceToMapData(datasource);
}
public DruidDataSource getDruidDataSourceById(Integer identity) {
if (identity == null) {
return null;
}
private DruidDataSource getDruidDataSourceById(Integer identity) {
for (DruidDataSource datasource : getDruidDataSourceInstances()) {
if (System.identityHashCode(datasource) == identity) {
return datasource;
}
}
return null;
}
if (identity == null) {
return null;
}
public List<Map<String, Object>> getSqlStatDataList() {
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
for (DruidDataSource datasource : getDruidDataSourceInstances()) {
for (JdbcSqlStat sqlStat : datasource.getDataSourceStat().getSqlStatMap().values()) {
if (sqlStat.getExecuteCount() == 0 && sqlStat.getRunningCount() == 0) {
continue;
}
for (DruidDataSource datasource : getDruidDataSourceInstances()) {
if (System.identityHashCode(datasource) == identity) {
return datasource;
}
}
return null;
}
result.add(getSqlStatData(sqlStat));
}
}
return result;
}
public List<Map<String, Object>> getSqlStatDataList() {
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
for (DruidDataSource datasource : getDruidDataSourceInstances()) {
for (JdbcSqlStat sqlStat : datasource.getDataSourceStat().getSqlStatMap().values()) {
if (sqlStat.getExecuteCount() == 0 && sqlStat.getRunningCount() == 0) {
continue;
}
public Map<String, Object> getSqlStatData(Integer id) {
if (id == null) {
return null;
}
JdbcSqlStat sqlStat = getSqlStatById(id);
return sqlStat == null ? null : getSqlStatData(sqlStat);
}
result.add(getSqlStatData(sqlStat));
}
}
return result;
}
private Map<String, Object> getSqlStatData(JdbcSqlStat sqlStat) {
try {
return sqlStat.getData();
} catch (JMException e) {
}
return null;
}
public Map<String, Object> getSqlStatData(Integer id) {
if (id == null) {
return null;
}
JdbcSqlStat sqlStat = getSqlStatById(id);
return sqlStat == null ? null : getSqlStatData(sqlStat);
}
public List<Object> getDataSourceStatList() {
List<Object> datasourceList = new ArrayList<Object>();
for (DruidDataSource dataSource : getDruidDataSourceInstances()) {
datasourceList.add(dataSourceToMapData(dataSource));
}
return datasourceList;
}
private Map<String, Object> getSqlStatData(JdbcSqlStat sqlStat) {
try {
return sqlStat.getData();
} catch (JMException e) {
}
return null;
}
public Map<String, Object> returnJSONBasicStat() {
Map<String, Object> dataMap = new LinkedHashMap<String, Object>();
dataMap.put("Version", VERSION.getVersionNumber());
dataMap.put("Drivers", getDriversData());
return dataMap;
}
public List<Object> getDataSourceStatList() {
List<Object> datasourceList = new ArrayList<Object>();
for (DruidDataSource dataSource : getDruidDataSourceInstances()) {
datasourceList.add(dataSourceToMapData(dataSource));
}
return datasourceList;
}
private List<String> getDriversData() {
List<String> drivers = new ArrayList<String>();
for (Enumeration<Driver> e = DriverManager.getDrivers(); e.hasMoreElements();) {
Driver driver = e.nextElement();
drivers.add(driver.getClass().getName());
}
return drivers;
}
public Map<String, Object> returnJSONBasicStat() {
Map<String, Object> dataMap = new LinkedHashMap<String, Object>();
dataMap.put("Version", VERSION.getVersionNumber());
dataMap.put("Drivers", getDriversData());
return dataMap;
}
public List<Map<String, Object>> getPoolingConnectionInfoByDataSourceId(Integer id) {
DruidDataSource datasource = getDruidDataSourceById(id);
if (datasource == null) return null;
return datasource.getPoolingConnectionInfo();
}
private List<String> getDriversData() {
List<String> drivers = new ArrayList<String>();
for (Enumeration<Driver> e = DriverManager.getDrivers(); e.hasMoreElements();) {
Driver driver = e.nextElement();
drivers.add(driver.getClass().getName());
}
return drivers;
}
public List<String> getActiveConnectionStackTraceByDataSourceId(Integer id) {
DruidDataSource datasource = getDruidDataSourceById(id);
if (datasource == null || !datasource.isRemoveAbandoned()) return null;
public List<Map<String, Object>> getPoolingConnectionInfoByDataSourceId(Integer id) {
DruidDataSource datasource = getDruidDataSourceById(id);
if (datasource == null)
return null;
return datasource.getPoolingConnectionInfo();
}
return datasource.getActiveConnectionStackTrace();
}
public List<String> getActiveConnectionStackTraceByDataSourceId(Integer id) {
DruidDataSource datasource = getDruidDataSourceById(id);
if (datasource == null || !datasource.isRemoveAbandoned())
return null;
private Map<String, Object> dataSourceToMapData(DruidDataSource dataSource) {
return datasource.getActiveConnectionStackTrace();
}
Map<String, Object> dataMap = new LinkedHashMap<String, Object>();
dataMap.put("Identity", System.identityHashCode(dataSource));
dataMap.put("Name", dataSource.getName());
dataMap.put("DbType", dataSource.getDbType());
dataMap.put("DriverClassName", dataSource.getDriverClassName());
private Map<String, Object> dataSourceToMapData(DruidDataSource dataSource) {
dataMap.put("URL", dataSource.getUrl());
dataMap.put("UserName", dataSource.getUsername());
dataMap.put("FilterClassNames", dataSource.getFilterClassNames());
Map<String, Object> dataMap = new LinkedHashMap<String, Object>();
dataMap.put("Identity", System.identityHashCode(dataSource));
dataMap.put("Name", dataSource.getName());
dataMap.put("DbType", dataSource.getDbType());
dataMap.put("DriverClassName", dataSource.getDriverClassName());
dataMap.put("WaitThreadCount", dataSource.getWaitThreadCount());
dataMap.put("NotEmptyWaitCount", dataSource.getNotEmptyWaitCount());
dataMap.put("NotEmptyWaitMillis", dataSource.getNotEmptyWaitMillis());
dataMap.put("URL", dataSource.getUrl());
dataMap.put("UserName", dataSource.getUsername());
dataMap.put("FilterClassNames", dataSource.getFilterClassNames());
dataMap.put("PoolingCount", dataSource.getPoolingCount());
dataMap.put("PoolingPeak", dataSource.getPoolingPeak());
dataMap.put("PoolingPeakTime",
dataSource.getPoolingPeakTime() == null ? null : dataSource.getPoolingPeakTime().toString());
dataMap.put("WaitThreadCount", dataSource.getWaitThreadCount());
dataMap.put("NotEmptyWaitCount", dataSource.getNotEmptyWaitCount());
dataMap.put("NotEmptyWaitMillis", dataSource.getNotEmptyWaitMillis());
dataMap.put("ActiveCount", dataSource.getActiveCount());
dataMap.put("ActivePeak", dataSource.getActivePeak());
dataMap.put("ActivePeakTime",
dataSource.getActivePeakTime() == null ? null : dataSource.getActivePeakTime().toString());
dataMap.put("PoolingCount", dataSource.getPoolingCount());
dataMap.put("PoolingPeak", dataSource.getPoolingPeak());
dataMap.put("PoolingPeakTime", dataSource.getPoolingPeakTime() == null ? null : dataSource.getPoolingPeakTime().toString());
dataMap.put("InitialSize", dataSource.getInitialSize());
dataMap.put("MinIdle", dataSource.getMinIdle());
dataMap.put("MaxActive", dataSource.getMaxActive());
dataMap.put("ActiveCount", dataSource.getActiveCount());
dataMap.put("ActivePeak", dataSource.getActivePeak());
dataMap.put("ActivePeakTime", dataSource.getActivePeakTime() == null ? null : dataSource.getActivePeakTime().toString());
dataMap.put("QueryTimeout", dataSource.getQueryTimeout());
dataMap.put("TransactionQueryTimeout", dataSource.getTransactionQueryTimeout());
dataMap.put("LoginTimeout", dataSource.getLoginTimeout());
dataMap.put("ValidConnectionCheckerClassName", dataSource.getValidConnectionCheckerClassName());
dataMap.put("ExceptionSorterClassName", dataSource.getExceptionSorterClassName());
dataMap.put("InitialSize", dataSource.getInitialSize());
dataMap.put("MinIdle", dataSource.getMinIdle());
dataMap.put("MaxActive", dataSource.getMaxActive());
dataMap.put("TestOnBorrow", dataSource.isTestOnBorrow());
dataMap.put("TestOnReturn", dataSource.isTestOnReturn());
dataMap.put("TestWhileIdle", dataSource.isTestWhileIdle());
dataMap.put("QueryTimeout", dataSource.getQueryTimeout());
dataMap.put("TransactionQueryTimeout", dataSource.getTransactionQueryTimeout());
dataMap.put("LoginTimeout", dataSource.getLoginTimeout());
dataMap.put("ValidConnectionCheckerClassName", dataSource.getValidConnectionCheckerClassName());
dataMap.put("ExceptionSorterClassName", dataSource.getExceptionSorterClassName());
dataMap.put("DefaultAutoCommit", dataSource.isDefaultAutoCommit());
dataMap.put("DefaultReadOnly", dataSource.isDefaultAutoCommit());
dataMap.put("DefaultTransactionIsolation", dataSource.getDefaultTransactionIsolation());
dataMap.put("TestOnBorrow", dataSource.isTestOnBorrow());
dataMap.put("TestOnReturn", dataSource.isTestOnReturn());
dataMap.put("TestWhileIdle", dataSource.isTestWhileIdle());
dataMap.put("LogicConnectCount", dataSource.getConnectCount());
dataMap.put("LogicCloseCount", dataSource.getCloseCount());
dataMap.put("LogicConnectErrorCount", dataSource.getConnectErrorCount());
dataMap.put("DefaultAutoCommit", dataSource.isDefaultAutoCommit());
dataMap.put("DefaultReadOnly", dataSource.isDefaultAutoCommit());
dataMap.put("DefaultTransactionIsolation", dataSource.getDefaultTransactionIsolation());
dataMap.put("PhysicalConnectCount", dataSource.getCreateCount());
dataMap.put("PhysicalCloseCount", dataSource.getDestroyCount());
dataMap.put("PhysicalConnectErrorCount", dataSource.getCreateErrorCount());
dataMap.put("LogicConnectCount", dataSource.getConnectCount());
dataMap.put("LogicCloseCount", dataSource.getCloseCount());
dataMap.put("LogicConnectErrorCount", dataSource.getConnectErrorCount());
dataMap.put("ExecuteCount", dataSource.getExecuteCount());
dataMap.put("ErrorCount", dataSource.getErrorCount());
dataMap.put("CommitCount", dataSource.getCommitCount());
dataMap.put("RollbackCount", dataSource.getRollbackCount());
dataMap.put("PhysicalConnectCount", dataSource.getCreateCount());
dataMap.put("PhysicalCloseCount", dataSource.getDestroyCount());
dataMap.put("PhysicalConnectErrorCount", dataSource.getCreateErrorCount());
dataMap.put("PSCacheAccessCount", dataSource.getCachedPreparedStatementAccessCount());
dataMap.put("PSCacheHitCount", dataSource.getCachedPreparedStatementHitCount());
dataMap.put("PSCacheMissCount", dataSource.getCachedPreparedStatementMissCount());
dataMap.put("ExecuteCount", dataSource.getExecuteCount());
dataMap.put("ErrorCount", dataSource.getErrorCount());
dataMap.put("CommitCount", dataSource.getCommitCount());
dataMap.put("RollbackCount", dataSource.getRollbackCount());
dataMap.put("StartTransactionCount", dataSource.getStartTransactionCount());
dataMap.put("TransactionHistogram", dataSource.getTransactionHistogramValues());
dataMap.put("PSCacheAccessCount", dataSource.getCachedPreparedStatementAccessCount());
dataMap.put("PSCacheHitCount", dataSource.getCachedPreparedStatementHitCount());
dataMap.put("PSCacheMissCount", dataSource.getCachedPreparedStatementMissCount());
dataMap.put("ConnectionHoldTimeHistogram",
dataSource.getDataSourceStat().getConnectionHoldHistogram().toArray());
dataMap.put("RemoveAbandoned", dataSource.isRemoveAbandoned());
dataMap.put("StartTransactionCount", dataSource.getStartTransactionCount());
dataMap.put("TransactionHistogram", dataSource.getTransactionHistogramValues());
dataMap.put("ConnectionHoldTimeHistogram", dataSource.getDataSourceStat().getConnectionHoldHistogram().toArray());
dataMap.put("RemoveAbandoned", dataSource.isRemoveAbandoned());
return dataMap;
}
return dataMap;
}
}
@@ -3,60 +3,73 @@ package com.alibaba.druid.stat;
import java.util.List;
import java.util.Map;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.alibaba.druid.util.ReflectionUtils;
public class DruidDataSourceStatJNDIStatStrategy implements DruidDataSourceStatStrategy{
private final static Log LOG = LogFactory.getLog(DruidDataSourceStatJNDIStatStrategy.class);
public class DruidDataSourceStatJNDIStatStrategy implements DruidDataSourceStatStrategy {
private Object getStrategyB() {
try {
Class<?> clazz = ReflectionUtils.getClassFromWebContainerOrCurrentClassLoader("com.alibaba.druid.stat.DruidDataSourceStatDefaultStrategy");
return clazz.newInstance();
} catch (Exception e) {
LOG.error(e.getMessage(), e);
return null;
}
}
private final static Log LOG = LogFactory.getLog(DruidDataSourceStatJNDIStatStrategy.class);
@SuppressWarnings("unchecked")
public Map<String, Object> getSqlStatData(Integer id) {
return (Map<String, Object>) ReflectionUtils.callObjectMethod(getStrategyB(), "getSqlStatData", id);
}
private Object getStatDefaultStrategy() {
try {
Class<?> clazz = ReflectionUtils.getClassFromWebContainerOrCurrentClassLoader("com.alibaba.druid.stat.DruidDataSourceStatDefaultStrategy");
return clazz.newInstance();
} catch (Exception e) {
LOG.error(e.getMessage(), e);
return null;
}
}
@SuppressWarnings("unchecked")
public List<Map<String, Object>> getSqlStatDataList() {
return (List<Map<String, Object>>) ReflectionUtils.callObjectMethod(getStrategyB(), "getSqlStatDataList");
}
@SuppressWarnings("unchecked")
public Map<String, Object> getSqlStatData(Integer id) {
return (Map<String, Object>) ReflectionUtils.callObjectMethod(getStatDefaultStrategy(), "getSqlStatData", id);
}
@SuppressWarnings("unchecked")
public List<String> getActiveConnectionStackTraceByDataSourceId(Integer id) {
return (List<String>) ReflectionUtils.callObjectMethod(getStrategyB(), "getActiveConnectionStackTraceByDataSourceId", id);
}
@SuppressWarnings("unchecked")
public List<Map<String, Object>> getSqlStatDataList() {
return (List<Map<String, Object>>) ReflectionUtils.callObjectMethod(getStatDefaultStrategy(), "getSqlStatDataList");
}
@SuppressWarnings("unchecked")
public Map<String, Object> returnJSONBasicStat() {
return (Map<String, Object>) ReflectionUtils.callObjectMethod(getStrategyB(), "returnJSONBasicStat");
}
@SuppressWarnings("unchecked")
public List<String> getActiveConnectionStackTraceByDataSourceId(Integer id) {
return (List<String>) ReflectionUtils.callObjectMethod(getStatDefaultStrategy(),
"getActiveConnectionStackTraceByDataSourceId", id);
}
@SuppressWarnings("unchecked")
public List<Object> getDataSourceStatList() {
return (List<Object>) ReflectionUtils.callObjectMethod(getStrategyB(), "getDataSourceStatList");
}
@SuppressWarnings("unchecked")
public Map<String, Object> returnJSONBasicStat() {
return (Map<String, Object>) ReflectionUtils.callObjectMethod(getStatDefaultStrategy(), "returnJSONBasicStat");
}
@SuppressWarnings("unchecked")
public Map<String, Object> getDataSourceStatData(Integer id) {
return (Map<String, Object>) ReflectionUtils.callObjectMethod(getStrategyB(), "getDataSourceStatData", id);
}
@SuppressWarnings("unchecked")
public List<Object> getDataSourceStatList() {
return (List<Object>) ReflectionUtils.callObjectMethod(getStatDefaultStrategy(), "getDataSourceStatList");
}
@SuppressWarnings("unchecked")
public List<Map<String, Object>> getPoolingConnectionInfoByDataSourceId(Integer id) {
return (List<Map<String, Object>>) ReflectionUtils.callObjectMethod(getStrategyB(), "getPoolingConnectionInfoByDataSourceId", id);
}
@SuppressWarnings("unchecked")
public Map<String, Object> getDataSourceStatData(Integer id) {
return (Map<String, Object>) ReflectionUtils.callObjectMethod(getStatDefaultStrategy(), "getDataSourceStatData", id);
}
public void resetAll() {
ReflectionUtils.callObjectMethod(getStrategyB(), "resetAll");
}
@SuppressWarnings("unchecked")
public List<Map<String, Object>> getPoolingConnectionInfoByDataSourceId(Integer id) {
return (List<Map<String, Object>>) ReflectionUtils.callObjectMethod(getStatDefaultStrategy(),
"getPoolingConnectionInfoByDataSourceId",
id);
}
public void resetAll() {
ReflectionUtils.callObjectMethod(getStatDefaultStrategy(), "resetAll");
}
public DruidDataSource getDruidDataSourceById(Integer id) {
return (DruidDataSource) ReflectionUtils.callObjectMethod(getStatDefaultStrategy(), "getDruidDataSourceById");
}
public JdbcSqlStat getSqlStatById(Integer id) {
return (JdbcSqlStat) ReflectionUtils.callObjectMethod(getStatDefaultStrategy(), "getSqlStatById", id);
}
}
@@ -3,20 +3,27 @@ package com.alibaba.druid.stat;
import java.util.List;
import java.util.Map;
import com.alibaba.druid.pool.DruidDataSource;
public interface DruidDataSourceStatStrategy {
public Map<String, Object> getSqlStatData(Integer id);
public List<Map<String, Object>> getSqlStatDataList();
public Map<String, Object> getSqlStatData(Integer id);
public List<String> getActiveConnectionStackTraceByDataSourceId(Integer id);
public List<Map<String, Object>> getSqlStatDataList();
public Map<String, Object> returnJSONBasicStat();
public List<String> getActiveConnectionStackTraceByDataSourceId(Integer id);
public List<Object> getDataSourceStatList();
public Map<String, Object> returnJSONBasicStat();
public Map<String, Object> getDataSourceStatData(Integer id);
public List<Object> getDataSourceStatList();
public List<Map<String, Object>> getPoolingConnectionInfoByDataSourceId(Integer id);
public Map<String, Object> getDataSourceStatData(Integer id);
public void resetAll();
public List<Map<String, Object>> getPoolingConnectionInfoByDataSourceId(Integer id);
public void resetAll();
public DruidDataSource getDruidDataSourceById(Integer id);
public JdbcSqlStat getSqlStatById(Integer id);
}
@@ -3,42 +3,54 @@ package com.alibaba.druid.stat;
import java.util.List;
import java.util.Map;
import com.alibaba.druid.pool.DruidDataSource;
public class DruidDataSourceStatStrategyContext {
private DruidDataSourceStatStrategy druidDataSourceStatStrategy;
public DruidDataSourceStatStrategyContext(DruidDataSourceStatStrategy druidDataSourceStatStrategy) {
this.druidDataSourceStatStrategy = druidDataSourceStatStrategy;
}
private DruidDataSourceStatStrategy druidDataSourceStatStrategy;
public Map<String, Object> getSqlStatData(Integer id) {
return druidDataSourceStatStrategy.getSqlStatData(id);
}
public DruidDataSourceStatStrategyContext(DruidDataSourceStatStrategy druidDataSourceStatStrategy){
this.druidDataSourceStatStrategy = druidDataSourceStatStrategy;
}
public List<Map<String, Object>> getSqlStatDataList() {
return druidDataSourceStatStrategy.getSqlStatDataList();
}
public Map<String, Object> getSqlStatData(Integer id) {
return druidDataSourceStatStrategy.getSqlStatData(id);
}
public List<String> getActiveConnectionStackTraceByDataSourceId(Integer id) {
return druidDataSourceStatStrategy.getActiveConnectionStackTraceByDataSourceId(id);
}
public List<Map<String, Object>> getSqlStatDataList() {
return druidDataSourceStatStrategy.getSqlStatDataList();
}
public Map<String, Object> returnJSONBasicStat() {
return druidDataSourceStatStrategy.returnJSONBasicStat();
}
public List<String> getActiveConnectionStackTraceByDataSourceId(Integer id) {
return druidDataSourceStatStrategy.getActiveConnectionStackTraceByDataSourceId(id);
}
public List<Object> getDataSourceStatList() {
return druidDataSourceStatStrategy.getDataSourceStatList();
}
public Map<String, Object> returnJSONBasicStat() {
return druidDataSourceStatStrategy.returnJSONBasicStat();
}
public Map<String, Object> getDataSourceStatData(Integer id) {
return druidDataSourceStatStrategy.getDataSourceStatData(id);
}
public List<Object> getDataSourceStatList() {
return druidDataSourceStatStrategy.getDataSourceStatList();
}
public List<Map<String, Object>> getPoolingConnectionInfoByDataSourceId(Integer id) {
return druidDataSourceStatStrategy.getPoolingConnectionInfoByDataSourceId(id);
}
public Map<String, Object> getDataSourceStatData(Integer id) {
return druidDataSourceStatStrategy.getDataSourceStatData(id);
}
public List<Map<String, Object>> getPoolingConnectionInfoByDataSourceId(Integer id) {
return druidDataSourceStatStrategy.getPoolingConnectionInfoByDataSourceId(id);
}
public void resetAll() {
druidDataSourceStatStrategy.resetAll();
}
public DruidDataSource getDruidDataSourceById(Integer id) {
return druidDataSourceStatStrategy.getDruidDataSourceById(id);
}
public JdbcSqlStat getSqlStatById(Integer id) {
return druidDataSourceStatStrategy.getSqlStatById(id);
}
public void resetAll() {
druidDataSourceStatStrategy.resetAll();
}
}
@@ -3,6 +3,8 @@ package com.alibaba.druid.stat;
import java.util.List;
import java.util.Map;
import com.alibaba.druid.pool.DruidDataSource;
/**
* 监控相关的对外数据暴露
*
@@ -15,53 +17,61 @@ import java.util.Map;
*/
public class DruidStatManagerFacade {
private final static DruidStatManagerFacade instance = new DruidStatManagerFacade();
private final static DruidStatManagerFacade instance = new DruidStatManagerFacade();
private static DruidDataSourceStatStrategyContext ctx = null;
private static DruidDataSourceStatStrategyContext ctx = null;
private static DruidDataSourceStatStrategy strategy = null;
private static DruidDataSourceStatStrategy strategy = null;
static {
strategy = new DruidDataSourceStatJNDIStatStrategy();
ctx = new DruidDataSourceStatStrategyContext(strategy);
}
static {
strategy = new DruidDataSourceStatJNDIStatStrategy();
ctx = new DruidDataSourceStatStrategyContext(strategy);
}
private DruidStatManagerFacade() {
}
private DruidStatManagerFacade(){
}
public static DruidStatManagerFacade getInstance() {
return instance;
}
public static DruidStatManagerFacade getInstance() {
return instance;
}
public Map<String, Object> getSqlStatData(Integer id) {
return ctx.getSqlStatData(id);
}
public Map<String, Object> getSqlStatData(Integer id) {
return ctx.getSqlStatData(id);
}
public List<Map<String, Object>> getSqlStatDataList() {
return ctx.getSqlStatDataList();
}
public List<Map<String, Object>> getSqlStatDataList() {
return ctx.getSqlStatDataList();
}
public List<String> getActiveConnectionStackTraceByDataSourceId(Integer id) {
return ctx.getActiveConnectionStackTraceByDataSourceId(id);
}
public List<String> getActiveConnectionStackTraceByDataSourceId(Integer id) {
return ctx.getActiveConnectionStackTraceByDataSourceId(id);
}
public Map<String, Object> returnJSONBasicStat() {
return ctx.returnJSONBasicStat();
}
public Map<String, Object> returnJSONBasicStat() {
return ctx.returnJSONBasicStat();
}
public List<Object> getDataSourceStatList() {
return ctx.getDataSourceStatList();
}
public List<Object> getDataSourceStatList() {
return ctx.getDataSourceStatList();
}
public Map<String, Object> getDataSourceStatData(Integer id) {
return ctx.getDataSourceStatData(id);
}
public Map<String, Object> getDataSourceStatData(Integer id) {
return ctx.getDataSourceStatData(id);
}
public List<Map<String, Object>> getPoolingConnectionInfoByDataSourceId(Integer id) {
return ctx.getPoolingConnectionInfoByDataSourceId(id);
}
public List<Map<String, Object>> getPoolingConnectionInfoByDataSourceId(Integer id) {
return ctx.getPoolingConnectionInfoByDataSourceId(id);
}
public void resetAll() {
ctx.resetAll();
}
public void resetAll() {
ctx.resetAll();
}
public DruidDataSource getDruidDataSourceById(Integer id) {
return ctx.getDruidDataSourceById(id);
}
public JdbcSqlStat getSqlStatById(Integer id) {
return ctx.getSqlStatById(id);
}
}
@@ -37,7 +37,7 @@ public class StatViewServlet extends HttpServlet {
private static JSONDruidStatService jsonDruidStatService = JSONDruidStatService.getInstance();
public String templatePage;
private static DateFormat format = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss:SSS");
private static DateFormat format = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss:SSS");
public void init() throws ServletException {
try {
@@ -134,7 +134,7 @@ public class StatViewServlet extends HttpServlet {
content.append("</textarea><br />");
content.append("<p>API:com.alibaba.druid.sql.SQLUtils.format(sql,DBType);</p>");
content.append("<br />");
if (sqlStat.getLastSlowParameters() != null && sqlStat.getLastSlowParameters().trim().length() > 0) {
content.append("<h2>LastSlow SQL View:</h2>");
content.append("<table cellpadding='5' cellspacing='1' width='99%'>");
@@ -149,7 +149,7 @@ public class StatViewServlet extends HttpServlet {
content.append("</table>");
content.append("<br />");
}
List<SQLStatement> statementList = SQLUtils.parseStatements(sqlStat.getSql(), sqlStat.getDbType());
if (!statementList.isEmpty()) {
content.append("<h2>Parse View:</h2>");
@@ -214,4 +214,3 @@ public class StatViewServlet extends HttpServlet {
return templatePage.replaceAll("\\{title\\}", title).replaceAll("\\{content\\}", content);
}
}