monitor support

This commit is contained in:
wenshao
2013-08-14 13:49:55 +08:00
parent f58d1d2f6f
commit 5aa3d51128
11 changed files with 1311 additions and 171 deletions
@@ -15,12 +15,10 @@
*/
package com.alibaba.druid.stat;
import java.lang.management.ManagementFactory;
import java.sql.Driver;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
@@ -36,6 +34,7 @@ import com.alibaba.druid.sql.visitor.SQLEvalVisitorUtils;
import com.alibaba.druid.support.http.stat.WebAppStatManager;
import com.alibaba.druid.support.spring.stat.SpringStatManager;
import com.alibaba.druid.util.DruidDataSourceUtils;
import com.alibaba.druid.util.IOUtils;
import com.alibaba.druid.util.JdbcSqlStatUtils;
import com.alibaba.druid.util.StringUtils;
@@ -167,7 +166,7 @@ public final class DruidStatManagerFacade {
if (dataSourceId == null) {
Map<String, Object> map = new HashMap<String, Object>();
for (Object datasource : dataSources) {
Map<String, Object> wallStat = DruidDataSourceUtils.getWallStatMap(datasource);
map = mergWallStat(map, wallStat);
@@ -185,50 +184,50 @@ public final class DruidStatManagerFacade {
}
return new HashMap<String, Object>();
//
//
}
@SuppressWarnings({ "rawtypes", "unchecked" })
public static Map mergWallStat(Map mapA, Map mapB) {
if (mapA == null || mapA.size() == 0) {
return mapB;
}
if (mapB == null || mapB.size() == 0) {
return mapA;
}
Map<String, Object> newMap = new LinkedHashMap<String, Object>();
for (Object item : mapB.entrySet()) {
Map.Entry entry = (Map.Entry) item;
Map.Entry entry = (Map.Entry) item;
String key = (String) entry.getKey();
Object valueB = entry.getValue();
Object valueA = mapA.get(key);
if (valueA == null) {
newMap.put(key, valueB);
} else if (valueB == null) {
newMap.put(key, valueA);
} else if ("blackList".equals(key)) {
Map<String, Map<String, Object>> newSet = new HashMap<String, Map<String, Object>>();
Collection<Map<String, Object>> collectionA = (Collection<Map<String, Object>>) valueA;
for (Map<String, Object> blackItem : collectionA) {
if (newSet.size() >= 1000) {
break;
}
String sql = (String) blackItem.get("sql");
Map<String, Object> oldItem = newSet.get(sql);
newSet.put(sql, mergWallStat(oldItem, blackItem));
}
Collection<Map<String, Object>> collectionB = (Collection<Map<String, Object>>) valueB;
for (Map<String, Object> blackItem : collectionB) {
if (newSet.size() >= 1000) {
break;
}
String sql = (String) blackItem.get("sql");
Map<String, Object> oldItem = newSet.get(sql);
newSet.put(sql, mergWallStat(oldItem, blackItem));
@@ -236,7 +235,7 @@ public final class DruidStatManagerFacade {
newMap.put(key, newSet.values());
} else {
if (valueA instanceof Map && valueB instanceof Map) {
Object newValue = mergWallStat((Map)valueA, (Map)valueB);
Object newValue = mergWallStat((Map) valueA, (Map) valueB);
newMap.put(key, newValue);
} else if (valueA instanceof Set && valueB instanceof Set) {
Set<Object> set = new HashSet<Object>();
@@ -254,7 +253,7 @@ public final class DruidStatManagerFacade {
}
}
}
return newMap;
}
@@ -266,17 +265,17 @@ public final class DruidStatManagerFacade {
String name = (String) map.get("name");
mapped.put(name, map);
}
List<Map<String, Object>> mergedList = new ArrayList<Map<String, Object>>();
for (Object item : (List) listB) {
Map<String, Object> mapB = (Map<String, Object>) item;
String name = (String) mapB.get("name");
Map<String, Object> mapA = mapped.get(name);
Map<String, Object> mergedMap = mergWallStat(mapA, mapB);
mergedList.add(mergedMap);
}
return mergedList;
}
@@ -345,7 +344,7 @@ public final class DruidStatManagerFacade {
dataMap.put("JavaVMName", System.getProperty("java.vm.name"));
dataMap.put("JavaVersion", System.getProperty("java.version"));
dataMap.put("JavaClassPath", System.getProperty("java.class.path"));
dataMap.put("StartTime", new Date(ManagementFactory.getRuntimeMXBean().getStartTime()));
dataMap.put("StartTime", IOUtils.getStartTime());
return dataMap;
}
@@ -15,9 +15,10 @@
*/
package com.alibaba.druid.support.http.stat;
import static com.alibaba.druid.util.JdbcSqlStatUtils.get;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@@ -56,7 +57,10 @@ public class WebAppStat {
private final AtomicLong jdbcCommitCount = new AtomicLong();
private final AtomicLong jdbcRollbackCount = new AtomicLong();
private final ConcurrentMap<String, WebURIStat> uriStatMap = new ConcurrentHashMap<String, WebURIStat>(16, 0.75f, 1);
private final ConcurrentMap<String, WebURIStat> uriStatMap = new ConcurrentHashMap<String, WebURIStat>(
16,
0.75f,
1);
private final LRUCache<String, WebSessionStat> sessionStatMap;
private final ReadWriteLock sessionStatLock = new ReentrantReadWriteLock();
@@ -136,7 +140,7 @@ public class WebAppStat {
requestCount.set(0);
requestCount.set(0);
sessionCount.set(0);
jdbcFetchRowCount.set(0);
jdbcUpdateCount.set(0);
jdbcExecuteCount.set(0);
@@ -354,7 +358,7 @@ public class WebAppStat {
public void afterInvoke(Throwable error, long nanoSpan) {
runningCount.decrementAndGet();
currentLocal.set(null);
WebRequestStat requestStat = WebRequestStat.current();
if (requestStat != null) {
this.addJdbcExecuteCount(requestStat.getJdbcExecuteCount());
@@ -365,15 +369,15 @@ public class WebAppStat {
this.addJdbcExecuteTimeNano(requestStat.getJdbcExecuteTimeNano());
}
}
public void incrementSessionCount() {
sessionCount.incrementAndGet();
}
public long getSessionCount() {
return sessionCount.get();
}
public void addJdbcFetchRowCount(long delta) {
this.jdbcFetchRowCount.addAndGet(delta);
}
@@ -402,10 +406,6 @@ public class WebAppStat {
return jdbcExecuteCount.get();
}
public long getJdbcExecuteTimeMillis() {
return getJdbcExecuteTimeNano() / (1000 * 1000);
}
public long getJdbcExecuteTimeNano() {
return jdbcExecuteTimeNano.get();
}
@@ -467,81 +467,22 @@ public class WebAppStat {
}
public Map<String, Object> getStatData() {
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("ContextPath", this.getContextPath());
data.put("RunningCount", this.getRunningCount());
data.put("ConcurrentMax", this.getConcurrentMax());
data.put("RequestCount", this.getRequestCount());
data.put("SessionCount", this.getSessionCount());
return getStatValue(false).getStatData();
}
public List<WebURIStatValue> getURIStatValueList(boolean reset) {
List<WebURIStatValue> list = new ArrayList<WebURIStatValue>(this.uriStatMap.size());
data.put("JdbcCommitCount", this.getJdbcCommitCount());
data.put("JdbcRollbackCount", this.getJdbcRollbackCount());
data.put("JdbcExecuteCount", this.getJdbcExecuteCount());
data.put("JdbcExecuteTimeMillis", this.getJdbcExecuteTimeMillis());
data.put("JdbcFetchRowCount", this.getJdbcFetchRowCount());
data.put("JdbcUpdateCount", this.getJdbcUpdateCount());
data.put("OSMacOSXCount", this.getOSMacOSXCount());
data.put("OSWindowsCount", this.getOSWindowsCount());
data.put("OSLinuxCount", this.getOSLinuxCount());
data.put("OSSymbianCount", this.getOSSymbianCount());
data.put("OSFreeBSDCount", this.getOSFreeBSDCount());
data.put("OSOpenBSDCount", this.getOSOpenBSDCount());
data.put("OSAndroidCount", this.getOSAndroidCount());
data.put("OSWindows98Count", this.getOSWindows98Count());
data.put("OSWindowsXPCount", this.getOSWindowsXPCount());
data.put("OSWindows2000Count", this.getOSWindows2000Count());
data.put("OSWindowsVistaCount", this.getOSWindowsVistaCount());
data.put("OSWindows7Count", this.getOSWindows7Count());
data.put("OSWindows8Count", this.getOSWindows8Count());
data.put("OSAndroid15Count", this.getOSAndroid15Count());
data.put("OSAndroid16Count", this.getOSAndroid16Count());
data.put("OSAndroid20Count", this.getOSAndroid20Count());
data.put("OSAndroid21Count", this.getOSAndroid21Count());
data.put("OSAndroid22Count", this.getOSAndroid22Count());
data.put("OSAndroid23Count", this.getOSAndroid23Count());
data.put("OSAndroid30Count", this.getOSAndroid30Count());
data.put("OSAndroid31Count", this.getOSAndroid31Count());
data.put("OSAndroid32Count", this.getOSAndroid32Count());
data.put("OSAndroid40Count", this.getOSAndroid40Count());
data.put("OSAndroid41Count", this.getOSAndroid41Count());
data.put("OSAndroid42Count", this.getOSAndroid42Count());
data.put("OSAndroid43Count", this.getOSAndroid43Count());
data.put("OSLinuxUbuntuCount", this.getOSLinuxUbuntuCount());
data.put("BrowserIECount", this.getBrowserIECount());
data.put("BrowserFirefoxCount", this.getBrowserFirefoxCount());
data.put("BrowserChromeCount", this.getBrowserChromeCount());
data.put("BrowserSafariCount", this.getBrowserSafariCount());
data.put("BrowserOperaCount", this.getBrowserOperaCount());
data.put("BrowserIE5Count", this.getBrowserIE5Count());
data.put("BrowserIE6Count", this.getBrowserIE6Count());
data.put("BrowserIE7Count", this.getBrowserIE7Count());
data.put("BrowserIE8Count", this.getBrowserIE8Count());
data.put("BrowserIE9Count", this.getBrowserIE9Count());
data.put("BrowserIE10Count", this.getBrowserIE10Count());
data.put("Browser360SECount", this.getBrowser360SECount());
data.put("DeviceAndroidCount", this.getDeviceAndroidCount());
data.put("DeviceIpadCount", this.getDeviceIpadCount());
data.put("DeviceIphoneCount", this.getDeviceIphoneCount());
data.put("DeviceWindowsPhoneCount", this.getDeviceWindowsPhoneCount());
data.put("BotCount", this.getBotCount());
data.put("BotBaiduCount", this.getBotBaiduCount());
data.put("BotYoudaoCount", this.getBotYoudaoCount());
data.put("BotGoogleCount", this.getBotGoogleCount());
data.put("BotMsnCount", this.getBotMsnCount());
data.put("BotBingCount", this.getBotBingCount());
data.put("BotSosoCount", this.getBotSosoCount());
data.put("BotSogouCount", this.getBotSogouCount());
data.put("BotYahooCount", this.getBotYahooCount());
return data;
for (WebURIStat uriStat : this.uriStatMap.values()) {
WebURIStatValue statValue = uriStat.getValue(reset);
if (statValue.getRunningCount() == 0 && statValue.getRequestCount() == 0) {
continue;
}
list.add(statValue);
}
return list;
}
public List<Map<String, Object>> getURIStatDataList() {
@@ -871,7 +812,7 @@ public class WebAppStat {
} else if (userAgent.startsWith("Windows NT 6.1", 13)) {
osWindows7Count.incrementAndGet();
} else if (userAgent.startsWith("Windows NT 6.2", 13)) {
osWindows8Count.incrementAndGet();
@@ -913,11 +854,11 @@ public class WebAppStat {
isAndroid = userAgent.startsWith("Android", 20);
toffset = 28;
}
if (isAndroid) {
osAndroidCount.incrementAndGet();
deviceAndroidCount.incrementAndGet();
if (userAgent.startsWith("1.5", toffset)) {
osAndroid15Count.incrementAndGet();
} else if (userAgent.startsWith("1.6", toffset)) {
@@ -1001,7 +942,7 @@ public class WebAppStat {
public long getOSWindows7Count() {
return osWindows7Count.get();
}
public long getOSWindows8Count() {
return osWindows8Count.get();
}
@@ -1045,15 +986,15 @@ public class WebAppStat {
public long getOSAndroid40Count() {
return osAndroid40Count.get();
}
public long getOSAndroid41Count() {
return osAndroid41Count.get();
}
public long getOSAndroid42Count() {
return osAndroid42Count.get();
}
public long getOSAndroid43Count() {
return osAndroid43Count.get();
}
@@ -1162,4 +1103,81 @@ public class WebAppStat {
return botYahooCount.get();
}
public WebAppStatValue getStatValue(boolean reset) {
WebAppStatValue val = new WebAppStatValue();
val.setContextPath(contextPath);
val.setRunningCount(getRunningCount());
val.concurrentMax = get(concurrentMax, reset);
val.requestCount = get(requestCount, reset);
val.sessionCount = get(sessionCount, reset);
val.jdbcFetchRowCount = get(jdbcFetchRowCount, reset);
val.jdbcUpdateCount = get(jdbcUpdateCount, reset);
val.jdbcExecuteCount = get(jdbcExecuteCount, reset);
val.jdbcExecuteTimeNano = get(jdbcExecuteTimeNano, reset);
val.jdbcCommitCount = get(jdbcCommitCount, reset);
val.jdbcRollbackCount = get(jdbcRollbackCount, reset);
val.osMacOSXCount = get(osMacOSXCount, reset);
val.osWindowsCount = get(osWindowsCount, reset);
val.osLinuxCount = get(osLinuxCount, reset);
val.osSymbianCount = get(osSymbianCount, reset);
val.osFreeBSDCount = get(osFreeBSDCount, reset);
val.osOpenBSDCount = get(osOpenBSDCount, reset);
val.osAndroidCount = get(osAndroidCount, reset);
val.osWindows98Count = get(osWindows98Count, reset);
val.osWindowsXPCount = get(osWindowsXPCount, reset);
val.osWindows2000Count = get(osWindows2000Count, reset);
val.osWindowsVistaCount = get(osWindowsVistaCount, reset);
val.osWindows7Count = get(osWindows7Count, reset);
val.osWindows8Count = get(osWindows8Count, reset);
val.osAndroid15Count = get(osAndroid15Count, reset);
val.osAndroid16Count = get(osAndroid16Count, reset);
val.osAndroid20Count = get(osAndroid20Count, reset);
val.osAndroid21Count = get(osAndroid21Count, reset);
val.osAndroid22Count = get(osAndroid22Count, reset);
val.osAndroid23Count = get(osAndroid23Count, reset);
val.osAndroid30Count = get(osAndroid30Count, reset);
val.osAndroid31Count = get(osAndroid31Count, reset);
val.osAndroid32Count = get(osAndroid32Count, reset);
val.osAndroid40Count = get(osAndroid40Count, reset);
val.osAndroid41Count = get(osAndroid41Count, reset);
val.osAndroid42Count = get(osAndroid42Count, reset);
val.osAndroid43Count = get(osAndroid43Count, reset);
val.osLinuxUbuntuCount = get(osLinuxUbuntuCount, reset);
val.browserIECount = get(browserIECount, reset);
val.browserFirefoxCount = get(browserFirefoxCount, reset);
val.browserChromeCount = get(browserChromeCount, reset);
val.browserSafariCount = get(browserSafariCount, reset);
val.browserOperaCount = get(browserOperaCount, reset);
val.browserIE5Count = get(browserIE5Count, reset);
val.browserIE6Count = get(browserIE6Count, reset);
val.browserIE7Count = get(browserIE7Count, reset);
val.browserIE8Count = get(browserIE8Count, reset);
val.browserIE9Count = get(browserIE9Count, reset);
val.browserIE10Count = get(browserIE10Count, reset);
val.browser360SECount = get(browser360SECount, reset);
val.deviceAndroidCount = get(deviceAndroidCount, reset);
val.deviceIpadCount = get(deviceIpadCount, reset);
val.deviceIphoneCount = get(deviceIphoneCount, reset);
val.deviceWindowsPhoneCount = get(deviceWindowsPhoneCount, reset);
val.botCount = get(botCount, reset);
val.botBaiduCount = get(botBaiduCount, reset);
val.botYoudaoCount = get(botYoudaoCount, reset);
val.botGoogleCount = get(botGoogleCount, reset);
val.botMsnCount = get(botMsnCount, reset);
val.botBingCount = get(botBingCount, reset);
val.botSosoCount = get(botSosoCount, reset);
val.botSogouCount = get(botSogouCount, reset);
val.botYahooCount = get(botYahooCount, reset);
return val;
}
}
@@ -0,0 +1,683 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.http.stat;
import java.util.LinkedHashMap;
import java.util.Map;
public class WebAppStatValue {
String contextPath;
int runningCount;
int concurrentMax;
long requestCount;
long sessionCount;
long jdbcFetchRowCount;
long jdbcUpdateCount;
long jdbcExecuteCount;
long jdbcExecuteTimeNano;
long jdbcCommitCount;
long jdbcRollbackCount;
long osMacOSXCount;
long osWindowsCount;
long osLinuxCount;
long osSymbianCount;
long osFreeBSDCount;
long osOpenBSDCount;
long osAndroidCount;
long osWindows98Count;
long osWindowsXPCount;
long osWindows2000Count;
long osWindowsVistaCount;
long osWindows7Count;
long osWindows8Count;
long osAndroid15Count;
long osAndroid16Count;
long osAndroid20Count;
long osAndroid21Count;
long osAndroid22Count;
long osAndroid23Count;
long osAndroid30Count;
long osAndroid31Count;
long osAndroid32Count;
long osAndroid40Count;
long osAndroid41Count;
long osAndroid42Count;
long osAndroid43Count;
long osLinuxUbuntuCount;
long browserIECount;
long browserFirefoxCount;
long browserChromeCount;
long browserSafariCount;
long browserOperaCount;
long browserIE5Count;
long browserIE6Count;
long browserIE7Count;
long browserIE8Count;
long browserIE9Count;
long browserIE10Count;
long browser360SECount;
long deviceAndroidCount;
long deviceIpadCount;
long deviceIphoneCount;
long deviceWindowsPhoneCount;
long botCount;
long botBaiduCount;
long botYoudaoCount;
long botGoogleCount;
long botMsnCount;
long botBingCount;
long botSosoCount;
long botSogouCount;
long botYahooCount;
public String getContextPath() {
return contextPath;
}
public void setContextPath(String contextPath) {
this.contextPath = contextPath;
}
public int getRunningCount() {
return runningCount;
}
public void setRunningCount(int runningCount) {
this.runningCount = runningCount;
}
public int getConcurrentMax() {
return concurrentMax;
}
public void setConcurrentMax(int concurrentMax) {
this.concurrentMax = concurrentMax;
}
public long getRequestCount() {
return requestCount;
}
public void setRequestCount(long requestCount) {
this.requestCount = requestCount;
}
public long getSessionCount() {
return sessionCount;
}
public void setSessionCount(long sessionCount) {
this.sessionCount = sessionCount;
}
public long getJdbcFetchRowCount() {
return jdbcFetchRowCount;
}
public void setJdbcFetchRowCount(long jdbcFetchRowCount) {
this.jdbcFetchRowCount = jdbcFetchRowCount;
}
public long getJdbcUpdateCount() {
return jdbcUpdateCount;
}
public void setJdbcUpdateCount(long jdbcUpdateCount) {
this.jdbcUpdateCount = jdbcUpdateCount;
}
public long getJdbcExecuteCount() {
return jdbcExecuteCount;
}
public void setJdbcExecuteCount(long jdbcExecuteCount) {
this.jdbcExecuteCount = jdbcExecuteCount;
}
public long getJdbcExecuteTimeNano() {
return jdbcExecuteTimeNano;
}
public void setJdbcExecuteTimeNano(long jdbcExecuteTimeNano) {
this.jdbcExecuteTimeNano = jdbcExecuteTimeNano;
}
public long getJdbcCommitCount() {
return jdbcCommitCount;
}
public void setJdbcCommitCount(long jdbcCommitCount) {
this.jdbcCommitCount = jdbcCommitCount;
}
public long getJdbcRollbackCount() {
return jdbcRollbackCount;
}
public void setJdbcRollbackCount(long jdbcRollbackCount) {
this.jdbcRollbackCount = jdbcRollbackCount;
}
public long getOsMacOSXCount() {
return osMacOSXCount;
}
public void setOsMacOSXCount(long osMacOSXCount) {
this.osMacOSXCount = osMacOSXCount;
}
public long getOsWindowsCount() {
return osWindowsCount;
}
public void setOsWindowsCount(long osWindowsCount) {
this.osWindowsCount = osWindowsCount;
}
public long getOsLinuxCount() {
return osLinuxCount;
}
public void setOsLinuxCount(long osLinuxCount) {
this.osLinuxCount = osLinuxCount;
}
public long getOsSymbianCount() {
return osSymbianCount;
}
public void setOsSymbianCount(long osSymbianCount) {
this.osSymbianCount = osSymbianCount;
}
public long getOsFreeBSDCount() {
return osFreeBSDCount;
}
public void setOsFreeBSDCount(long osFreeBSDCount) {
this.osFreeBSDCount = osFreeBSDCount;
}
public long getOsOpenBSDCount() {
return osOpenBSDCount;
}
public void setOsOpenBSDCount(long osOpenBSDCount) {
this.osOpenBSDCount = osOpenBSDCount;
}
public long getOsAndroidCount() {
return osAndroidCount;
}
public void setOsAndroidCount(long osAndroidCount) {
this.osAndroidCount = osAndroidCount;
}
public long getOsWindows98Count() {
return osWindows98Count;
}
public void setOsWindows98Count(long osWindows98Count) {
this.osWindows98Count = osWindows98Count;
}
public long getOsWindowsXPCount() {
return osWindowsXPCount;
}
public void setOsWindowsXPCount(long osWindowsXPCount) {
this.osWindowsXPCount = osWindowsXPCount;
}
public long getOsWindows2000Count() {
return osWindows2000Count;
}
public void setOsWindows2000Count(long osWindows2000Count) {
this.osWindows2000Count = osWindows2000Count;
}
public long getOsWindowsVistaCount() {
return osWindowsVistaCount;
}
public void setOsWindowsVistaCount(long osWindowsVistaCount) {
this.osWindowsVistaCount = osWindowsVistaCount;
}
public long getOsWindows7Count() {
return osWindows7Count;
}
public void setOsWindows7Count(long osWindows7Count) {
this.osWindows7Count = osWindows7Count;
}
public long getOsWindows8Count() {
return osWindows8Count;
}
public void setOsWindows8Count(long osWindows8Count) {
this.osWindows8Count = osWindows8Count;
}
public long getOsAndroid15Count() {
return osAndroid15Count;
}
public void setOsAndroid15Count(long osAndroid15Count) {
this.osAndroid15Count = osAndroid15Count;
}
public long getOsAndroid16Count() {
return osAndroid16Count;
}
public void setOsAndroid16Count(long osAndroid16Count) {
this.osAndroid16Count = osAndroid16Count;
}
public long getOsAndroid20Count() {
return osAndroid20Count;
}
public void setOsAndroid20Count(long osAndroid20Count) {
this.osAndroid20Count = osAndroid20Count;
}
public long getOsAndroid21Count() {
return osAndroid21Count;
}
public void setOsAndroid21Count(long osAndroid21Count) {
this.osAndroid21Count = osAndroid21Count;
}
public long getOsAndroid22Count() {
return osAndroid22Count;
}
public void setOsAndroid22Count(long osAndroid22Count) {
this.osAndroid22Count = osAndroid22Count;
}
public long getOsAndroid23Count() {
return osAndroid23Count;
}
public void setOsAndroid23Count(long osAndroid23Count) {
this.osAndroid23Count = osAndroid23Count;
}
public long getOsAndroid30Count() {
return osAndroid30Count;
}
public void setOsAndroid30Count(long osAndroid30Count) {
this.osAndroid30Count = osAndroid30Count;
}
public long getOsAndroid31Count() {
return osAndroid31Count;
}
public void setOsAndroid31Count(long osAndroid31Count) {
this.osAndroid31Count = osAndroid31Count;
}
public long getOsAndroid32Count() {
return osAndroid32Count;
}
public void setOsAndroid32Count(long osAndroid32Count) {
this.osAndroid32Count = osAndroid32Count;
}
public long getOsAndroid40Count() {
return osAndroid40Count;
}
public void setOsAndroid40Count(long osAndroid40Count) {
this.osAndroid40Count = osAndroid40Count;
}
public long getOsAndroid41Count() {
return osAndroid41Count;
}
public void setOsAndroid41Count(long osAndroid41Count) {
this.osAndroid41Count = osAndroid41Count;
}
public long getOsAndroid42Count() {
return osAndroid42Count;
}
public void setOsAndroid42Count(long osAndroid42Count) {
this.osAndroid42Count = osAndroid42Count;
}
public long getOsAndroid43Count() {
return osAndroid43Count;
}
public void setOsAndroid43Count(long osAndroid43Count) {
this.osAndroid43Count = osAndroid43Count;
}
public long getOsLinuxUbuntuCount() {
return osLinuxUbuntuCount;
}
public void setOsLinuxUbuntuCount(long osLinuxUbuntuCount) {
this.osLinuxUbuntuCount = osLinuxUbuntuCount;
}
public long getBrowserIECount() {
return browserIECount;
}
public void setBrowserIECount(long browserIECount) {
this.browserIECount = browserIECount;
}
public long getBrowserFirefoxCount() {
return browserFirefoxCount;
}
public void setBrowserFirefoxCount(long browserFirefoxCount) {
this.browserFirefoxCount = browserFirefoxCount;
}
public long getBrowserChromeCount() {
return browserChromeCount;
}
public void setBrowserChromeCount(long browserChromeCount) {
this.browserChromeCount = browserChromeCount;
}
public long getBrowserSafariCount() {
return browserSafariCount;
}
public void setBrowserSafariCount(long browserSafariCount) {
this.browserSafariCount = browserSafariCount;
}
public long getBrowserOperaCount() {
return browserOperaCount;
}
public void setBrowserOperaCount(long browserOperaCount) {
this.browserOperaCount = browserOperaCount;
}
public long getBrowserIE5Count() {
return browserIE5Count;
}
public void setBrowserIE5Count(long browserIE5Count) {
this.browserIE5Count = browserIE5Count;
}
public long getBrowserIE6Count() {
return browserIE6Count;
}
public void setBrowserIE6Count(long browserIE6Count) {
this.browserIE6Count = browserIE6Count;
}
public long getBrowserIE7Count() {
return browserIE7Count;
}
public void setBrowserIE7Count(long browserIE7Count) {
this.browserIE7Count = browserIE7Count;
}
public long getBrowserIE8Count() {
return browserIE8Count;
}
public void setBrowserIE8Count(long browserIE8Count) {
this.browserIE8Count = browserIE8Count;
}
public long getBrowserIE9Count() {
return browserIE9Count;
}
public void setBrowserIE9Count(long browserIE9Count) {
this.browserIE9Count = browserIE9Count;
}
public long getBrowserIE10Count() {
return browserIE10Count;
}
public void setBrowserIE10Count(long browserIE10Count) {
this.browserIE10Count = browserIE10Count;
}
public long getBrowser360SECount() {
return browser360SECount;
}
public void setBrowser360SECount(long browser360seCount) {
browser360SECount = browser360seCount;
}
public long getDeviceAndroidCount() {
return deviceAndroidCount;
}
public void setDeviceAndroidCount(long deviceAndroidCount) {
this.deviceAndroidCount = deviceAndroidCount;
}
public long getDeviceIpadCount() {
return deviceIpadCount;
}
public void setDeviceIpadCount(long deviceIpadCount) {
this.deviceIpadCount = deviceIpadCount;
}
public long getDeviceIphoneCount() {
return deviceIphoneCount;
}
public void setDeviceIphoneCount(long deviceIphoneCount) {
this.deviceIphoneCount = deviceIphoneCount;
}
public long getDeviceWindowsPhoneCount() {
return deviceWindowsPhoneCount;
}
public void setDeviceWindowsPhoneCount(long deviceWindowsPhoneCount) {
this.deviceWindowsPhoneCount = deviceWindowsPhoneCount;
}
public long getBotCount() {
return botCount;
}
public void setBotCount(long botCount) {
this.botCount = botCount;
}
public long getBotBaiduCount() {
return botBaiduCount;
}
public void setBotBaiduCount(long botBaiduCount) {
this.botBaiduCount = botBaiduCount;
}
public long getBotYoudaoCount() {
return botYoudaoCount;
}
public void setBotYoudaoCount(long botYoudaoCount) {
this.botYoudaoCount = botYoudaoCount;
}
public long getBotGoogleCount() {
return botGoogleCount;
}
public void setBotGoogleCount(long botGoogleCount) {
this.botGoogleCount = botGoogleCount;
}
public long getBotMsnCount() {
return botMsnCount;
}
public void setBotMsnCount(long botMsnCount) {
this.botMsnCount = botMsnCount;
}
public long getBotBingCount() {
return botBingCount;
}
public void setBotBingCount(long botBingCount) {
this.botBingCount = botBingCount;
}
public long getBotSosoCount() {
return botSosoCount;
}
public void setBotSosoCount(long botSosoCount) {
this.botSosoCount = botSosoCount;
}
public long getBotSogouCount() {
return botSogouCount;
}
public void setBotSogouCount(long botSogouCount) {
this.botSogouCount = botSogouCount;
}
public long getBotYahooCount() {
return botYahooCount;
}
public void setBotYahooCount(long botYahooCount) {
this.botYahooCount = botYahooCount;
}
public long getJdbcExecuteTimeMillis() {
return getJdbcExecuteTimeNano() / (1000 * 1000);
}
public Map<String, Object> getStatData() {
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("ContextPath", this.getContextPath());
data.put("RunningCount", this.getRunningCount());
data.put("ConcurrentMax", this.getConcurrentMax());
data.put("RequestCount", this.getRequestCount());
data.put("SessionCount", this.getSessionCount());
data.put("JdbcCommitCount", this.getJdbcCommitCount());
data.put("JdbcRollbackCount", this.getJdbcRollbackCount());
data.put("JdbcExecuteCount", this.getJdbcExecuteCount());
data.put("JdbcExecuteTimeMillis", this.getJdbcExecuteTimeMillis());
data.put("JdbcFetchRowCount", this.getJdbcFetchRowCount());
data.put("JdbcUpdateCount", this.getJdbcUpdateCount());
data.put("OSMacOSXCount", this.getOsMacOSXCount());
data.put("OSWindowsCount", this.getOsWindowsCount());
data.put("OSLinuxCount", this.getOsLinuxCount());
data.put("OSSymbianCount", this.getOsSymbianCount());
data.put("OSFreeBSDCount", this.getOsFreeBSDCount());
data.put("OSOpenBSDCount", this.getOsOpenBSDCount());
data.put("OSAndroidCount", this.getOsAndroidCount());
data.put("OSWindows98Count", this.getOsWindows98Count());
data.put("OSWindowsXPCount", this.getOsWindowsXPCount());
data.put("OSWindows2000Count", this.getOsWindows2000Count());
data.put("OSWindowsVistaCount", this.getOsWindowsVistaCount());
data.put("OSWindows7Count", this.getOsWindows7Count());
data.put("OSWindows8Count", this.getOsWindows8Count());
data.put("OSAndroid15Count", this.getOsAndroid15Count());
data.put("OSAndroid16Count", this.getOsAndroid16Count());
data.put("OSAndroid20Count", this.getOsAndroid20Count());
data.put("OSAndroid21Count", this.getOsAndroid21Count());
data.put("OSAndroid22Count", this.getOsAndroid22Count());
data.put("OSAndroid23Count", this.getOsAndroid23Count());
data.put("OSAndroid30Count", this.getOsAndroid30Count());
data.put("OSAndroid31Count", this.getOsAndroid31Count());
data.put("OSAndroid32Count", this.getOsAndroid32Count());
data.put("OSAndroid40Count", this.getOsAndroid40Count());
data.put("OSAndroid41Count", this.getOsAndroid41Count());
data.put("OSAndroid42Count", this.getOsAndroid42Count());
data.put("OSAndroid43Count", this.getOsAndroid43Count());
data.put("OSLinuxUbuntuCount", this.getOsLinuxUbuntuCount());
data.put("BrowserIECount", this.getBrowserIECount());
data.put("BrowserFirefoxCount", this.getBrowserFirefoxCount());
data.put("BrowserChromeCount", this.getBrowserChromeCount());
data.put("BrowserSafariCount", this.getBrowserSafariCount());
data.put("BrowserOperaCount", this.getBrowserOperaCount());
data.put("BrowserIE5Count", this.getBrowserIE5Count());
data.put("BrowserIE6Count", this.getBrowserIE6Count());
data.put("BrowserIE7Count", this.getBrowserIE7Count());
data.put("BrowserIE8Count", this.getBrowserIE8Count());
data.put("BrowserIE9Count", this.getBrowserIE9Count());
data.put("BrowserIE10Count", this.getBrowserIE10Count());
data.put("Browser360SECount", this.getBrowser360SECount());
data.put("DeviceAndroidCount", this.getDeviceAndroidCount());
data.put("DeviceIpadCount", this.getDeviceIpadCount());
data.put("DeviceIphoneCount", this.getDeviceIphoneCount());
data.put("DeviceWindowsPhoneCount", this.getDeviceWindowsPhoneCount());
data.put("BotCount", this.getBotCount());
data.put("BotBaiduCount", this.getBotBaiduCount());
data.put("BotYoudaoCount", this.getBotYoudaoCount());
data.put("BotGoogleCount", this.getBotGoogleCount());
data.put("BotMsnCount", this.getBotMsnCount());
data.put("BotBingCount", this.getBotBingCount());
data.put("BotSosoCount", this.getBotSosoCount());
data.put("BotSogouCount", this.getBotSogouCount());
data.put("BotYahooCount", this.getBotYahooCount());
return data;
}
}
@@ -15,8 +15,8 @@
*/
package com.alibaba.druid.support.http.stat;
import java.util.Date;
import java.util.LinkedHashMap;
import static com.alibaba.druid.util.JdbcSqlStatUtils.get;
import java.util.Map;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
@@ -154,14 +154,6 @@ public class WebSessionStat {
return createTimeMillis;
}
public Date getCreateTime() {
if (createTimeMillis == -1L) {
return null;
}
return new Date(createTimeMillis);
}
public String getPrincipal() {
return principal;
}
@@ -178,14 +170,6 @@ public class WebSessionStat {
return lastAccessTimeMillis;
}
public Date getLastAccessTime() {
if (lastAccessTimeMillis < 0L) {
return null;
}
return new Date(lastAccessTimeMillis);
}
public String getRemoteAddress() {
return remoteAddresses;
}
@@ -307,10 +291,6 @@ public class WebSessionStat {
return requestTimeNano;
}
public long getRequestTimeMillis() {
return getRequestTimeNano() / (1000 * 1000);
}
public void addJdbcFetchRowCount(long delta) {
jdbcFetchRowCountUpdater.addAndGet(this, delta);
}
@@ -339,10 +319,6 @@ public class WebSessionStat {
return jdbcExecuteCount;
}
public long getJdbcExecuteTimeMillis() {
return getJdbcExecuteTimeNano() / (1000 * 1000);
}
public long getJdbcExecuteTimeNano() {
return jdbcExecuteTimeNano;
}
@@ -391,30 +367,40 @@ public class WebSessionStat {
}
public Map<String, Object> getStatData() {
Map<String, Object> data = new LinkedHashMap<String, Object>();
return getValue(false).getStatData();
}
data.put("SESSIONID", this.getSessionId());
data.put("Principal", this.getPrincipal());
data.put("RunningCount", this.getRunningCount());
data.put("ConcurrentMax", this.getConcurrentMax());
data.put("RequestCount", this.getRequestCount());
data.put("RequestTimeMillisTotal", this.getRequestTimeMillis());
data.put("CreateTime", this.getCreateTime());
data.put("LastAccessTime", this.getLastAccessTime());
data.put("RemoteAddress", this.getRemoteAddress());
data.put("Principal", this.getPrincipal());
public WebSessionStatValue getValue(boolean reset) {
WebSessionStatValue val = new WebSessionStatValue();
data.put("JdbcCommitCount", this.getJdbcCommitCount());
data.put("JdbcRollbackCount", this.getJdbcRollbackCount());
val.sessionId = sessionId;
val.runningCount = this.getRunningCount();
val.concurrentMax = get(this, concurrentMaxUpdater, reset);
val.requestErrorCount = get(this, requestErrorCountUpdater, reset);
val.requestTimeNano = get(this, requestTimeNanoUpdater, reset);
val.jdbcFetchRowCount = get(this, jdbcFetchRowCountUpdater, reset);
val.jdbcUpdateCount = get(this, jdbcUpdateCountUpdater, reset);
val.jdbcExecuteCount = get(this, jdbcExecuteCountUpdater, reset);
val.jdbcExecuteTimeNano = get(this, jdbcExecuteTimeNanoUpdater, reset);
val.jdbcCommitCount = get(this, jdbcCommitCountUpdater, reset);
val.jdbcRollbackCount = get(this, jdbcRollbackCountUpdater, reset);
val.createTimeMillis = createTimeMillis;
val.lastAccessTimeMillis = lastAccessTimeMillis;
val.remoteAddresse = remoteAddresses;
val.principal = principal;
val.userAgent = userAgent;
data.put("JdbcExecuteCount", this.getJdbcExecuteCount());
data.put("JdbcExecuteTimeMillis", this.getJdbcExecuteTimeMillis());
data.put("JdbcFetchRowCount", this.getJdbcFetchRowCount());
data.put("JdbcUpdateCount", this.getJdbcUpdateCount());
val.requestIntervalHistogram_0_1 = get(this, requestIntervalHistogram_0_1_Updater, reset);
val.requestIntervalHistogram_1_10 = get(this, requestIntervalHistogram_1_10_Updater, reset);
val.requestIntervalHistogram_10_100 = get(this, requestIntervalHistogram_10_100_Updater, reset);
val.requestIntervalHistogram_100_1000 = get(this, requestIntervalHistogram_100_1000_Updater, reset);
val.requestIntervalHistogram_1000_10000 = get(this, requestIntervalHistogram_1000_10000_Updater, reset);
val.requestIntervalHistogram_10000_100000 = get(this, requestIntervalHistogram_10000_100000_Updater, reset);
val.requestIntervalHistogram_100000_1000000 = get(this, requestIntervalHistogram_100000_1000000_Updater, reset);
val.requestIntervalHistogram_1000000_10000000 = get(this, requestIntervalHistogram_1000000_10000000_Updater,
reset);
val.requestIntervalHistogram_10000000_more = get(this, requestIntervalHistogram_10000000_more_Updater, reset);
data.put("UserAgent", this.getUserAgent());
data.put("RequestInterval", this.getRequestInterval());
return data;
return val;
}
}
@@ -0,0 +1,255 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.http.stat;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
public class WebSessionStatValue {
String sessionId;
int runningCount;
int concurrentMax;
long requestCount;
long requestErrorCount;
long requestTimeNano;
long jdbcFetchRowCount;
long jdbcUpdateCount;
long jdbcExecuteCount;
long jdbcExecuteTimeNano;
long jdbcCommitCount;
long jdbcRollbackCount;
long createTimeMillis;
long lastAccessTimeMillis;
String remoteAddresse;
String principal;
String userAgent;
int requestIntervalHistogram_0_1;
int requestIntervalHistogram_1_10;
int requestIntervalHistogram_10_100;
int requestIntervalHistogram_100_1000;
int requestIntervalHistogram_1000_10000;
int requestIntervalHistogram_10000_100000;
int requestIntervalHistogram_100000_1000000;
int requestIntervalHistogram_1000000_10000000;
int requestIntervalHistogram_10000000_more;
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
public int getRunningCount() {
return runningCount;
}
public void setRunningCount(int runningCount) {
this.runningCount = runningCount;
}
public int getConcurrentMax() {
return concurrentMax;
}
public void setConcurrentMax(int concurrentMax) {
this.concurrentMax = concurrentMax;
}
public long getRequestCount() {
return requestCount;
}
public void setRequestCount(long requestCount) {
this.requestCount = requestCount;
}
public long getRequestErrorCount() {
return requestErrorCount;
}
public void setRequestErrorCount(long requestErrorCount) {
this.requestErrorCount = requestErrorCount;
}
public long getRequestTimeNano() {
return requestTimeNano;
}
public void setRequestTimeNano(long requestTimeNano) {
this.requestTimeNano = requestTimeNano;
}
public long getJdbcFetchRowCount() {
return jdbcFetchRowCount;
}
public void setJdbcFetchRowCount(long jdbcFetchRowCount) {
this.jdbcFetchRowCount = jdbcFetchRowCount;
}
public long getJdbcUpdateCount() {
return jdbcUpdateCount;
}
public void setJdbcUpdateCount(long jdbcUpdateCount) {
this.jdbcUpdateCount = jdbcUpdateCount;
}
public long getJdbcExecuteCount() {
return jdbcExecuteCount;
}
public void setJdbcExecuteCount(long jdbcExecuteCount) {
this.jdbcExecuteCount = jdbcExecuteCount;
}
public long getJdbcExecuteTimeNano() {
return jdbcExecuteTimeNano;
}
public void setJdbcExecuteTimeNano(long jdbcExecuteTimeNano) {
this.jdbcExecuteTimeNano = jdbcExecuteTimeNano;
}
public long getJdbcCommitCount() {
return jdbcCommitCount;
}
public void setJdbcCommitCount(long jdbcCommitCount) {
this.jdbcCommitCount = jdbcCommitCount;
}
public long getJdbcRollbackCount() {
return jdbcRollbackCount;
}
public void setJdbcRollbackCount(long jdbcRollbackCount) {
this.jdbcRollbackCount = jdbcRollbackCount;
}
public long getCreateTimeMillis() {
return createTimeMillis;
}
public void setCreateTimeMillis(long createTimeMillis) {
this.createTimeMillis = createTimeMillis;
}
public long getLastAccessTimeMillis() {
return lastAccessTimeMillis;
}
public void setLastAccessTimeMillis(long lastAccessTimeMillis) {
this.lastAccessTimeMillis = lastAccessTimeMillis;
}
public String getRemoteAddresse() {
return remoteAddresse;
}
public void setRemoteAddresse(String remoteAddresses) {
this.remoteAddresse = remoteAddresses;
}
public String getPrincipal() {
return principal;
}
public void setPrincipal(String principal) {
this.principal = principal;
}
public String getUserAgent() {
return userAgent;
}
public void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}
public long getRequestTimeMillis() {
return getRequestTimeNano() / (1000 * 1000);
}
public Date getCreateTime() {
if (createTimeMillis == -1L) {
return null;
}
return new Date(createTimeMillis);
}
public Date getLastAccessTime() {
if (lastAccessTimeMillis < 0L) {
return null;
}
return new Date(lastAccessTimeMillis);
}
public long getJdbcExecuteTimeMillis() {
return getJdbcExecuteTimeNano() / (1000 * 1000);
}
public long[] getRequestInterval() {
return new long[] {
//
requestIntervalHistogram_0_1, //
requestIntervalHistogram_1_10, //
requestIntervalHistogram_10_100, //
requestIntervalHistogram_100_1000, //
requestIntervalHistogram_1000_10000, //
requestIntervalHistogram_10000_100000, //
requestIntervalHistogram_100000_1000000, //
requestIntervalHistogram_1000000_10000000, //
requestIntervalHistogram_10000000_more //
};
}
public Map<String, Object> getStatData() {
Map<String, Object> data = new LinkedHashMap<String, Object>();
data.put("SESSIONID", this.getSessionId());
data.put("Principal", this.getPrincipal());
data.put("RunningCount", this.getRunningCount());
data.put("ConcurrentMax", this.getConcurrentMax());
data.put("RequestCount", this.getRequestCount());
data.put("RequestTimeMillisTotal", this.getRequestTimeMillis());
data.put("CreateTime", this.getCreateTime());
data.put("LastAccessTime", this.getLastAccessTime());
data.put("RemoteAddress", this.getRemoteAddresse());
data.put("Principal", this.getPrincipal());
data.put("JdbcCommitCount", this.getJdbcCommitCount());
data.put("JdbcRollbackCount", this.getJdbcRollbackCount());
data.put("JdbcExecuteCount", this.getJdbcExecuteCount());
data.put("JdbcExecuteTimeMillis", this.getJdbcExecuteTimeMillis());
data.put("JdbcFetchRowCount", this.getJdbcFetchRowCount());
data.put("JdbcUpdateCount", this.getJdbcUpdateCount());
data.put("UserAgent", this.getUserAgent());
data.put("RequestInterval", this.getRequestInterval());
return data;
}
}
@@ -1,19 +1,31 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.monitor;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
public class MonitorContext {
private String appName;
private Date collectTime;
private final Map<String, Object> atrributes = new HashMap<String, Object>();
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
private Date collectTime;
private int pid;
private Date startTime;
public Date getCollectTime() {
return collectTime;
@@ -23,4 +35,24 @@ public class MonitorContext {
this.collectTime = collectTime;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Map<String, Object> getAtrributes() {
return atrributes;
}
public int getPID() {
return pid;
}
public void setPID(int pid) {
this.pid = pid;
}
}
@@ -1,10 +1,40 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.monitor;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidDataSourceStatValue;
import com.alibaba.druid.stat.DruidDataSourceStatManager;
import com.alibaba.druid.support.http.stat.WebAppStat;
import com.alibaba.druid.support.http.stat.WebAppStatManager;
import com.alibaba.druid.support.http.stat.WebAppStatValue;
import com.alibaba.druid.support.http.stat.WebURIStatValue;
import com.alibaba.druid.support.monitor.dao.MonitorDao;
import com.alibaba.druid.support.spring.stat.SpringMethodStatValue;
import com.alibaba.druid.support.spring.stat.SpringStat;
import com.alibaba.druid.support.spring.stat.SpringStatManager;
import com.alibaba.druid.util.IOUtils;
public class MonitorService {
@@ -26,6 +56,7 @@ public class MonitorService {
}
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
collectSql();
@@ -33,6 +64,7 @@ public class MonitorService {
}, timeBeetweenSqlCollect, timeBeetweenSqlCollect, timeUnit);
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
collectSpringMethod();
@@ -40,6 +72,7 @@ public class MonitorService {
}, timeBeetweenSpringCollect, timeBeetweenSpringCollect, timeUnit);
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
collectWebURI();
@@ -55,16 +88,70 @@ public class MonitorService {
this.scheduler = scheduler;
}
@SuppressWarnings("resource")
private void collectSql() {
Set<Object> dataSources = DruidDataSourceStatManager.getInstances().keySet();
List<DruidDataSourceStatValue> statValueList = new ArrayList<DruidDataSourceStatValue>(dataSources.size());
for (Object item : dataSources) {
if (!(item instanceof DruidDataSource)) {
continue;
}
DruidDataSource dataSource = (DruidDataSource) item;
DruidDataSourceStatValue statValue = dataSource.getStatValueAndReset();
statValueList.add(statValue);
}
MonitorContext ctx = createContext();
dao.saveSql(ctx, statValueList);
}
private MonitorContext createContext() {
MonitorContext ctx = new MonitorContext();
ctx.setCollectTime(new Date());
ctx.setPID(IOUtils.getPID());
ctx.setCollectTime(IOUtils.getStartTime());
return ctx;
}
private void collectSpringMethod() {
List<SpringMethodStatValue> statValueList = new ArrayList<SpringMethodStatValue>();
Set<Object> stats = SpringStatManager.getInstance().getSpringStatSet();
for (Object item : stats) {
if (!(item instanceof SpringStat)) {
continue;
}
SpringStat sprintStat = (SpringStat) item;
statValueList.addAll(sprintStat.getStatList(true));
}
MonitorContext ctx = createContext();
dao.saveSpringMethod(ctx, statValueList);
}
private void collectWebURI() {
List<WebURIStatValue> webURIValueList = new ArrayList<WebURIStatValue>();
List<WebAppStatValue> webAppStatValueList = new ArrayList<WebAppStatValue>();
Set<Object> stats = WebAppStatManager.getInstance().getWebAppStatSet();
for (Object item : stats) {
if (!(item instanceof WebAppStat)) {
continue;
}
WebAppStat webAppStat = (WebAppStat) item;
webURIValueList.addAll(webAppStat.getURIStatValueList(true));
}
MonitorContext ctx = createContext();
dao.saveWebURI(ctx, webURIValueList);
dao.saveWebApp(ctx, webAppStatValueList);
}
public MonitorDao getDao() {
@@ -1,17 +1,35 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.monitor.dao;
import java.util.List;
import com.alibaba.druid.stat.JdbcSqlStatValue;
import com.alibaba.druid.pool.DruidDataSourceStatValue;
import com.alibaba.druid.support.http.stat.WebAppStatValue;
import com.alibaba.druid.support.http.stat.WebURIStatValue;
import com.alibaba.druid.support.monitor.MonitorContext;
import com.alibaba.druid.support.spring.stat.SpringMethodStatValue;
public interface MonitorDao {
void saveSql(MonitorContext ctx, List<JdbcSqlStatValue> sqlList);
void saveSql(MonitorContext ctx, List<DruidDataSourceStatValue> statList);
void saveSpringMethod(MonitorContext ctx, List<SpringMethodStatValue> methodList);
void saveWebURI(MonitorContext ctx, List<WebURIStatValue> uriList);
void saveWebApp(MonitorContext ctx, List<WebAppStatValue> uriList);
}
@@ -1,8 +1,24 @@
/*
* Copyright 1999-2011 Alibaba Group Holding Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.alibaba.druid.support.monitor.dao;
import java.util.List;
import com.alibaba.druid.stat.JdbcSqlStatValue;
import com.alibaba.druid.pool.DruidDataSourceStatValue;
import com.alibaba.druid.support.http.stat.WebAppStatValue;
import com.alibaba.druid.support.http.stat.WebURIStatValue;
import com.alibaba.druid.support.monitor.MonitorContext;
import com.alibaba.druid.support.spring.stat.SpringMethodStatValue;
@@ -10,7 +26,7 @@ import com.alibaba.druid.support.spring.stat.SpringMethodStatValue;
public class MonitorDaoJdbcImpl implements MonitorDao {
@Override
public void saveSql(MonitorContext ctx, List<JdbcSqlStatValue> sqlList) {
public void saveSql(MonitorContext ctx, List<DruidDataSourceStatValue> dataSourceList) {
}
@@ -24,4 +40,9 @@ public class MonitorDaoJdbcImpl implements MonitorDao {
}
@Override
public void saveWebApp(MonitorContext ctx, List<WebAppStatValue> uriList) {
}
}
@@ -48,6 +48,22 @@ public class SpringStat {
return methodStat;
}
public List<SpringMethodStatValue> getStatList(boolean reset) {
List<SpringMethodStatValue> statValueList = new ArrayList<SpringMethodStatValue>(this.methodStats.size());
for (SpringMethodStat methodStat : this.methodStats.values()) {
SpringMethodStatValue statValue = methodStat.getStatValue(reset);
if (statValue.getRunningCount() == 0 && statValue.getExecuteCount() == 0) {
continue;
}
statValueList.add(statValue);
}
return statValueList;
}
public List<Map<String, Object>> getMethodStatDataList() {
List<Map<String, Object>> methodStatDataList = new ArrayList<Map<String, Object>>(this.methodStats.size());
@@ -24,7 +24,9 @@ import java.io.PrintWriter;
import java.io.Reader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.lang.management.ManagementFactory;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
public class IOUtils {
@@ -221,4 +223,27 @@ public class IOUtils {
return null;
}
}
private static int pid;
public final static int getPID() {
if (pid == 0) {
String name = ManagementFactory.getRuntimeMXBean().getName();
String[] items = name.split("@");
pid = Integer.parseInt(items[0]);
}
return pid;
}
private static Date startTime;
public final static Date getStartTime() {
if (startTime == null) {
startTime = new Date(ManagementFactory.getRuntimeMXBean().getStartTime());
}
return startTime;
}
}