增强监控

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@336 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-07-01 01:52:18 +00:00
parent ab783dd8fa
commit 98fa9ae97e
7 changed files with 128 additions and 72 deletions
@@ -46,7 +46,7 @@ public class DruidDriver implements Driver, DruidDriverMBean {
private final static DruidDriver instance = new DruidDriver();
private final static ConcurrentMap<String, DataSourceProxyImpl> dataSources = new ConcurrentHashMap<String, DataSourceProxyImpl>();
private final static ConcurrentMap<String, DataSourceProxyImpl> proxyDataSources = new ConcurrentHashMap<String, DataSourceProxyImpl>();
private final static AtomicInteger dataSourceIdSeed = new AtomicInteger(0);
public final static String DEFAULT_PREFIX = "jdbc:wrap-jdbc:";
@@ -128,7 +128,7 @@ public class DruidDriver implements Driver, DruidDriverMBean {
* @throws SQLException
*/
private DataSourceProxyImpl getDataSource(String url, Properties info) throws SQLException {
DataSourceProxyImpl dataSource = dataSources.get(url);
DataSourceProxyImpl dataSource = proxyDataSources.get(url);
if (dataSource == null) {
String restUrl = url.substring(DEFAULT_PREFIX.length());
@@ -193,7 +193,7 @@ public class DruidDriver implements Driver, DruidDriverMBean {
DataSourceProxyImpl newDataSource = new DataSourceProxyImpl(rawDriver, config);
DataSourceProxy oldDataSource = dataSources.putIfAbsent(url, newDataSource); // 多线程处理需要
DataSourceProxy oldDataSource = proxyDataSources.putIfAbsent(url, newDataSource); // 多线程处理需要
if (oldDataSource == null) {
// 放进去的线程负责初始化
int dataSourceId = createDataSourceId();
@@ -208,7 +208,7 @@ public class DruidDriver implements Driver, DruidDriverMBean {
}
}
dataSource = dataSources.get(url);
dataSource = proxyDataSources.get(url);
}
return dataSource;
}
@@ -264,10 +264,10 @@ public class DruidDriver implements Driver, DruidDriverMBean {
@Override
public String[] getDataSourceUrls() {
return dataSources.keySet().toArray(new String[dataSources.size()]);
return proxyDataSources.keySet().toArray(new String[proxyDataSources.size()]);
}
public static ConcurrentMap<String, DataSourceProxyImpl> getDataSources() {
return dataSources;
public static ConcurrentMap<String, DataSourceProxyImpl> getProxyDataSources() {
return proxyDataSources;
}
}
@@ -28,11 +28,7 @@ import java.util.Properties;
import java.util.concurrent.atomic.AtomicLong;
import javax.management.JMException;
import javax.management.openmbean.ArrayType;
import javax.management.openmbean.CompositeDataSupport;
import javax.management.openmbean.CompositeType;
import javax.management.openmbean.OpenType;
import javax.management.openmbean.SimpleType;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
@@ -41,6 +37,7 @@ import com.alibaba.druid.filter.FilterChain;
import com.alibaba.druid.filter.FilterChainImpl;
import com.alibaba.druid.filter.stat.StatFilter;
import com.alibaba.druid.stat.JdbcDataSourceStat;
import com.alibaba.druid.stat.JdbcStatManager;
import com.alibaba.druid.util.JdbcUtils;
/**
@@ -179,49 +176,6 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
return properties.toString();
}
private static CompositeType COMPOSITE_TYPE = null;
public static CompositeType getCompositeType() throws JMException {
if (COMPOSITE_TYPE != null) {
return COMPOSITE_TYPE;
}
OpenType<?>[] indexTypes = new OpenType<?>[] { //
SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, new ArrayType<SimpleType<String>>(SimpleType.STRING, false), SimpleType.DATE, //
SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.STRING //
, SimpleType.LONG, SimpleType.INTEGER, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG //
, SimpleType.DATE, SimpleType.LONG, SimpleType.DATE, SimpleType.STRING, SimpleType.STRING //
, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.LONG, SimpleType.INTEGER //
, SimpleType.INTEGER, SimpleType.LONG, SimpleType.LONG, SimpleType.DATE, SimpleType.STRING //
, SimpleType.STRING, SimpleType.LONG, SimpleType.INTEGER, SimpleType.DATE, SimpleType.LONG //
, SimpleType.LONG, SimpleType.INTEGER, SimpleType.INTEGER, SimpleType.LONG, SimpleType.DATE //
, SimpleType.LONG, SimpleType.LONG, SimpleType.DATE, SimpleType.STRING, SimpleType.STRING //
, SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG, SimpleType.INTEGER //
, SimpleType.LONG, SimpleType.DATE, SimpleType.LONG, SimpleType.LONG
//
};
String[] indexNames = { "ID", "URL", "Name", "FilterClasses", "CreatedTime", //
"RawUrl", "RawDriverClassName", "RawDriverMajorVersion", "RawDriverMinorVersion", "Properties" //
, "ConnectionActiveCount", "ConnectionActiveCountMax", "ConnectionCloseCount", "ConnectionCommitCount", "ConnectionRollbackCount" //
, "ConnectionConnectLastTime", "ConnectionConnectErrorCount", "ConnectionConnectErrorLastTime", "ConnectionConnectErrorLastMessage", "ConnectionConnectErrorLastStackTrace" //
, "StatementCreateCount", "StatementPrepareCount", "StatementPreCallCount", "StatementExecuteCount", "StatementRunningCount" //
, "StatementConcurrentMax", "StatementCloseCount", "StatementErrorCount", "StatementLastErrorTime", "StatementLastErrorMessage" //
, "StatementLastErrorStackTrace", "StatementExecuteMillis", "ConnectionConnectingCount", "StatementExecuteLastTime", "ResultSetCloseCount" //
, "ResultSetOpenCount", "ResultSetOpenningCount", "ResultSetOpenningMax", "ResultSetFetchRowCount", "ResultSetLastOpenTime" //
, "ResultSetErrorCount", "ResultSetOpenningMillisTotal", "ResultSetLastErrorTime", "ResultSetLastErrorMessage", "ResultSetLastErrorStackTrace"
, "ConnectionConnectCount", "ConnectionErrorLastMessage", "ConnectionErrorLastStackTrace", "ConnectionConnectMillisTotal", "ConnectionConnectingCountMax" //
, "ConnectionConnectMillisMax", "ConnectionErrorLastTime", "ConnectionAliveMillisMax", "ConnectionAliveMillisMin"
//
};
String[] indexDescriptions = indexNames;
COMPOSITE_TYPE = new CompositeType("DataSourceStatistic", "DataSource Statistic", indexNames, indexDescriptions, indexTypes);
return COMPOSITE_TYPE;
}
public CompositeDataSupport getCompositeData() throws JMException {
StatFilter statFilter = null;
JdbcDataSourceStat stat = null;
@@ -391,7 +345,7 @@ public class DataSourceProxyImpl implements DataSourceProxy, DataSourceProxyImpl
map.put("ConnectionAliveMillisMin", null);
}
return new CompositeDataSupport(getCompositeType(), map);
return new CompositeDataSupport(JdbcStatManager.getDataSourceCompositeType(), map);
}
@Override