improve monitor-client support

This commit is contained in:
wenshao
2013-08-15 19:39:49 +08:00
parent 10163f7867
commit 73a267f721
19 changed files with 553 additions and 350 deletions
@@ -19,19 +19,20 @@ import java.util.Date;
import java.util.List;
import com.alibaba.druid.stat.JdbcSqlStatValue;
import com.alibaba.druid.support.monitor.MField;
import com.alibaba.druid.support.monitor.MTable;
import com.alibaba.druid.support.monitor.annotation.AggregateType;
import com.alibaba.druid.support.monitor.annotation.MField;
import com.alibaba.druid.support.monitor.annotation.MTable;
@MTable(name = "druid_datasource")
public class DruidDataSourceStatValue {
@MField(groupBy = true)
@MField(groupBy = true, aggregate = AggregateType.None)
protected String name;
@MField
@MField(aggregate = AggregateType.None)
protected String dbType;
@MField
@MField(aggregate = AggregateType.None)
protected String driverClassName;
protected String url;
@@ -54,75 +55,93 @@ public class DruidDataSourceStatValue {
protected boolean defaultReadOnly;
protected Integer defaultTransactionIsolation;
@MField
@MField(aggregate = AggregateType.Last)
protected int activeCount;
@MField
@MField(aggregate = AggregateType.Max)
protected int activePeak;
@MField
@MField(aggregate = AggregateType.Max)
protected long activePeakTime;
@MField
@MField(aggregate = AggregateType.Last)
protected int poolingCount;
@MField
@MField(aggregate = AggregateType.Max)
protected int poolingPeak;
@MField
@MField(aggregate = AggregateType.Max)
protected long poolingPeakTime;
@MField
@MField(aggregate = AggregateType.Sum)
protected long connectCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long closeCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long waitThreadCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long notEmptyWaitCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long notEmptyWaitNanos;
@MField
@MField(aggregate = AggregateType.Sum)
protected long logicConnectErrorCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long physicalConnectCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long physicalCloseCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long physicalConnectErrorCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long executeCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long errorCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long commitCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long rollbackCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long pstmtCacheHitCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long pstmtCacheMissCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long startTransactionCount;
protected long[] transactionHistogram;
// protected long[] transactionHistogram;
protected long[] connectionHoldTimeHistogram;
@MField
@MField(aggregate = AggregateType.Sum)
protected long txn_0_1;
@MField(aggregate = AggregateType.Sum)
protected long txn_1_10;
@MField(aggregate = AggregateType.Sum)
protected long txn_10_100;
@MField(aggregate = AggregateType.Sum)
protected long txn_100_1000;
@MField(aggregate = AggregateType.Sum)
protected long txn_1000_10000;
@MField(aggregate = AggregateType.Sum)
protected long txn_10000_100000;
@MField(aggregate = AggregateType.Sum)
protected long txn_more;
@MField(aggregate = AggregateType.Sum)
protected long clobOpenCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long blobOpenCount;
@MField(aggregate = AggregateType.Sum)
protected long sqlSkipCount;
protected List<JdbcSqlStatValue> sqlList;
@@ -484,11 +503,22 @@ public class DruidDataSourceStatValue {
}
public long[] getTransactionHistogram() {
return transactionHistogram;
return new long[] { txn_0_1,// txn_0_1
txn_10_100, //
txn_100_1000, //
txn_1000_10000, //
txn_10000_100000, //
txn_more, //
};
}
public void setTransactionHistogram(long[] transactionHistogram) {
this.transactionHistogram = transactionHistogram;
public void setTransactionHistogram(long[] values) {
txn_0_1 = values[0];
txn_10_100 = values[1];
txn_100_1000 = values[2];
txn_1000_10000 = values[3];
txn_10000_100000 = values[4];
txn_more = values[5];
}
public long[] getConnectionHoldTimeHistogram() {
@@ -866,12 +866,15 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
SimpleType.LONG, //
SimpleType.LONG, //
// 35 -
// 35 - 39
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.LONG, //
// 40 -
SimpleType.LONG, //
};
@@ -931,6 +934,9 @@ public final class JdbcSqlStat implements JdbcSqlStatMBean {
"ReadBytesLength", //
"InputStreamOpenCount", //
"ReaderOpenCount", //
// 40
"HASH", //
//
};
@@ -21,8 +21,9 @@ import java.util.Map;
import javax.management.JMException;
import com.alibaba.druid.support.monitor.MField;
import com.alibaba.druid.support.monitor.MTable;
import com.alibaba.druid.support.monitor.annotation.AggregateType;
import com.alibaba.druid.support.monitor.annotation.MField;
import com.alibaba.druid.support.monitor.annotation.MTable;
import com.alibaba.druid.util.JMXUtils;
import com.alibaba.druid.util.Utils;
@@ -33,129 +34,129 @@ public class JdbcSqlStatValue {
protected String sql;
@MField(groupBy = true)
@MField(groupBy = true, aggregate = AggregateType.None, hashFor = "sql", hashForType="sql")
private long sqlHash;
@MField
@MField(aggregate = AggregateType.None)
protected String dataSource;
@MField(name = "lastStartTime")
@MField(name = "lastStartTime", aggregate = AggregateType.Max)
protected long executeLastStartTime;
@MField(name = "batchTotal")
@MField(name = "batchTotal", aggregate = AggregateType.Sum)
protected long executeBatchSizeTotal;
@MField(name = "batchToMax")
@MField(name = "batchToMax", aggregate = AggregateType.Max)
protected int executeBatchSizeMax;
@MField(name = "execSuccessCount")
@MField(name = "execSuccessCount", aggregate = AggregateType.Sum)
protected long executeSuccessCount;
@MField(name = "execNanoTotal")
@MField(name = "execNanoTotal", aggregate = AggregateType.Sum)
protected long executeSpanNanoTotal;
@MField(name = "execNanoMax")
@MField(name = "execNanoMax", aggregate = AggregateType.Sum)
protected long executeSpanNanoMax;
@MField(name = "running")
@MField(name = "running", aggregate = AggregateType.Last)
protected int runningCount;
@MField
@MField(aggregate = AggregateType.Max)
protected int concurrentMax;
@MField(name = "rsHoldTime")
@MField(name = "rsHoldTime", aggregate = AggregateType.Sum)
protected long resultSetHoldTimeNano;
@MField(name = "execRsHoldTime")
@MField(name = "execRsHoldTime", aggregate = AggregateType.Sum)
protected long executeAndResultSetHoldTime;
@MField
@MField(aggregate = AggregateType.None)
protected String name;
@MField
@MField(aggregate = AggregateType.None)
protected String file;
@MField
@MField(aggregate = AggregateType.None)
protected String dbType;
@MField(name = "execNanoMaxOccurTime")
@MField(name = "execNanoMaxOccurTime", aggregate = AggregateType.Max)
protected long executeNanoSpanMaxOccurTime;
@MField(name = "errorCount")
@MField(name = "errorCount", aggregate = AggregateType.Sum)
protected long executeErrorCount;
protected Throwable executeErrorLast;
@MField(name = "errorLastMsg")
@MField(name = "errorLastMsg", aggregate = AggregateType.Last)
protected String executeErrorLastMessage;
@MField(name = "errorLastClass")
@MField(name = "errorLastClass", aggregate = AggregateType.Last)
protected String executeErrorLastClass;
@MField(name = "errorLastStackTrace")
@MField(name = "errorLastStackTrace", aggregate = AggregateType.Last)
protected String executeErrorLastStackTrace;
@MField(name = "errorLastTime")
@MField(name = "errorLastTime", aggregate = AggregateType.Last)
protected long executeErrorLastTime;
@MField
@MField(aggregate = AggregateType.Sum)
protected long updateCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long updateCountMax;
@MField
@MField(aggregate = AggregateType.Sum)
protected long fetchRowCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long fetchRowCountMax;
@MField(name = "inTxnCount")
@MField(name = "inTxnCount", aggregate = AggregateType.Sum)
protected long inTransactionCount;
@MField
@MField(aggregate = AggregateType.Last)
protected String lastSlowParameters;
@MField
@MField(aggregate = AggregateType.Sum)
protected long clobOpenCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long blobOpenCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long readStringLength;
@MField
@MField(aggregate = AggregateType.Sum)
protected long readBytesLength;
@MField
@MField(aggregate = AggregateType.Sum)
protected long inputStreamOpenCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long readerOpenCount;
@MField(name = "h1")
@MField(name = "h1", aggregate = AggregateType.Sum)
protected long histogram_0_1;
@MField(name = "h10")
@MField(name = "h10", aggregate = AggregateType.Sum)
protected long histogram_1_10;
@MField(name = "h100")
@MField(name = "h100", aggregate = AggregateType.Sum)
protected int histogram_10_100;
@MField(name = "h1000")
@MField(name = "h1000", aggregate = AggregateType.Sum)
protected int histogram_100_1000;
@MField(name = "h10000")
@MField(name = "h10000", aggregate = AggregateType.Sum)
protected int histogram_1000_10000;
@MField(name = "h100000")
@MField(name = "h100000", aggregate = AggregateType.Sum)
protected int histogram_10000_100000;
@MField(name = "h1000000")
@MField(name = "h1000000", aggregate = AggregateType.Sum)
protected int histogram_100000_1000000;
@MField(name = "hmore")
@MField(name = "hmore", aggregate = AggregateType.Sum)
protected int histogram_1000000_more;
public long[] getExecuteHistogram() {
@@ -170,28 +171,28 @@ public class JdbcSqlStatValue {
};
}
@MField(name = "eh1")
@MField(name = "eh1", aggregate = AggregateType.Sum)
protected long executeAndResultHoldTime_0_1;
@MField(name = "eh10")
@MField(name = "eh10", aggregate = AggregateType.Sum)
protected long executeAndResultHoldTime_1_10;
@MField(name = "eh100")
@MField(name = "eh100", aggregate = AggregateType.Sum)
protected int executeAndResultHoldTime_10_100;
@MField(name = "eh1000")
@MField(name = "eh1000", aggregate = AggregateType.Sum)
protected int executeAndResultHoldTime_100_1000;
@MField(name = "eh10000")
@MField(name = "eh10000", aggregate = AggregateType.Sum)
protected int executeAndResultHoldTime_1000_10000;
@MField(name = "eh100000")
@MField(name = "eh100000", aggregate = AggregateType.Sum)
protected int executeAndResultHoldTime_10000_100000;
@MField(name = "eh1000000")
@MField(name = "eh1000000", aggregate = AggregateType.Sum)
protected int executeAndResultHoldTime_100000_1000000;
@MField(name = "ehmore")
@MField(name = "ehmore", aggregate = AggregateType.Sum)
protected int executeAndResultHoldTime_1000000_more;
public long[] getExecuteAndResultHoldHistogram() {
@@ -206,22 +207,22 @@ public class JdbcSqlStatValue {
};
}
@MField(name = "f1")
@MField(name = "f1", aggregate = AggregateType.Sum)
protected long fetchRowCount_0_1;
@MField(name = "f10")
@MField(name = "f10", aggregate = AggregateType.Sum)
protected long fetchRowCount_1_10;
@MField(name = "f100")
@MField(name = "f100", aggregate = AggregateType.Sum)
protected long fetchRowCount_10_100;
@MField(name = "f1000")
@MField(name = "f1000", aggregate = AggregateType.Sum)
protected int fetchRowCount_100_1000;
@MField(name = "f10000")
@MField(name = "f10000", aggregate = AggregateType.Sum)
protected int fetchRowCount_1000_10000;
@MField(name = "fmore")
@MField(name = "fmore", aggregate = AggregateType.Sum)
protected int fetchRowCount_10000_more;
public long[] getFetchRowHistogram() {
@@ -234,22 +235,22 @@ public class JdbcSqlStatValue {
};
}
@MField(name = "u1")
@MField(name = "u1", aggregate = AggregateType.Sum)
protected long updateCount_0_1;
@MField(name = "u10")
@MField(name = "u10", aggregate = AggregateType.Sum)
protected long updateCount_1_10;
@MField(name = "u100")
@MField(name = "u100", aggregate = AggregateType.Sum)
protected long updateCount_10_100;
@MField(name = "u1000")
@MField(name = "u1000", aggregate = AggregateType.Sum)
protected int updateCount_100_1000;
@MField(name = "u10000")
@MField(name = "u10000", aggregate = AggregateType.Sum)
protected int updateCount_1000_10000;
@MField(name = "umore")
@MField(name = "umore", aggregate = AggregateType.Sum)
protected int updateCount_10000_more;
public long[] getUpdateHistogram() {
@@ -690,6 +691,8 @@ public class JdbcSqlStatValue {
map.put("InputStreamOpenCount", getInputStreamOpenCount()); // 38
map.put("ReaderOpenCount", getReaderOpenCount()); // 39
map.put("HASH", getSqlHash()); // 40
return map;
}
@@ -18,165 +18,166 @@ package com.alibaba.druid.support.http.stat;
import java.util.LinkedHashMap;
import java.util.Map;
import com.alibaba.druid.support.monitor.MField;
import com.alibaba.druid.support.monitor.MTable;
import com.alibaba.druid.support.monitor.annotation.AggregateType;
import com.alibaba.druid.support.monitor.annotation.MField;
import com.alibaba.druid.support.monitor.annotation.MTable;
@MTable(name = "druid_webapp")
public class WebAppStatValue {
@MField(groupBy = true)
@MField(groupBy = true, aggregate=AggregateType.None)
String contextPath;
@MField
@MField(aggregate = AggregateType.Last)
int runningCount;
@MField
@MField(aggregate = AggregateType.Max)
int concurrentMax;
@MField
@MField(aggregate = AggregateType.Sum)
long requestCount;
@MField
@MField(aggregate = AggregateType.Last)
long sessionCount;
@MField
@MField(aggregate = AggregateType.Sum)
long jdbcFetchRowCount;
@MField
@MField(aggregate = AggregateType.Sum)
long jdbcUpdateCount;
@MField
@MField(aggregate = AggregateType.Sum)
long jdbcExecuteCount;
@MField
@MField(aggregate = AggregateType.Sum)
long jdbcExecuteTimeNano;
@MField
@MField(aggregate = AggregateType.Sum)
long jdbcCommitCount;
@MField
@MField(aggregate = AggregateType.Sum)
long jdbcRollbackCount;
@MField
@MField(aggregate = AggregateType.Sum)
long osMacOSXCount;
@MField
@MField(aggregate = AggregateType.Sum)
long osWindowsCount;
@MField
@MField(aggregate = AggregateType.Sum)
long osLinuxCount;
@MField
@MField(aggregate = AggregateType.Sum)
long osSymbianCount;
@MField
@MField(aggregate = AggregateType.Sum)
long osFreeBSDCount;
@MField
@MField(aggregate = AggregateType.Sum)
long osOpenBSDCount;
@MField
@MField(aggregate = AggregateType.Sum)
long osAndroidCount;
@MField
@MField(aggregate = AggregateType.Sum)
long osWindows98Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osWindowsXPCount;
@MField
@MField(aggregate = AggregateType.Sum)
long osWindows2000Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osWindowsVistaCount;
@MField
@MField(aggregate = AggregateType.Sum)
long osWindows7Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osWindows8Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osAndroid15Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osAndroid16Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osAndroid20Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osAndroid21Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osAndroid22Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osAndroid23Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osAndroid30Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osAndroid31Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osAndroid32Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osAndroid40Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osAndroid41Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osAndroid42Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osAndroid43Count;
@MField
@MField(aggregate = AggregateType.Sum)
long osLinuxUbuntuCount;
@MField
@MField(aggregate = AggregateType.Sum)
long browserIECount;
@MField
@MField(aggregate = AggregateType.Sum)
long browserFirefoxCount;
@MField
@MField(aggregate = AggregateType.Sum)
long browserChromeCount;
@MField
@MField(aggregate = AggregateType.Sum)
long browserSafariCount;
@MField
@MField(aggregate = AggregateType.Sum)
long browserOperaCount;
@MField
@MField(aggregate = AggregateType.Sum)
long browserIE5Count;
@MField
@MField(aggregate = AggregateType.Sum)
long browserIE6Count;
@MField
@MField(aggregate = AggregateType.Sum)
long browserIE7Count;
@MField
@MField(aggregate = AggregateType.Sum)
long browserIE8Count;
@MField
@MField(aggregate = AggregateType.Sum)
long browserIE9Count;
@MField
@MField(aggregate = AggregateType.Sum)
long browserIE10Count;
@MField
@MField(aggregate = AggregateType.Sum)
long browser360SECount;
@MField
@MField(aggregate = AggregateType.Sum)
long deviceAndroidCount;
@MField
@MField(aggregate = AggregateType.Sum)
long deviceIpadCount;
@MField
@MField(aggregate = AggregateType.Sum)
long deviceIphoneCount;
@MField
@MField(aggregate = AggregateType.Sum)
long deviceWindowsPhoneCount;
@MField
@MField(aggregate = AggregateType.Sum)
long botCount;
@MField
@MField(aggregate = AggregateType.Sum)
long botBaiduCount;
@MField
@MField(aggregate = AggregateType.Sum)
long botYoudaoCount;
@MField
@MField(aggregate = AggregateType.Sum)
long botGoogleCount;
@MField
@MField(aggregate = AggregateType.Sum)
long botMsnCount;
@MField
@MField(aggregate = AggregateType.Sum)
long botBingCount;
@MField
@MField(aggregate = AggregateType.Sum)
long botSosoCount;
@MField
@MField(aggregate = AggregateType.Sum)
long botSogouCount;
@MField
@MField(aggregate = AggregateType.Sum)
long botYahooCount;
public String getContextPath() {
@@ -21,99 +21,100 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.druid.support.monitor.MField;
import com.alibaba.druid.support.monitor.MTable;
import com.alibaba.druid.support.monitor.annotation.AggregateType;
import com.alibaba.druid.support.monitor.annotation.MField;
import com.alibaba.druid.support.monitor.annotation.MTable;
import com.alibaba.druid.support.profile.ProfileEntryStatValue;
@MTable(name = "druid_weburi")
public class WebURIStatValue {
@MField(groupBy = true)
@MField(groupBy = true, aggregate = AggregateType.None)
protected String uri;
@MField
@MField(aggregate = AggregateType.Last)
protected int runningCount;
@MField
@MField(aggregate = AggregateType.Max)
protected int concurrentMax;
@MField
@MField(aggregate = AggregateType.Sum)
protected long requestCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long requestTimeNano;
@MField
@MField(aggregate = AggregateType.Sum)
protected long jdbcFetchRowCount;
@MField
@MField(aggregate = AggregateType.Max)
protected long jdbcFetchRowPeak;
@MField
@MField(aggregate = AggregateType.Sum)
protected long jdbcUpdateCount;
@MField
@MField(aggregate = AggregateType.Max)
protected long jdbcUpdatePeak;
@MField
@MField(aggregate = AggregateType.Sum)
protected long jdbcExecuteCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long jdbcExecuteErrorCount;
@MField
@MField(aggregate = AggregateType.Max)
protected long jdbcExecutePeak; // 单次请求执行SQL次数的峰值
@MField
@MField(aggregate = AggregateType.Sum)
protected long jdbcExecuteTimeNano;
@MField
@MField(aggregate = AggregateType.Sum)
protected long jdbcCommitCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long jdbcRollbackCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long jdbcPoolConnectionOpenCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long jdbcPoolConnectionCloseCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long jdbcResultSetOpenCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long jdbcResultSetCloseCount;
@MField
@MField(aggregate = AggregateType.Sum)
protected long errorCount;
@MField
protected long lastAccessTimeMillis = -1L;
@MField(aggregate = AggregateType.Last)
protected Date lastAccessTime = null;
private List<ProfileEntryStatValue> profileEntryStatValueList;
@MField(name = "h1")
@MField(name = "h1", aggregate = AggregateType.Sum)
protected long histogram_0_1;
@MField(name = "h10")
@MField(name = "h10", aggregate = AggregateType.Sum)
protected long histogram_1_10;
@MField(name = "h100")
@MField(name = "h100", aggregate = AggregateType.Sum)
protected long histogram_10_100;
@MField(name = "h1000")
@MField(name = "h1000", aggregate = AggregateType.Sum)
protected long histogram_100_1000;
@MField(name = "h10000")
@MField(name = "h10000", aggregate = AggregateType.Sum)
protected int histogram_1000_10000;
@MField(name = "h100000")
@MField(name = "h100000", aggregate = AggregateType.Sum)
protected int histogram_10000_100000;
@MField(name = "h1000000")
@MField(name = "h1000000", aggregate = AggregateType.Sum)
protected int histogram_100000_1000000;
@MField(name = "hmore")
@MField(name = "hmore", aggregate = AggregateType.Sum)
protected int histogram_1000000_more;
public long[] getHistogram() {
@@ -296,12 +297,12 @@ public class WebURIStatValue {
this.errorCount = errorCount;
}
public long getLastAccessTimeMillis() {
return lastAccessTimeMillis;
}
public void setLastAccessTimeMillis(long lastAccessTimeMillis) {
this.lastAccessTimeMillis = lastAccessTimeMillis;
if (lastAccessTimeMillis > 0) {
this.lastAccessTime = new Date(lastAccessTimeMillis);
} else {
this.lastAccessTime = null;
}
}
public long getRequestTimeMillis() {
@@ -309,11 +310,7 @@ public class WebURIStatValue {
}
public Date getLastAccessTime() {
if (lastAccessTimeMillis < 0L) {
return null;
}
return new Date(lastAccessTimeMillis);
return lastAccessTime;
}
public long getJdbcExecuteTimeMillis() {
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.monitor;
package com.alibaba.druid.support.monitor.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -25,6 +25,12 @@ import java.lang.annotation.Target;
public @interface MField {
String name() default "";
boolean groupBy() default false;
AggregateType aggregate();
String hashFor() default "";
String hashForType() default "";
}
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.monitor;
package com.alibaba.druid.support.monitor.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -28,6 +28,8 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import javax.sql.DataSource;
@@ -38,9 +40,10 @@ import com.alibaba.druid.support.http.stat.WebAppStatValue;
import com.alibaba.druid.support.http.stat.WebURIStatValue;
import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import com.alibaba.druid.support.monitor.MField;
import com.alibaba.druid.support.monitor.MTable;
import com.alibaba.druid.support.monitor.MonitorContext;
import com.alibaba.druid.support.monitor.annotation.AggregateType;
import com.alibaba.druid.support.monitor.annotation.MField;
import com.alibaba.druid.support.monitor.annotation.MTable;
import com.alibaba.druid.support.spring.stat.SpringMethodStatValue;
import com.alibaba.druid.util.JdbcUtils;
import com.alibaba.druid.util.StringUtils;
@@ -58,11 +61,31 @@ public class MonitorDaoJdbcImpl implements MonitorDao {
private BeanInfo webURIStatBeanInfo = new BeanInfo(WebURIStatValue.class);
private BeanInfo webAppStatBeanInfo = new BeanInfo(WebAppStatValue.class);
//
public MonitorDaoJdbcImpl(){
}
public void createTables(String dbType) {
String[] resources = new String[] { "const.sql", //
"datasource.sql", //
"springmethod.sql", //
"sql.sql", //
"webapp.sql", //
"weburi.sql" };
for (String item : resources) {
String path = "/support/monitor/" + dbType + "/" + item;
try {
String text = Utils.readFromResource(path);
String[] sqls = text.split(";");
for (String sql : sqls) {
JdbcUtils.execute(dataSource, sql);
}
} catch (Exception ex) {
LOG.error("create table error", ex);
}
}
}
public DataSource getDataSource() {
return dataSource;
}
@@ -166,11 +189,30 @@ public class MonitorDaoJdbcImpl implements MonitorDao {
List<FieldInfo> fields = beanInfo.getFields();
for (int i = 0; i < fields.size(); ++i) {
FieldInfo field = fields.get(i);
FieldInfo fieldInfo = fields.get(i);
if (i != 0) {
buf.append(", ");
}
buf.append(field.getColumnName());
AggregateType aggregateType = fieldInfo.getField().getAnnotation(MField.class).aggregate();
switch (aggregateType) {
case Sum:
buf.append("SUM(");
buf.append(fieldInfo.getColumnName());
buf.append(")");
break;
case Max:
buf.append("MAX(");
buf.append(fieldInfo.getColumnName());
buf.append(")");
break;
case None:
case Last:
default:
buf.append(fieldInfo.getColumnName());
break;
}
}
buf.append("\nFROM ");
@@ -212,6 +254,17 @@ public class MonitorDaoJdbcImpl implements MonitorDao {
buf.append("\nAND pid = ?");
}
List<FieldInfo> groupByFields = beanInfo.getGroupByFields();
for (int i = 0; i < groupByFields.size(); ++i) {
if (i == 0) {
buf.append("\nGROUP BY ");
} else {
buf.append(", ");
}
FieldInfo fieldInfo = groupByFields.get(i);
buf.append(fieldInfo.getColumnName());
}
{
Integer offset = (Integer) filters.get("offset");
Integer limit = (Integer) filters.get("limit");
@@ -275,6 +328,10 @@ public class MonitorDaoJdbcImpl implements MonitorDao {
JdbcUtils.close(conn);
}
for (FieldInfo hashField : beanInfo.getHashFields()) {
loadHashValue(hashField, list, filters);
}
return list;
}
@@ -304,7 +361,73 @@ public class MonitorDaoJdbcImpl implements MonitorDao {
}
}
private void loadHashValue(FieldInfo hashField, List<?> list, Map<String, Object> filters) {
String domain = (String) filters.get("domain");
if (StringUtils.isEmpty(domain)) {
domain = "defaultDomain";
}
String app = (String) filters.get("app");
if (StringUtils.isEmpty(app)) {
app = "defaultApp";
}
for (Object statValue : list) {
try {
String sql = "select hash, value from druid_const where domain = ? AND app = ? and type = ? and value = ?";
Long hash = (Long) hashField.field.get(statValue);
} catch (IllegalArgumentException e) {
throw new DruidRuntimeException("set field error" + hashField.getField(), e);
} catch (IllegalAccessException e) {
throw new DruidRuntimeException("set field error" + hashField.getField(), e);
}
}
}
private void saveHash(FieldInfo hashField, MonitorContext ctx, List<?> list) {
final String hashType = hashField.getHashForType();
for (Object statValue : list) {
try {
Long hash = (Long) hashField.field.get(statValue);
if (!hashField.hashCacheContains(hash)) {
String value = (String) hashField.getHashFor().get(statValue);
final String sql = "insert into druid_const (domain, app, type, hash, value) values (?, ?, ?, ?, ?)";
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = dataSource.getConnection();
stmt = conn.prepareStatement(sql);
stmt.setString(1, ctx.getDomainName());
stmt.setString(2, ctx.getAppName());
stmt.setString(3, hashType);
stmt.setLong(4, hash);
stmt.setString(5, value);
stmt.execute();
stmt.close();
} catch (SQLException ex) {
LOG.error("save const error error", ex);
} finally {
JdbcUtils.close(stmt);
JdbcUtils.close(conn);
}
hashField.hashCacheAdd(hash, value);
}
} catch (IllegalArgumentException e) {
throw new DruidRuntimeException("set field error" + hashField.getField(), e);
} catch (IllegalAccessException e) {
throw new DruidRuntimeException("set field error" + hashField.getField(), e);
}
}
}
private void save(BeanInfo beanInfo, MonitorContext ctx, List<?> list) {
for (FieldInfo hashField : beanInfo.getHashFields()) {
saveHash(hashField, ctx, list);
}
String sql = buildInsertSql(beanInfo);
Connection conn = null;
PreparedStatement stmt = null;
@@ -453,8 +576,10 @@ public class MonitorDaoJdbcImpl implements MonitorDao {
private final Class<?> clazz;
private final List<FieldInfo> fields = new ArrayList<FieldInfo>();
private final List<FieldInfo> groupByFields = new ArrayList<FieldInfo>();
private final List<FieldInfo> hashFields = new ArrayList<FieldInfo>();
private final String tableName;
private String insertSql;
private String tableName;
public BeanInfo(Class<?> clazz){
this.clazz = clazz;
@@ -479,11 +604,27 @@ public class MonitorDaoJdbcImpl implements MonitorDao {
columnName = field.getName();
}
FieldInfo fieldInfo = new FieldInfo(field, columnName);
Field hashFor = null;
String hashForType = null;
if (!StringUtils.isEmpty(annotation.hashFor())) {
try {
hashFor = clazz.getDeclaredField(annotation.hashFor());
hashForType = annotation.hashForType();
} catch (Exception e) {
throw new IllegalStateException("hashFor error", e);
}
}
FieldInfo fieldInfo = new FieldInfo(field, columnName, hashFor, hashForType);
fields.add(fieldInfo);
if (annotation.groupBy()) {
groupByFields.add(fieldInfo);
}
if (hashFor != null) {
hashFields.add(fieldInfo);
}
}
}
@@ -511,24 +652,45 @@ public class MonitorDaoJdbcImpl implements MonitorDao {
return groupByFields;
}
public List<FieldInfo> getHashFields() {
return hashFields;
}
}
public static class FieldInfo {
private final Field field;
private final String columnName;
private final Field field;
private final String columnName;
private final Field hashFor;
private final String hashForType;
public FieldInfo(Field field, String columnName){
private ConcurrentMap<Long, String> hashCache = new ConcurrentHashMap<Long, String>(16, 0.75f, 1);
public FieldInfo(Field field, String columnName, Field hashFor, String hashForType){
this.field = field;
this.columnName = columnName;
this.hashFor = hashFor;
this.hashForType = hashForType;
field.setAccessible(true);
if (hashFor != null) {
hashFor.setAccessible(true);
}
}
public String getHashForType() {
return hashForType;
}
public Field getField() {
return field;
}
public Field getHashFor() {
return hashFor;
}
public String getColumnName() {
return columnName;
}
@@ -536,6 +698,18 @@ public class MonitorDaoJdbcImpl implements MonitorDao {
public Class<?> getFieldType() {
return field.getType();
}
public void hashCacheAdd(long hash, String value) {
if (hashCache.size() > 1000) {
return;
}
hashCache.put(hash, value);
}
public boolean hashCacheContains(long hash) {
return hashCache.containsKey(hash);
}
}
@Override
@@ -19,101 +19,102 @@ import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
import com.alibaba.druid.support.monitor.MField;
import com.alibaba.druid.support.monitor.MTable;
import com.alibaba.druid.support.monitor.annotation.AggregateType;
import com.alibaba.druid.support.monitor.annotation.MField;
import com.alibaba.druid.support.monitor.annotation.MTable;
import com.alibaba.druid.util.Utils;
@MTable(name = "druid_springmethod")
public class SpringMethodStatValue {
@MField(groupBy = true)
@MField(groupBy = true, aggregate=AggregateType.None)
private String className;
@MField(groupBy = true)
@MField(groupBy = true, aggregate=AggregateType.None)
private String signature;
@MField
@MField(aggregate = AggregateType.Last)
private int runningCount;
@MField
@MField(aggregate = AggregateType.Max)
private int concurrentMax;
@MField
@MField(aggregate = AggregateType.Sum)
private long executeCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long executeErrorCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long executeTimeNano;
@MField
@MField(aggregate = AggregateType.Sum)
private long jdbcFetchRowCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long jdbcUpdateCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long jdbcExecuteCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long jdbcExecuteErrorCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long jdbcExecuteTimeNano;
@MField
@MField(aggregate = AggregateType.Sum)
private long jdbcCommitCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long jdbcRollbackCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long jdbcPoolConnectionOpenCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long jdbcPoolConnectionCloseCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long jdbcResultSetOpenCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long jdbcResultSetCloseCount;
@MField
@MField(aggregate = AggregateType.Last)
private String lastErrorClass;
@MField
@MField(aggregate = AggregateType.Last)
private String lastErrorMessage;
@MField
@MField(aggregate = AggregateType.Last)
private String lastErrorStackTrace;
@MField
@MField(aggregate = AggregateType.Last)
private long lastErrorTimeMillis;
@MField(name = "h1")
@MField(name = "h1", aggregate=AggregateType.Sum)
long histogram_0_1;
@MField(name = "h10")
@MField(name = "h10", aggregate=AggregateType.Sum)
long histogram_1_10;
@MField(name = "h100")
@MField(name = "h100", aggregate=AggregateType.Sum)
long histogram_10_100;
@MField(name = "h1000")
@MField(name = "h1000", aggregate=AggregateType.Sum)
long histogram_100_1000;
@MField(name = "h10000")
@MField(name = "h10000", aggregate=AggregateType.Sum)
int histogram_1000_10000;
@MField(name = "h100000")
@MField(name = "h100000", aggregate=AggregateType.Sum)
int histogram_10000_100000;
@MField(name = "h1000000")
@MField(name = "h1000000", aggregate=AggregateType.Sum)
int histogram_100000_1000000;
@MField(name = "hmore")
@MField(name = "hmore", aggregate=AggregateType.Sum)
int histogram_1000000_more;
public String getClassName() {
@@ -18,16 +18,17 @@ package com.alibaba.druid.wall;
import java.util.LinkedHashMap;
import java.util.Map;
import com.alibaba.druid.support.monitor.MField;
import com.alibaba.druid.support.monitor.MTable;
import com.alibaba.druid.support.monitor.annotation.AggregateType;
import com.alibaba.druid.support.monitor.annotation.MField;
import com.alibaba.druid.support.monitor.annotation.MTable;
@MTable(name = "druid_wall_function")
public class WallFunctionStatValue {
@MField
@MField(groupBy=true, aggregate=AggregateType.None)
private String name;
@MField
@MField(aggregate=AggregateType.Sum)
private long invokeCount;
public WallFunctionStatValue(){
@@ -20,28 +20,29 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.alibaba.druid.support.monitor.MField;
import com.alibaba.druid.support.monitor.MTable;
import com.alibaba.druid.support.monitor.annotation.AggregateType;
import com.alibaba.druid.support.monitor.annotation.MField;
import com.alibaba.druid.support.monitor.annotation.MTable;
@MTable(name = "druid_wall")
public class WallProviderStatValue {
@MField
@MField(aggregate = AggregateType.None)
private String name;
@MField
@MField(aggregate = AggregateType.Sum)
private long checkCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long hardCheckCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long violationCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long whiteListHitCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long blackListHitCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long syntaxErrorCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long violationEffectRowCount;
private final List<WallTableStatValue> tables = new ArrayList<WallTableStatValue>();
@@ -18,31 +18,32 @@ package com.alibaba.druid.wall;
import java.util.LinkedHashMap;
import java.util.Map;
import com.alibaba.druid.support.monitor.MField;
import com.alibaba.druid.support.monitor.MTable;
import com.alibaba.druid.support.monitor.annotation.AggregateType;
import com.alibaba.druid.support.monitor.annotation.MField;
import com.alibaba.druid.support.monitor.annotation.MTable;
@MTable(name = "druid_wall_sql")
public class WallSqlStatValue {
@MField
@MField(aggregate = AggregateType.None)
private String sql;
@MField
@MField(aggregate = AggregateType.None)
private String sqlSample;
@MField
@MField(aggregate = AggregateType.Sum)
private long executeCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long fetchRowCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long updateCount;
@MField
@MField(aggregate = AggregateType.Last)
private boolean syntaxError;
@MField
@MField(aggregate = AggregateType.Last)
private String violationMessage;
public WallSqlStatValue(){
@@ -18,55 +18,56 @@ package com.alibaba.druid.wall;
import java.util.LinkedHashMap;
import java.util.Map;
import com.alibaba.druid.support.monitor.MField;
import com.alibaba.druid.support.monitor.MTable;
import com.alibaba.druid.support.monitor.annotation.AggregateType;
import com.alibaba.druid.support.monitor.annotation.MField;
import com.alibaba.druid.support.monitor.annotation.MTable;
@MTable(name = "druid_wall_table")
public class WallTableStatValue {
@MField
@MField(aggregate = AggregateType.None)
private String name;
@MField
@MField(aggregate = AggregateType.Sum)
private long selectCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long selectIntoCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long insertCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long updateCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long deleteCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long truncateCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long createCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long alterCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long dropCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long replaceCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long deleteDataCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long updateDataCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long insertDataCount;
@MField
@MField(aggregate = AggregateType.Sum)
private long fetchRowCount;
public WallTableStatValue(){