use of com.alibaba.druid.pool.DruidDataSourceStatValue in project druid by alibaba.
the class MonitorClient method collectSql.
@SuppressWarnings("resource")
public void collectSql() {
if ((!collectSqlEnable) && !collectSqlWallEnable) {
return;
}
Set<Object> dataSources = DruidDataSourceStatManager.getInstances().keySet();
List<DruidDataSourceStatValue> statValueList = new ArrayList<DruidDataSourceStatValue>(dataSources.size());
List<WallProviderStatValue> wallStatValueList = new ArrayList<WallProviderStatValue>();
for (Object item : dataSources) {
if (!(item instanceof DruidDataSource)) {
continue;
}
DruidDataSource dataSource = (DruidDataSource) item;
if (collectSqlEnable) {
DruidDataSourceStatValue statValue = dataSource.getStatValueAndReset();
statValueList.add(statValue);
}
if (collectSqlWallEnable) {
WallProviderStatValue wallStatValue = dataSource.getWallStatValue(true);
if (wallStatValue != null && wallStatValue.getCheckCount() > 0) {
wallStatValueList.add(wallStatValue);
}
}
}
MonitorContext ctx = createContext();
if (statValueList.size() > 0) {
dao.saveSql(ctx, statValueList);
}
if (wallStatValueList.size() > 0) {
dao.saveSqlWall(ctx, wallStatValueList);
}
}
use of com.alibaba.druid.pool.DruidDataSourceStatValue in project druid by alibaba.
the class SqlSkipCountTest method test_connectPropertiesChange.
public void test_connectPropertiesChange() throws Exception {
for (int i = 0; i < 2000; ++i) {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("select " + i);
stmt.execute();
stmt.close();
conn.close();
}
{
DruidDataSourceStatValue statValue = dataSource.getStatValueAndReset();
Assert.assertEquals(1000, statValue.getSqlList().size());
Assert.assertEquals(1000, statValue.getSqlSkipCount());
}
dataSource.setConnectionProperties("druid.stat.sql.MaxSize=2000");
for (int i = 0; i < 2000; ++i) {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("select " + i);
stmt.execute();
stmt.close();
conn.close();
}
{
DruidDataSourceStatValue statValue = dataSource.getStatValueAndReset();
Assert.assertEquals(2000, statValue.getSqlList().size());
Assert.assertEquals(0, statValue.getSqlSkipCount());
}
{
DruidDataSourceStatValue statValue = dataSource.getStatValueAndReset();
Assert.assertEquals(0, statValue.getSqlList().size());
Assert.assertEquals(0, statValue.getSqlSkipCount());
}
dataSource.setConnectionProperties("druid.stat.sql.MaxSize=2000");
for (int i = 0; i < 2000; ++i) {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("select " + i);
stmt.execute();
stmt.close();
conn.close();
}
{
DruidDataSourceStatValue statValue = dataSource.getStatValueAndReset();
Assert.assertEquals(2000, statValue.getSqlList().size());
Assert.assertEquals(0, statValue.getSqlSkipCount());
}
dataSource.setConnectionProperties("druid.stat.sql.MaxSize=100");
for (int i = 0; i < 2000; ++i) {
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement("select " + i);
stmt.execute();
stmt.close();
conn.close();
}
{
DruidDataSourceStatValue statValue = dataSource.getStatValueAndReset();
Assert.assertEquals(100, statValue.getSqlList().size());
Assert.assertEquals(1900, statValue.getSqlSkipCount());
}
{
DruidDataSourceStatValue statValue = dataSource.getStatValueAndReset();
Assert.assertEquals(0, statValue.getSqlList().size());
Assert.assertEquals(0, statValue.getSqlSkipCount());
}
}
use of com.alibaba.druid.pool.DruidDataSourceStatValue in project druid by alibaba.
the class MonitorDaoJdbcImpl method saveSql.
@Override
public void saveSql(MonitorContext ctx, List<DruidDataSourceStatValue> dataSourceList) {
save(dataSourceStatBeanInfo, ctx, dataSourceList);
for (DruidDataSourceStatValue dataSourceStatValue : dataSourceList) {
List<JdbcSqlStatValue> sqlList = dataSourceStatValue.getSqlList();
save(sqlStatBeanInfo, ctx, sqlList);
}
}
Aggregations