mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
Merge remote-tracking branch 'main/master'
Conflicts: src/main/resources/support/http/resources/js/common.js
This commit is contained in:
@@ -207,6 +207,7 @@ public class WebStatFilter implements Filter {
|
||||
}
|
||||
|
||||
webAppStat.computeUserAgent(userAgent);
|
||||
webAppStat.incrementSessionCount();
|
||||
}
|
||||
|
||||
sessionStat.setUserAgent(userAgent);
|
||||
|
||||
@@ -46,6 +46,7 @@ public class WebAppStat {
|
||||
private final AtomicInteger runningCount = new AtomicInteger();
|
||||
private final AtomicInteger concurrentMax = new AtomicInteger();
|
||||
private final AtomicLong requestCount = new AtomicLong(0);
|
||||
private final AtomicLong sessionCount = new AtomicLong(0);
|
||||
|
||||
private final AtomicLong jdbcFetchRowCount = new AtomicLong();
|
||||
private final AtomicLong jdbcUpdateCount = new AtomicLong();
|
||||
@@ -130,6 +131,7 @@ public class WebAppStat {
|
||||
concurrentMax.set(0);
|
||||
requestCount.set(0);
|
||||
requestCount.set(0);
|
||||
sessionCount.set(0);
|
||||
|
||||
jdbcFetchRowCount.set(0);
|
||||
jdbcUpdateCount.set(0);
|
||||
@@ -356,6 +358,14 @@ public class WebAppStat {
|
||||
}
|
||||
}
|
||||
|
||||
public void incrementSessionCount() {
|
||||
sessionCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public long getSessionCount() {
|
||||
return sessionCount.get();
|
||||
}
|
||||
|
||||
public void addJdbcFetchRowCount(long delta) {
|
||||
this.jdbcFetchRowCount.addAndGet(delta);
|
||||
}
|
||||
@@ -455,6 +465,7 @@ public class WebAppStat {
|
||||
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());
|
||||
|
||||
@@ -29,7 +29,7 @@ public class MapComparator<K extends Object, V extends Object> implements Compar
|
||||
private boolean isDesc;
|
||||
private K orderByKey;
|
||||
|
||||
public MapComparator(K orderByKey, boolean isDesc) {
|
||||
public MapComparator(K orderByKey, boolean isDesc){
|
||||
this.orderByKey = orderByKey;
|
||||
this.isDesc = isDesc;
|
||||
}
|
||||
@@ -58,19 +58,23 @@ public class MapComparator<K extends Object, V extends Object> implements Compar
|
||||
private Object getValueByKey(Map<K, V> map, K key) {
|
||||
if (key instanceof String) {
|
||||
String keyStr = (String) key;
|
||||
|
||||
if (keyStr.matches(".+\\[[0-9]+\\]")) {
|
||||
Object value = map.get(keyStr.substring(0, keyStr.indexOf("[")));
|
||||
if (value == null) return null;
|
||||
|
||||
Integer index = StringUtils.subStringToInteger(keyStr, "[", "]");
|
||||
if (value.getClass().isArray() && Array.getLength(value) >= index) {
|
||||
return Array.get(value, index);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return map.get(key);
|
||||
}
|
||||
|
||||
public int compare_0(Map<K, V> o1, Map<K, V> o2) {
|
||||
private int compare_0(Map<K, V> o1, Map<K, V> o2) {
|
||||
Object v1 = getValueByKey(o1, orderByKey);
|
||||
Object v2 = getValueByKey(o2, orderByKey);
|
||||
|
||||
|
||||
@@ -41,9 +41,9 @@ druid.common = function () {
|
||||
buildFooter : function() {
|
||||
var html = '<footer class="footer">'+
|
||||
' <div class="container">'+
|
||||
' powered by <a href="https://github.com/AlibabaTech/" target="_blank">AlibabaTech</a> & <a href="mailto:sandzhangtoo@gmail.com" target="_blank">sandzhang</a> & <a href="http://melin.iteye.com/" target="_blank">melin</a>'+
|
||||
' </div>'+
|
||||
'</footer>';
|
||||
' powered by <a href="https://github.com/AlibabaTech/" target="_blank">AlibabaTech</a> & <a href="http://www.sandzhang.com/" target="_blank">sandzhang</a> & <a href="http://melin.iteye.com/" target="_blank">melin</a>'+
|
||||
' </div>'+
|
||||
'</footer>';
|
||||
$(document.body).append(html);
|
||||
},
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
"RunningCount",
|
||||
"ConcurrentMax",
|
||||
"RequestCount",
|
||||
"SessionCount",
|
||||
|
||||
"JdbcCommitCount",
|
||||
"JdbcRollbackCount",
|
||||
|
||||
@@ -23,9 +23,10 @@
|
||||
<th><a id="th-URI" >URI</a></th>
|
||||
<th width="50"><a id="th-RequestCount" >RequestCount</a></th>
|
||||
<th width="50"><a id="th-RequestTimeMillis" >RequestTime</a></th>
|
||||
<th width="50"><a id="th-RunningCount" >RunningCount</a></th>
|
||||
<th width="50"><a id="th-RunningCount" >Running</a></th>
|
||||
<th width="50" title="Concurrent Max"><a id="th-ConcurrentMax" >Concurrent</a></th>
|
||||
<th width="50" title="Jdbc Execute Count"><a id="th-JdbcExecuteCount" >JdbcCount </a></th>
|
||||
<th width="50" title="Jdbc Execute Count"><a id="th-JdbcExecuteCount" >JdbcCount</a></th>
|
||||
<th width="50" title="Jdbc Execute Error Count"><a id="th-JdbcExecuteErrorCount" >JdbcError</a></th>
|
||||
<th width="50" title="Jdbc Execute Time"><a id="th-JdbcExecuteTimeMillis" >JdbcTime</a></th>
|
||||
<th width="50"><a id="th-JdbcCommitCount" >JdbcCommit</a></th>
|
||||
<th width="50"><a id="th-JdbcRollbackCount" >JdbcRollback</a></th>
|
||||
@@ -75,6 +76,7 @@
|
||||
html += "<td>" + stat.RunningCount + "</td>";
|
||||
html += "<td>" + stat.ConcurrentMax + "</td>";
|
||||
html += "<td>" + stat.JdbcExecuteCount + "</td>";
|
||||
html += "<td>" + stat.JdbcExecuteErrorCount + "</td>";
|
||||
html += "<td>" + stat.JdbcExecuteTimeMillis + "</td>";
|
||||
html += "<td>" + stat.JdbcCommitCount + "</td>";
|
||||
html += "<td>" + stat.JdbcRollbackCount + "</td>";
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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.util;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class MapComparatorTest extends TestCase {
|
||||
|
||||
private String orderByKey = "orderby";
|
||||
|
||||
public void test_comparator_date() throws Exception {
|
||||
test_comparator_date_0(true);
|
||||
test_comparator_date_0(false);
|
||||
}
|
||||
|
||||
public void test_comparator_String() throws Exception {
|
||||
test_comparator_string_0(true);
|
||||
test_comparator_string_0(false);
|
||||
}
|
||||
|
||||
public void test_comparator_number() throws Exception {
|
||||
test_comparator_number_0(true);
|
||||
test_comparator_number_0(false);
|
||||
}
|
||||
|
||||
public void test_comparator_array() throws Exception {
|
||||
test_comparator_array_0(true);
|
||||
test_comparator_array_0(false);
|
||||
}
|
||||
|
||||
private void test_comparator_array_0(boolean desc) throws Exception {
|
||||
String orderByKey = "orderby";
|
||||
long now = System.currentTimeMillis();
|
||||
MapComparator<String, Date[]> comparator = new MapComparator<String, Date[]>(orderByKey + "[0]", desc);
|
||||
|
||||
Map<String, Date[]> map1 = new HashMap<String, Date[]>();
|
||||
Map<String, Date[]> map2 = new HashMap<String, Date[]>();
|
||||
|
||||
map1.put(orderByKey, new Date[] { new Date(now) });
|
||||
map2.put(orderByKey, new Date[] { new Date(now - 1) });
|
||||
Assert.assertEquals(!desc, comparator.compare(map1, map2) > 0);
|
||||
|
||||
map2.put(orderByKey, new Date[] { new Date(now) });
|
||||
Assert.assertEquals(true, comparator.compare(map1, map2) == 0);
|
||||
|
||||
map2.put(orderByKey, new Date[] { new Date(now + 1) });
|
||||
Assert.assertEquals(!desc, comparator.compare(map1, map2) < 0);
|
||||
|
||||
map2.put(orderByKey, null);
|
||||
Assert.assertEquals(!desc, comparator.compare(map1, map2) > 0);
|
||||
|
||||
map1.put(orderByKey, null);
|
||||
map2.put(orderByKey, new Date[] { new Date(now) });
|
||||
Assert.assertEquals(!desc, comparator.compare(map1, map2) < 0);
|
||||
|
||||
map1.put(orderByKey, null);
|
||||
map2.put(orderByKey, null);
|
||||
Assert.assertEquals(true, comparator.compare(map1, map2) == 0);
|
||||
|
||||
}
|
||||
|
||||
private void test_comparator_date_0(boolean desc) throws Exception {
|
||||
long now = System.currentTimeMillis();
|
||||
MapComparator<String, Date> comparator = new MapComparator<String, Date>(orderByKey, desc);
|
||||
|
||||
Map<String, Date> map1 = new HashMap<String, Date>();
|
||||
Map<String, Date> map2 = new HashMap<String, Date>();
|
||||
|
||||
map1.put(orderByKey, new Date(now));
|
||||
map2.put(orderByKey, new Date(now - 1));
|
||||
Assert.assertEquals(!desc, comparator.compare(map1, map2) > 0);
|
||||
|
||||
map2.put(orderByKey, new Date(now));
|
||||
Assert.assertEquals(true, comparator.compare(map1, map2) == 0);
|
||||
|
||||
map2.put(orderByKey, new Date(now + 1));
|
||||
Assert.assertEquals(!desc, comparator.compare(map1, map2) < 0);
|
||||
|
||||
map2.put(orderByKey, null);
|
||||
Assert.assertEquals(!desc, comparator.compare(map1, map2) > 0);
|
||||
|
||||
map1.put(orderByKey, null);
|
||||
map2.put(orderByKey, new Date(now));
|
||||
Assert.assertEquals(!desc, comparator.compare(map1, map2) < 0);
|
||||
|
||||
map1.put(orderByKey, null);
|
||||
map2.put(orderByKey, null);
|
||||
Assert.assertEquals(true, comparator.compare(map1, map2) == 0);
|
||||
|
||||
}
|
||||
|
||||
private void test_comparator_string_0(boolean desc) throws Exception {
|
||||
MapComparator<String, String> comparator = new MapComparator<String, String>(orderByKey, desc);
|
||||
|
||||
Map<String, String> map1 = new HashMap<String, String>();
|
||||
Map<String, String> map2 = new HashMap<String, String>();
|
||||
|
||||
map1.put(orderByKey, "opq");
|
||||
map2.put(orderByKey, "xyz");
|
||||
Assert.assertEquals(desc, comparator.compare(map1, map2) > 0);
|
||||
|
||||
map2.put(orderByKey, "opq");
|
||||
Assert.assertEquals(true, comparator.compare(map1, map2) == 0);
|
||||
|
||||
map2.put(orderByKey, "abc");
|
||||
Assert.assertEquals(desc, comparator.compare(map1, map2) < 0);
|
||||
|
||||
map2.put(orderByKey, null);
|
||||
Assert.assertEquals(!desc, comparator.compare(map1, map2) > 0);
|
||||
|
||||
map1.put(orderByKey, null);
|
||||
map2.put(orderByKey, "opq");
|
||||
Assert.assertEquals(!desc, comparator.compare(map1, map2) < 0);
|
||||
|
||||
map1.put(orderByKey, null);
|
||||
map2.put(orderByKey, null);
|
||||
Assert.assertEquals(true, comparator.compare(map1, map2) == 0);
|
||||
}
|
||||
|
||||
private void test_comparator_number_0(boolean desc) throws Exception {
|
||||
MapComparator<String, Double> comparator = new MapComparator<String, Double>(orderByKey, desc);
|
||||
double baseNumber = 100.123;
|
||||
|
||||
Map<String, Double> map1 = new HashMap<String, Double>();
|
||||
Map<String, Double> map2 = new HashMap<String, Double>();
|
||||
|
||||
map1.put(orderByKey, baseNumber);
|
||||
map2.put(orderByKey, baseNumber - 1);
|
||||
Assert.assertEquals(!desc, comparator.compare(map1, map2) > 0);
|
||||
|
||||
map2.put(orderByKey, baseNumber);
|
||||
Assert.assertEquals(true, comparator.compare(map1, map2) == 0);
|
||||
|
||||
map2.put(orderByKey, baseNumber + 1);
|
||||
Assert.assertEquals(!desc, comparator.compare(map1, map2) < 0);
|
||||
|
||||
map2.put(orderByKey, null);
|
||||
Assert.assertEquals(!desc, comparator.compare(map1, map2) > 0);
|
||||
|
||||
map1.put(orderByKey, null);
|
||||
map2.put(orderByKey, baseNumber);
|
||||
Assert.assertEquals(!desc, comparator.compare(map1, map2) < 0);
|
||||
|
||||
map1.put(orderByKey, null);
|
||||
map2.put(orderByKey, null);
|
||||
Assert.assertEquals(true, comparator.compare(map1, map2) == 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user