mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
add sqlStat column, readBytesLength & readStringLength
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package com.alibaba.druid.filter.stat;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
import java.sql.Blob;
|
||||
import java.sql.Clob;
|
||||
import java.sql.NClob;
|
||||
@@ -573,7 +574,18 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
sqlStat.addFetchRowCount(fetchRowCount);
|
||||
long stmtExecuteNano = resultSet.getStatementProxy().getLastExecuteTimeNano();
|
||||
sqlStat.addResultSetHoldTimeNano(stmtExecuteNano, nanos);
|
||||
sqlStat.addStringReadLength(resultSet.getReadStringLength());
|
||||
if (resultSet.getReadStringLength() > 0) {
|
||||
sqlStat.addStringReadLength(resultSet.getReadStringLength());
|
||||
}
|
||||
if (resultSet.getReadBytesLength() > 0) {
|
||||
sqlStat.addReadBytesLength(resultSet.getReadBytesLength());
|
||||
}
|
||||
if (resultSet.getOpenInputStreamCount() > 0) {
|
||||
sqlStat.addInputStreamOpenCount(resultSet.getOpenInputStreamCount());
|
||||
}
|
||||
if (resultSet.getOpenReaderCount() > 0) {
|
||||
sqlStat.addReaderOpenCount(resultSet.getOpenReaderCount());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -960,4 +972,76 @@ public class StatFilter extends FilterEventAdapter implements StatFilterMBean {
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream resultSet_getBinaryStream(FilterChain chain, ResultSetProxy result, int columnIndex)
|
||||
throws SQLException {
|
||||
InputStream input = chain.resultSet_getBinaryStream(result, columnIndex);
|
||||
|
||||
if (input != null) {
|
||||
result.incrementOpenInputStreamCount();
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream resultSet_getBinaryStream(FilterChain chain, ResultSetProxy result, String columnLabel)
|
||||
throws SQLException {
|
||||
InputStream input = chain.resultSet_getBinaryStream(result, columnLabel);
|
||||
|
||||
if (input != null) {
|
||||
result.incrementOpenInputStreamCount();
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream resultSet_getAsciiStream(FilterChain chain, ResultSetProxy result, int columnIndex)
|
||||
throws SQLException {
|
||||
InputStream input = chain.resultSet_getAsciiStream(result, columnIndex);
|
||||
|
||||
if (input != null) {
|
||||
result.incrementOpenInputStreamCount();
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream resultSet_getAsciiStream(FilterChain chain, ResultSetProxy result, String columnLabel)
|
||||
throws SQLException {
|
||||
InputStream input = chain.resultSet_getAsciiStream(result, columnLabel);
|
||||
|
||||
if (input != null) {
|
||||
result.incrementOpenInputStreamCount();
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader resultSet_getCharacterStream(FilterChain chain, ResultSetProxy result, int columnIndex)
|
||||
throws SQLException {
|
||||
Reader reader = chain.resultSet_getCharacterStream(result, columnIndex);
|
||||
|
||||
if (reader != null) {
|
||||
result.incrementOpenReaderCount();
|
||||
}
|
||||
|
||||
return reader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Reader resultSet_getCharacterStream(FilterChain chain, ResultSetProxy result, String columnLabel)
|
||||
throws SQLException {
|
||||
Reader reader = chain.resultSet_getCharacterStream(result, columnLabel);
|
||||
|
||||
if (reader != null) {
|
||||
result.incrementOpenReaderCount();
|
||||
}
|
||||
|
||||
return reader;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,4 +51,12 @@ public interface ResultSetProxy extends ResultSet, WrapperProxy {
|
||||
void addReadBytesLength(int length);
|
||||
|
||||
long getReadBytesLength();
|
||||
|
||||
void incrementOpenInputStreamCount();
|
||||
|
||||
int getOpenInputStreamCount();
|
||||
|
||||
void incrementOpenReaderCount();
|
||||
|
||||
int getOpenReaderCount();
|
||||
}
|
||||
|
||||
@@ -51,14 +51,17 @@ public class ResultSetProxyImpl extends WrapperProxyImpl implements ResultSetPro
|
||||
private final StatementProxy statement;
|
||||
private final String sql;
|
||||
|
||||
protected int cursorIndex = 0;
|
||||
protected int fetchRowCount = 0;
|
||||
protected int cursorIndex = 0;
|
||||
protected int fetchRowCount = 0;
|
||||
protected long constructNano;
|
||||
protected final JdbcSqlStat sqlStat;
|
||||
private int closeCount = 0;
|
||||
private int closeCount = 0;
|
||||
|
||||
private long readStringLength = 0;
|
||||
private long readBytesLength = 0;
|
||||
private long readStringLength = 0;
|
||||
private long readBytesLength = 0;
|
||||
|
||||
private int openInputStreamCount = 0;
|
||||
private int openReaderCount = 0;
|
||||
|
||||
public ResultSetProxyImpl(StatementProxy statement, ResultSet resultSet, long id, String sql){
|
||||
super(resultSet, id);
|
||||
@@ -1090,15 +1093,35 @@ public class ResultSetProxyImpl extends WrapperProxyImpl implements ResultSetPro
|
||||
public long getReadStringLength() {
|
||||
return readStringLength;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addReadBytesLength(int length) {
|
||||
this.readBytesLength += length;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getReadBytesLength() {
|
||||
return readBytesLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementOpenInputStreamCount() {
|
||||
openInputStreamCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpenInputStreamCount() {
|
||||
return openInputStreamCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementOpenReaderCount() {
|
||||
openReaderCount++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpenReaderCount() {
|
||||
return openReaderCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -80,6 +80,9 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
private final AtomicLong readStringLength = new AtomicLong();
|
||||
private final AtomicLong readBytesLength = new AtomicLong();
|
||||
|
||||
private final AtomicLong inputStreamOpenCount = new AtomicLong();
|
||||
private final AtomicLong readerOpenCount = new AtomicLong();
|
||||
|
||||
private final Histogram histogram = new Histogram(new long[] { //
|
||||
//
|
||||
1, 10, 100, 1000, 10 * 1000, //
|
||||
@@ -230,6 +233,8 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
clobOpenCount.set(0);
|
||||
readStringLength.set(0);
|
||||
readBytesLength.set(0);
|
||||
inputStreamOpenCount.set(0);
|
||||
readerOpenCount.set(0);
|
||||
}
|
||||
|
||||
public long getConcurrentMax() {
|
||||
@@ -299,9 +304,25 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
return readBytesLength.get();
|
||||
}
|
||||
|
||||
public void addReadBytesLength(int length) {
|
||||
public void addReadBytesLength(long length) {
|
||||
this.readBytesLength.addAndGet(length);
|
||||
}
|
||||
|
||||
public long getReaderOpenCount() {
|
||||
return readerOpenCount.get();
|
||||
}
|
||||
|
||||
public void addReaderOpenCount(int count) {
|
||||
this.readerOpenCount.addAndGet(count);
|
||||
}
|
||||
|
||||
public long getInputStreamOpenCount() {
|
||||
return inputStreamOpenCount.get();
|
||||
}
|
||||
|
||||
public void addInputStreamOpenCount(int count) {
|
||||
this.inputStreamOpenCount.addAndGet(count);
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
@@ -530,6 +551,8 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
SimpleType.LONG, //
|
||||
|
||||
};
|
||||
|
||||
@@ -586,7 +609,9 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
// 35 -
|
||||
"BlobOpenCount", //
|
||||
"ReadStringLength", //
|
||||
"ReadBytesLength",
|
||||
"ReadBytesLength", //
|
||||
"InputStreamOpenCount", //
|
||||
"ReaderOpenCount", //
|
||||
|
||||
//
|
||||
};
|
||||
@@ -662,6 +687,8 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user