mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge pull request #4278 from digitalsonic/master
日志相关过滤器与HA的ZooKeeper逻辑优化
This commit is contained in:
@@ -122,11 +122,37 @@ public abstract class LogFilter extends FilterEventAdapter implements LogFilterM
|
||||
statementExecutableSqlLogEnable = false;
|
||||
}
|
||||
}
|
||||
{
|
||||
String prop = properties.getProperty("druid.log.conn.logError");
|
||||
if ("false".equals(prop)) {
|
||||
connectionLogErrorEnabled = false;
|
||||
} else if ("true".equals(prop)) {
|
||||
connectionLogErrorEnabled = true;
|
||||
}
|
||||
}
|
||||
{
|
||||
String prop = properties.getProperty("druid.log.stmt.logError");
|
||||
if ("false".equals(prop)) {
|
||||
statementLogErrorEnabled = false;
|
||||
} else if ("true".equals(prop)) {
|
||||
statementLogErrorEnabled = true;
|
||||
}
|
||||
}
|
||||
{
|
||||
String prop = properties.getProperty("druid.log.rs.logError");
|
||||
if ("false".equals(prop)) {
|
||||
resultSetLogErrorEnabled = false;
|
||||
} else if ("true".equals(prop)) {
|
||||
resultSetLogErrorEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(DataSourceProxy dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
configFromProperties(dataSource.getConnectProperties());
|
||||
configFromProperties(System.getProperties());
|
||||
}
|
||||
|
||||
public boolean isConnectionLogErrorEnabled() {
|
||||
|
||||
@@ -61,35 +61,38 @@ import com.alibaba.druid.support.profile.Profiler;
|
||||
*/
|
||||
public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
private final static Log LOG = LogFactory.getLog(StatFilter.class);
|
||||
private final static Log LOG = LogFactory.getLog(StatFilter.class);
|
||||
|
||||
private static final String SYS_PROP_LOG_SLOW_SQL = "druid.stat.logSlowSql";
|
||||
private static final String SYS_PROP_SLOW_SQL_MILLIS = "druid.stat.slowSqlMillis";
|
||||
private static final String SYS_PROP_MERGE_SQL = "druid.stat.mergeSql";
|
||||
private static final String SYS_PROP_LOG_SLOW_SQL = "druid.stat.logSlowSql";
|
||||
private static final String SYS_PROP_SLOW_SQL_MILLIS = "druid.stat.slowSqlMillis";
|
||||
private static final String SYS_PROP_SLOW_SQL_LOG_LEVEL = "druid.stat.slowSqlLogLevel";
|
||||
private static final String SYS_PROP_MERGE_SQL = "druid.stat.mergeSql";
|
||||
|
||||
public final static String ATTR_NAME_CONNECTION_STAT = "stat.conn";
|
||||
public final static String ATTR_TRANSACTION = "stat.tx";
|
||||
public final static String ATTR_NAME_CONNECTION_STAT = "stat.conn";
|
||||
public final static String ATTR_TRANSACTION = "stat.tx";
|
||||
|
||||
private final Lock lock = new ReentrantLock();
|
||||
private final Lock lock = new ReentrantLock();
|
||||
|
||||
// protected JdbcDataSourceStat dataSourceStat;
|
||||
|
||||
@Deprecated
|
||||
protected final JdbcStatementStat statementStat = JdbcStatManager.getInstance().getStatementStat();
|
||||
protected final JdbcStatementStat statementStat = JdbcStatManager.getInstance().getStatementStat();
|
||||
|
||||
@Deprecated
|
||||
protected final JdbcResultSetStat resultSetStat = JdbcStatManager.getInstance().getResultSetStat();
|
||||
protected final JdbcResultSetStat resultSetStat = JdbcStatManager.getInstance().getResultSetStat();
|
||||
|
||||
private boolean connectionStackTraceEnable = false;
|
||||
private boolean connectionStackTraceEnable = false;
|
||||
|
||||
// 3 seconds is slow sql
|
||||
protected long slowSqlMillis = 3 * 1000;
|
||||
protected long slowSqlMillis = 3 * 1000;
|
||||
|
||||
protected boolean logSlowSql = false;
|
||||
protected boolean logSlowSql = false;
|
||||
|
||||
protected String slowSqlLogLevel = "ERROR";
|
||||
|
||||
private DbType dbType;
|
||||
|
||||
private boolean mergeSql = false;
|
||||
private boolean mergeSql = false;
|
||||
|
||||
public StatFilter(){
|
||||
}
|
||||
@@ -138,6 +141,14 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
this.mergeSql = mergeSql;
|
||||
}
|
||||
|
||||
public String getSlowSqlLogLevel() {
|
||||
return slowSqlLogLevel;
|
||||
}
|
||||
|
||||
public void setSlowSqlLogLevel(String slowSqlLogLevel) {
|
||||
this.slowSqlLogLevel = slowSqlLogLevel;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String mergeSql(String sql) {
|
||||
return this.mergeSql(sql, dbType);
|
||||
@@ -210,6 +221,19 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
this.logSlowSql = false;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
String property = properties.getProperty(SYS_PROP_SLOW_SQL_LOG_LEVEL);
|
||||
if ("error".equalsIgnoreCase(property)) {
|
||||
this.slowSqlLogLevel = "ERROR";
|
||||
} else if ("warn".equalsIgnoreCase(property)) {
|
||||
this.slowSqlLogLevel = "WARN";
|
||||
} else if ("info".equalsIgnoreCase(property)) {
|
||||
this.slowSqlLogLevel = "INFO";
|
||||
} else if ("debug".equalsIgnoreCase(property)) {
|
||||
this.slowSqlLogLevel = "DEBUG";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException {
|
||||
@@ -484,7 +508,20 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
String lastExecSql = statement.getLastExecuteSql();
|
||||
if (logSlowSql) {
|
||||
LOG.error("slow sql " + millis + " millis. " + lastExecSql + "" + slowParameters);
|
||||
String msg = "slow sql " + millis + " millis. " + lastExecSql + "" + slowParameters;
|
||||
switch (slowSqlLogLevel) {
|
||||
case "WARN":
|
||||
LOG.warn(msg);
|
||||
break;
|
||||
case "INFO":
|
||||
LOG.info(msg);
|
||||
break;
|
||||
case "DEBUG":
|
||||
LOG.debug(msg);
|
||||
break;
|
||||
default:
|
||||
LOG.error(msg);
|
||||
}
|
||||
}
|
||||
|
||||
handleSlowSql(statement);
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.apache.curator.framework.recipes.cache.ChildData;
|
||||
import org.apache.curator.framework.recipes.cache.PathChildrenCache;
|
||||
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
|
||||
import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;
|
||||
import org.apache.curator.retry.ExponentialBackoffRetry;
|
||||
import org.apache.curator.retry.RetryForever;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
@@ -88,9 +88,9 @@ public class ZookeeperNodeListener extends NodeListener {
|
||||
if (client == null) {
|
||||
client = CuratorFrameworkFactory.builder()
|
||||
.canBeReadOnly(true)
|
||||
.connectionTimeoutMs(3000)
|
||||
.connectionTimeoutMs(5000)
|
||||
.connectString(zkConnectString)
|
||||
.retryPolicy(new ExponentialBackoffRetry(5000, 3, 30000))
|
||||
.retryPolicy(new RetryForever(10000))
|
||||
.sessionTimeoutMs(30000)
|
||||
.build();
|
||||
client.start();
|
||||
|
||||
@@ -20,7 +20,7 @@ import com.alibaba.druid.support.logging.LogFactory;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
import org.apache.curator.framework.recipes.nodes.GroupMember;
|
||||
import org.apache.curator.retry.ExponentialBackoffRetry;
|
||||
import org.apache.curator.retry.RetryForever;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
@@ -49,9 +49,9 @@ public class ZookeeperNodeRegister {
|
||||
public void init() {
|
||||
if (client == null) {
|
||||
client = CuratorFrameworkFactory.builder()
|
||||
.connectionTimeoutMs(3000)
|
||||
.connectionTimeoutMs(5000)
|
||||
.connectString(zkConnectString)
|
||||
.retryPolicy(new ExponentialBackoffRetry(5000, 3, 30000))
|
||||
.retryPolicy(new RetryForever(10000))
|
||||
.sessionTimeoutMs(30000)
|
||||
.build();
|
||||
client.start();
|
||||
|
||||
Reference in New Issue
Block a user