diff --git a/README.md b/README.md index 63f4ea02f..256777f03 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ SCOUTER can help you. ## Documents - [Document Home](./scouter.document/index.md) - [Quick Start Guide (Quick Installation and Demo)](./scouter.document/main/Quick-Start.md) + - [Live Demo(Try to use scouter by connecting on live demo system)](./scouter.document/main/Live-Demo.md) - [Client Screen Help](./scouter.document/client/How-To-Use-Client.md) ## Download @@ -67,12 +68,16 @@ Scouter has three modules: - **SWT & GEF4** : Charts and Diagrams
+## Facebook + - [Scouter APM : Facebook Scouter user group](https://www.facebook.com/groups/scouterapm/) + +## How to contribute + - TBD + + ## Q&A - [Google Groups](https://groups.google.com/forum/#!forum/scouter-project) -## Facebook - - [Facebook Scouter user group](https://www.facebook.com/groups/1525329794448529/) - ## License Licensed under the Apache License, Version 2.0
diff --git a/README_kr.md b/README_kr.md index 543d81033..22733723e 100644 --- a/README_kr.md +++ b/README_kr.md @@ -30,6 +30,7 @@ APM은 Application performance montoring 또는 application performance manageme ## Documents - [Document Home](./scouter.document/index_kr.md) - [Quick Start(Scouter Demo 설치)](./scouter.document/main/Quick-Start_kr.md) + - [Live Demo(제공되는 Demo 시스템 바로 접속해 보기)](./scouter.document/main/Live-Demo_kr.md) - [Client 화면 설명](./scouter.document/client/How-To-Use-Client_kr.md) ## Download @@ -62,12 +63,15 @@ APM은 Application performance montoring 또는 application performance manageme - **SWT & GEF4** : Charts and Diagrams
+## Facebook + - [Scouter APM 사용자 모임 - Facebook 그룹](https://www.facebook.com/groups/scouterapm/) + +## Scouter에 기여하기 + - TBD + ## Q&A - [Google Groups](https://groups.google.com/forum/#!forum/scouter-project) -## Facebook - - [Facebook Scouter user group](https://www.facebook.com/groups/1525329794448529/) - ## License Licensed under the Apache License, Version 2.0
diff --git a/scouter.agent.host/src/scouter/agent/counter/meter/MeterResource.java b/scouter.agent.host/src/scouter/agent/counter/meter/MeterResource.java new file mode 100644 index 000000000..09b9c5edb --- /dev/null +++ b/scouter.agent.host/src/scouter/agent/counter/meter/MeterResource.java @@ -0,0 +1,70 @@ +/* + * Copyright 2015 the original author or authors. + * @https://github.com/scouter-project/scouter + * + * 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 scouter.agent.counter.meter; + +import scouter.lang.ref.DOUBLE; +import scouter.lang.ref.INT; +import scouter.util.MeteringUtil; +import scouter.util.MeteringUtil.Handler; + +public class MeterResource { + + static class Bucket { + double value; + int count; + } + private MeteringUtil meter = new MeteringUtil() { + protected Bucket create() { + return new Bucket(); + }; + + protected void clear(Bucket o) { + o.value=0; + o.count = 0; + } + }; + + public synchronized void add(double value) { + Bucket b = meter.getCurrentBucket(); + b.value += value; + b.count++; + } + + public double getAvg(int period) { + final INT count = new INT(); + final DOUBLE sum = new DOUBLE(); + meter.search(period, new Handler() { + public void process(Bucket u) { + sum.value += u.value; + count.value += u.count; + } + }); + return count.value == 0 ? 0 : sum.value / count.value; + } + + public double getSum(int period) { + final DOUBLE sum = new DOUBLE(); + meter.search(period, new Handler() { + public void process(Bucket u) { + sum.value += u.value; + } + }); + return sum.value; + } + +} \ No newline at end of file diff --git a/scouter.agent.host/src/scouter/agent/counter/task/HostPerf.java b/scouter.agent.host/src/scouter/agent/counter/task/HostPerf.java index c022b151c..da17b6a0a 100644 --- a/scouter.agent.host/src/scouter/agent/counter/task/HostPerf.java +++ b/scouter.agent.host/src/scouter/agent/counter/task/HostPerf.java @@ -16,6 +16,7 @@ import scouter.agent.Logger; import scouter.agent.counter.CounterBasket; import scouter.agent.counter.anotation.Counter; +import scouter.agent.counter.meter.MeterResource; import scouter.agent.netio.data.DataProxy; import scouter.lang.AlertLevel; import scouter.lang.TimeTypeEnum; @@ -31,7 +32,11 @@ public class HostPerf { static int SLEEP_TIME = 2000; static Sigar sigarImpl = new Sigar(); static SigarProxy sigar = SigarProxyCache.newInstance(sigarImpl, SLEEP_TIME); - + + MeterResource cpuMeter = new MeterResource(); + MeterResource sysCpuMeter = new MeterResource(); + MeterResource userCpuMeter = new MeterResource(); + @Counter public void process(CounterBasket pw) { try { @@ -48,10 +53,18 @@ void domain(CounterBasket pw) throws SigarException { CpuPerc cpuPerc = sigar.getCpuPerc(); float cpu = (float) ((1.0D - cpuPerc.getIdle()) * 100); - alertCpu(cpu); + cpuMeter.add(cpu); float sysCpu = (float) cpuPerc.getSys() * 100; + sysCpuMeter.add(sysCpu); float userCpu = (float) cpuPerc.getUser() * 100; + userCpuMeter.add(userCpu); + + cpu = (float) cpuMeter.getAvg(10); + sysCpu = (float) sysCpuMeter.getAvg(10); + userCpu = (float) userCpuMeter.getAvg(10); + alertCpu(cpu); + Mem m = sigar.getMem(); alertMem(m); diff --git a/scouter.agent.java/src/scouter/AnyTrace.java b/scouter.agent.java/src/scouter/AnyTrace.java index 2555ec137..43ba332c7 100644 --- a/scouter.agent.java/src/scouter/AnyTrace.java +++ b/scouter.agent.java/src/scouter/AnyTrace.java @@ -18,13 +18,11 @@ package scouter; import scouter.agent.netio.data.DataProxy; -import scouter.agent.trace.AlertProxy; import scouter.agent.trace.TraceApiCall; import scouter.agent.trace.TraceContext; import scouter.agent.trace.TraceContextManager; import scouter.agent.trace.TraceMain; import scouter.lang.pack.XLogTypes; -import scouter.util.HashUtil; import scouter.util.KeyGen; public class AnyTrace { @@ -42,7 +40,7 @@ public static void setServiceName(String name) { } public static void serviceError(String emsg) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null && ctx.error != 0) { // already started ctx.error = DataProxy.sendError(emsg); } @@ -70,7 +68,7 @@ public static Object startApicall(String name, long apiTxid) { public static void setApicallName(String name) { try { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { if (ctx.apicall_name != null) { // already started subcall only ctx.apicall_name = name; @@ -86,7 +84,7 @@ public static void endApicall(Object stat, Throwable thr) { public static void desc(String desc) { try { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { ctx.desc = desc; } @@ -96,7 +94,7 @@ public static void desc(String desc) { public static void login(String login) { try { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { ctx.login = login; } diff --git a/scouter.agent.java/src/scouter/agent/AgentTransformer.java b/scouter.agent.java/src/scouter/agent/AgentTransformer.java index 19cdf3a8a..90fa42827 100644 --- a/scouter.agent.java/src/scouter/agent/AgentTransformer.java +++ b/scouter.agent.java/src/scouter/agent/AgentTransformer.java @@ -109,8 +109,10 @@ public byte[] transform(ClassLoader loader, String className, Class classBeingRe AsyncRunner.getInstance().add(loader, className, classfileBuffer); return null; } - if (loader == null) { - return null; + if (loader == null ) { + if(conf._hook_boot_prefix==null || conf._hook_boot_prefix.length()==0 || false == className.startsWith(conf._hook_boot_prefix)){ + return null; + } } } if (className.startsWith("scouter/")) { diff --git a/scouter.agent.java/src/scouter/agent/Configure.java b/scouter.agent.java/src/scouter/agent/Configure.java index c3d737185..2f82473e9 100644 --- a/scouter.agent.java/src/scouter/agent/Configure.java +++ b/scouter.agent.java/src/scouter/agent/Configure.java @@ -31,6 +31,7 @@ public class Configure extends Thread { public static boolean JDBC_REDEFINED = false; private static Configure instance = null; + public final static synchronized Configure getInstance() { if (instance == null) { instance = new Configure(); @@ -182,6 +183,7 @@ public final static synchronized Configure getInstance() { public boolean _hook_usertx_enabled = true; public String _hook_direct_patch_classes = ""; public boolean _hook_spring_rest_enabled = false; + public String _hook_boot_prefix=null; //Control public boolean control_reject_service_enabled = false; @@ -443,6 +445,7 @@ private void apply() { this.trace_db2_enabled = getBoolean("trace_db2_enabled", true); this._hook_usertx_enabled = getBoolean("_hook_usertx_enabled", true); this._hook_direct_patch_classes = getValue("_hook_direct_patch_classes", ""); + this._hook_boot_prefix = getValue("_hook_boot_prefix"); this.counter_recentuser_valid_ms = getLong("counter_recentuser_valid_ms", DateUtil.MILLIS_PER_FIVE_MINUTE); this.counter_object_registry_path = getValue("counter_object_registry_path", "/tmp/scouter"); this.sfa_dump_enabled = getBoolean("sfa_dump_enabled", false); diff --git a/scouter.agent.java/src/scouter/agent/asm/JDBCPreparedStatementASM.java b/scouter.agent.java/src/scouter/agent/asm/JDBCPreparedStatementASM.java index d8db9dad8..1b52db491 100644 --- a/scouter.agent.java/src/scouter/agent/asm/JDBCPreparedStatementASM.java +++ b/scouter.agent.java/src/scouter/agent/asm/JDBCPreparedStatementASM.java @@ -38,6 +38,7 @@ public class JDBCPreparedStatementASM implements IASM, Opcodes { public final HashSet target = HookingSet.getHookingClassSet(Configure.getInstance().hook_jdbc_pstmt_classes); public final HashSet noField = new HashSet(); public JDBCPreparedStatementASM() { + target.add("org.mariadb.jdbc.MariaDbClientPreparedStatement"); target.add("org/mariadb/jdbc/MySQLPreparedStatement"); target.add("oracle/jdbc/driver/OraclePreparedStatement"); target.add("org/postgresql/jdbc2/AbstractJdbc2Statement"); @@ -53,6 +54,7 @@ public JDBCPreparedStatementASM() { target.add("cubrid/jdbc/driver/CUBRIDPreparedStatement"); // @skyworker - MySQL ServerPreparedStatement는 특별히 필드를 추가하지 않음 + noField.add("org.mariadb.jdbc.MariaDbClientPreparedStatement"); noField.add("com/mysql/jdbc/ServerPreparedStatement"); noField.add("jdbc/FakePreparedStatement2"); } diff --git a/scouter.agent.java/src/scouter/agent/asm/JDBCStatementASM.java b/scouter.agent.java/src/scouter/agent/asm/JDBCStatementASM.java index 083b34eb6..07bee86cf 100644 --- a/scouter.agent.java/src/scouter/agent/asm/JDBCStatementASM.java +++ b/scouter.agent.java/src/scouter/agent/asm/JDBCStatementASM.java @@ -36,7 +36,7 @@ public class JDBCStatementASM implements IASM, Opcodes { public final HashSet target = HookingSet.getHookingClassSet(Configure.getInstance().hook_jdbc_stmt_classes); public JDBCStatementASM() { - + target.add("org.mariadb.jdbc.MariaDbStatement"); target.add("org/mariadb/jdbc/MySQLStatement"); target.add("oracle/jdbc/driver/OracleStatement"); target.add("com/mysql/jdbc/StatementImpl"); diff --git a/scouter.agent.java/src/scouter/agent/asm/util/HookingSet.java b/scouter.agent.java/src/scouter/agent/asm/util/HookingSet.java index 6d546b689..8c3a1fa6f 100644 --- a/scouter.agent.java/src/scouter/agent/asm/util/HookingSet.java +++ b/scouter.agent.java/src/scouter/agent/asm/util/HookingSet.java @@ -165,7 +165,7 @@ public static HashSet getHookingClassSet(String arg) { if(c ==null) return classSet; for (int i = 0; i < c.length; i++) { - classSet.add(c[i]); + classSet.add(c[i].replace('.', '/').trim()); } return classSet; } diff --git a/scouter.agent.java/src/scouter/agent/netio/request/handle/AgentThread.java b/scouter.agent.java/src/scouter/agent/netio/request/handle/AgentThread.java index c79554fb5..d6f41b3d0 100644 --- a/scouter.agent.java/src/scouter/agent/netio/request/handle/AgentThread.java +++ b/scouter.agent.java/src/scouter/agent/netio/request/handle/AgentThread.java @@ -131,6 +131,8 @@ public Pack activeThreadList(Pack param) { ListValue ip = rPack.newList("ip"); ListValue sql = rPack.newList("sql"); ListValue subcall = rPack.newList("subcall"); + ListValue login = rPack.newList("login"); + ListValue desc = rPack.newList("desc"); Enumeration en = TraceContextManager.getContextEnumeration(); while (en.hasMoreElements()) { TraceContext ctx = en.nextElement(); @@ -154,6 +156,8 @@ public Pack activeThreadList(Pack param) { Logger.println("A128", th); cpu.add(0L); } + login.add(ctx.login); + desc.add(ctx.desc); } rPack.put("complete", new BooleanValue(true)); return rPack; diff --git a/scouter.agent.java/src/scouter/agent/plugin/WrContext.java b/scouter.agent.java/src/scouter/agent/plugin/WrContext.java index 99364ad1d..e23d4b83e 100644 --- a/scouter.agent.java/src/scouter/agent/plugin/WrContext.java +++ b/scouter.agent.java/src/scouter/agent/plugin/WrContext.java @@ -101,7 +101,7 @@ public void profile(String msg) { /** * add xlog profile - * profile diplay like --> msg #value elapsed + * profile display like --> msg #value elapsed * @param msg message * @param value any value to display on a profile. * @param elapsed any value to display on a profile. diff --git a/scouter.agent.java/src/scouter/agent/trace/TraceApiCall.java b/scouter.agent.java/src/scouter/agent/trace/TraceApiCall.java index b6bafa527..177241c3f 100644 --- a/scouter.agent.java/src/scouter/agent/trace/TraceApiCall.java +++ b/scouter.agent.java/src/scouter/agent/trace/TraceApiCall.java @@ -53,14 +53,14 @@ public Stat(TraceContext ctx) { } } public static void apiInfo(String className, String methodName, String methodDesc, Object _this, Object[] arg) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null && arg.length >= 2) { ctx.apicall_target = arg[0] + ":" + arg[1]; } } public static Object startApicall(String className, String methodName, String methodDesc, Object _this, Object[] arg) { try { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) { return null; } @@ -85,7 +85,7 @@ public static Object startApicall(String className, String methodName, String me return null; } public static Object startApicall(String name, long apiTxid) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) return null; if (ctx.apicall_name != null) { @@ -153,7 +153,7 @@ public static void endApicall(Object stat, Object returnValue, Throwable thr) { public static Object startSocket(Socket socket, SocketAddress addr, int timeout) { if (!(addr instanceof InetSocketAddress)) return null; - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) { if (Configure.getInstance().trace_background_socket_enabled) { InetSocketAddress inet = (InetSocketAddress) addr; @@ -211,7 +211,7 @@ public static void endSocket(Object stat, Throwable thr) { } } public static void open(File file) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { MessageStep m = new MessageStep(); m.start_time = (int) (System.currentTimeMillis() - ctx.startTime); diff --git a/scouter.agent.java/src/scouter/agent/trace/TraceContextManager.java b/scouter.agent.java/src/scouter/agent/trace/TraceContextManager.java index d063da231..f9bc6698d 100644 --- a/scouter.agent.java/src/scouter/agent/trace/TraceContextManager.java +++ b/scouter.agent.java/src/scouter/agent/trace/TraceContextManager.java @@ -17,12 +17,12 @@ package scouter.agent.trace; -import java.util.Enumeration; - import scouter.agent.Configure; import scouter.util.LongEnumer; import scouter.util.LongKeyMap; +import java.util.Enumeration; + public class TraceContextManager { private static LongKeyMap entry = new LongKeyMap(); @@ -66,7 +66,7 @@ public static TraceContext getContext(long key) { return entry.get(key); } - public static TraceContext getLocalContext() { + public static TraceContext getContext() { return local.get(); } diff --git a/scouter.agent.java/src/scouter/agent/trace/TraceMain.java b/scouter.agent.java/src/scouter/agent/trace/TraceMain.java index 4eac04cb9..523b37318 100644 --- a/scouter.agent.java/src/scouter/agent/trace/TraceMain.java +++ b/scouter.agent.java/src/scouter/agent/trace/TraceMain.java @@ -64,7 +64,7 @@ public Stat(TraceContext ctx) { public static Object startHttpService(Object req, Object res) { try { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { return null; } @@ -77,7 +77,7 @@ public static Object startHttpService(Object req, Object res) { public static Object startHttpFilter(Object req, Object res) { try { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { return null; } @@ -206,7 +206,7 @@ public static void endHttpService(Object stat, Throwable thr) { if (thr == null) return; try { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null && ctx.error == 0) { Configure conf = Configure.getInstance(); String emsg = thr.toString(); @@ -350,7 +350,7 @@ public static boolean isStaticContents(String serviceName) { public static Object startService(String name, String className, String methodName, String methodDesc, Object _this, Object[] arg, byte xType) { try { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { return null; } @@ -484,7 +484,7 @@ private static int errorCheck(TraceContext ctx, Throwable thr) { } public static void capArgs(String className, String methodName, String methodDesc, Object this1, Object[] arg) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) return; // MessageStep step = new MessageStep(); @@ -499,7 +499,7 @@ public static void capArgs(String className, String methodName, String methodDes } public static void jspServlet(Object[] arg) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null || arg.length < 3) return; HashedMessageStep step = new HashedMessageStep(); @@ -556,7 +556,7 @@ private static String toStringTHIS(String type, String className, String methodD } public static void capThis(String className, String methodDesc, Object this0) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) return; // MessageStep step = new MessageStep(); @@ -571,7 +571,7 @@ public static void capThis(String className, String methodDesc, Object this0) { } public static void capReturn(String className, String methodName, String methodDesc, Object this1, Object rtn) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) return; PluginCaptureTrace.capReturn(ctx, new HookReturn(className, methodName, methodDesc, this1, rtn)); @@ -580,7 +580,7 @@ public static void capReturn(String className, String methodName, String methodD public static Object startMethod(int hash, String classMethod) { if (conf.profile_method_enabled == false) return null; - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) { if (conf._trace_auto_service_enabled) { Object localContext = startService(classMethod, null, null, null, null, null, XLogTypes.APP_SERVICE); @@ -630,7 +630,7 @@ public static void endMethod(Object localContext, Throwable thr) { } public static void setServiceName(String name) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null || name == null) return; ctx.serviceName = name; @@ -638,7 +638,7 @@ public static void setServiceName(String name) { } public static void setStatus(int httpStatus) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) return; ctx.status = httpStatus; @@ -669,7 +669,7 @@ public static XLogPack txperf(long endtime, long txid, int service_hash, String } public static void addMessage(String msg) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) return; MessageStep p = new MessageStep(); diff --git a/scouter.agent.java/src/scouter/agent/trace/TraceSQL.java b/scouter.agent.java/src/scouter/agent/trace/TraceSQL.java index 99e3a64a1..58e238e27 100644 --- a/scouter.agent.java/src/scouter/agent/trace/TraceSQL.java +++ b/scouter.agent.java/src/scouter/agent/trace/TraceSQL.java @@ -61,42 +61,42 @@ public class TraceSQL { static DBURL unknown = new DBURL(0, null); public static void set(int idx, boolean p) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { ctx.sql.put(idx, Boolean.toString(p)); } } public static void set(int idx, int p) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { ctx.sql.put(idx, Integer.toString(p)); } } public static void set(int idx, float p) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { ctx.sql.put(idx, Float.toString(p)); } } public static void set(int idx, long p) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { ctx.sql.put(idx, Long.toString(p)); } } public static void set(int idx, double p) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { ctx.sql.put(idx, Double.toString(p)); } } public static void set(int idx, String p) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { if (p == null) { ctx.sql.put(idx, "null"); @@ -108,7 +108,7 @@ public static void set(int idx, String p) { } public static void set(int idx, Object p) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { if (p == null) { ctx.sql.put(idx, "null"); @@ -120,14 +120,14 @@ public static void set(int idx, Object p) { } public static void clear(Object o) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { ctx.sql.clear(); } } public static Object start(Object o) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) { return null; } @@ -151,7 +151,7 @@ public static Object start(Object o) { } public static Object start(Object o, String sql, byte methodType) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) { if (conf._log_background_sql) { Logger.println("background: " + sql); @@ -290,14 +290,14 @@ public static void end(Object stat, Throwable thr, int updatedCount) { tCtx.profile.pop(step); } public static void prepare(Object o, String sql) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { ctx.sql.clear(); ctx.sql.setSql(sql); } } public static boolean rsnext(boolean b) { - TraceContext c = TraceContextManager.getLocalContext(); + TraceContext c = TraceContextManager.getContext(); if (c != null) { if (b) { if (c.rs_start == 0) { @@ -334,7 +334,7 @@ private static void fetch(TraceContext c) { } public static void rsclose(Object rs) { - TraceContext c = TraceContextManager.getLocalContext(); + TraceContext c = TraceContextManager.getContext(); if (c != null) { if (c.rs_start != 0) { fetch(c); @@ -402,7 +402,7 @@ public static void clear(Object o, SqlParameter args) { } public static Object start(Object o, SqlParameter args, byte methodType) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) { if (conf._log_background_sql && args != null) { Logger.println("background: " + args.getSql()); @@ -481,14 +481,14 @@ public static Connection driverConnect(Connection conn, String url) { public static void driverConnect(String url, Throwable thr) { AlertProxy.sendAlert(AlertLevel.ERROR, "CONNECT", url + " " + thr); - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { ServiceSummary.getInstance().process(connectionOpenFailException, 0, ctx.serviceHash, ctx.txid, 0, 0); } } public static void userTxOpen() { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) return; ctx.userTransaction++; @@ -498,7 +498,7 @@ public static void userTxOpen() { } public static void userTxClose(String method) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) return; if (ctx.userTransaction > 0) { @@ -510,7 +510,7 @@ public static void userTxClose(String method) { } public static Object dbcOpenStart(int hash, String msg, Object pool) { - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) return null; if (conf.profile_connection_open_enabled == false) @@ -647,7 +647,7 @@ public static void dbcOpenEnd(Object stat, Throwable thr) { public static void sqlMap(String methodName, String sqlname) { if (Configure.getInstance().profile_sqlmap_name_enabled == false) return; - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) return; HashedMessageStep p = new HashedMessageStep(); @@ -688,7 +688,7 @@ public static int getIntArraySum(int[] arr) { */ public static int incUpdateCount(int cnt) { Logger.trace("stmt.getUpdateCount()=" + cnt); - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) { return cnt; } diff --git a/scouter.agent.java/src/scouter/jdbc/DetectConnection.java b/scouter.agent.java/src/scouter/jdbc/DetectConnection.java index d3c39edf3..7a379a0c9 100644 --- a/scouter.agent.java/src/scouter/jdbc/DetectConnection.java +++ b/scouter.agent.java/src/scouter/jdbc/DetectConnection.java @@ -46,7 +46,7 @@ public DetectConnection(java.sql.Connection inner) { int serviceHash = 0; long txid = 0; - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx != null) { serviceHash = ctx.serviceHash; txid = ctx.txid; @@ -121,7 +121,7 @@ final public void close() throws java.sql.SQLException { this.inner.close(); long etime = System.currentTimeMillis(); - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) return; @@ -200,7 +200,7 @@ final public java.lang.String nativeSQL(java.lang.String a0) throws java.sql.SQL final public void setAutoCommit(boolean a0) throws java.sql.SQLException { this.inner.setAutoCommit(a0); - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) return; @@ -223,7 +223,7 @@ final public void commit() throws java.sql.SQLException { this.inner.commit(); long etime = System.currentTimeMillis(); - TraceContext ctx = TraceContextManager.getLocalContext(); + TraceContext ctx = TraceContextManager.getContext(); if (ctx == null) return; diff --git a/scouter.client/plugin.xml b/scouter.client/plugin.xml index 526a6e107..73818462c 100644 --- a/scouter.client/plugin.xml +++ b/scouter.client/plugin.xml @@ -455,14 +455,6 @@ name="Data File Management" restorable="false"> - - - - - - + + + + + + + + + + + + diff --git a/scouter.client/src/scouter/client/actions/OpenActiveServiceListAction.java b/scouter.client/src/scouter/client/actions/OpenActiveServiceListAction.java index 52997c4d4..1a0c0c312 100644 --- a/scouter.client/src/scouter/client/actions/OpenActiveServiceListAction.java +++ b/scouter.client/src/scouter/client/actions/OpenActiveServiceListAction.java @@ -36,10 +36,10 @@ public class OpenActiveServiceListAction extends Action { private String objType; private int serverId; - public OpenActiveServiceListAction(IWorkbenchWindow window, String label, String objType, Image image, int serverId) { + public OpenActiveServiceListAction(IWorkbenchWindow window, String objType, Image image, int serverId) { this.window = window; this.serverId = serverId; - setText(label); + setText("Active Service List"); setId(ID); setImageDescriptor(ImageUtil.getImageDescriptor(image)); this.objType = objType; diff --git a/scouter.client/src/scouter/client/actions/OpenActiveSpeedAction.java b/scouter.client/src/scouter/client/actions/OpenActiveSpeedAction.java index dc8ef540d..639aabc77 100644 --- a/scouter.client/src/scouter/client/actions/OpenActiveSpeedAction.java +++ b/scouter.client/src/scouter/client/actions/OpenActiveSpeedAction.java @@ -36,11 +36,11 @@ public class OpenActiveSpeedAction extends Action { private String objType; private int serverId; - public OpenActiveSpeedAction(IWorkbenchWindow window, String label, String objType, Image image, int serverId) { + public OpenActiveSpeedAction(IWorkbenchWindow window, String objType, Image image, int serverId) { this.window = window; this.objType = objType; this.serverId = serverId; - setText(label); + setText("Active Speed"); setId(ID); setImageDescriptor(ImageUtil.getImageDescriptor(image)); } diff --git a/scouter.client/src/scouter/client/actions/OpenServiceGroupElapsedAction.java b/scouter.client/src/scouter/client/actions/OpenServiceGroupElapsedAction.java new file mode 100644 index 000000000..867398ad8 --- /dev/null +++ b/scouter.client/src/scouter/client/actions/OpenServiceGroupElapsedAction.java @@ -0,0 +1,54 @@ +/* + * Copyright 2015 the original author or authors. + * @https://github.com/scouter-project/scouter + * + * 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 scouter.client.actions; + +import org.eclipse.jface.action.Action; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; + +import scouter.client.Images; +import scouter.client.views.ServiceGroupElapsedView; +import scouter.lang.counters.CounterConstants; + +public class OpenServiceGroupElapsedAction extends Action { + public final static String ID = OpenServiceGroupElapsedAction.class.getName(); + + private final IWorkbenchWindow window; + int serverId; + String objType; + + public OpenServiceGroupElapsedAction(IWorkbenchWindow window, int serverId, String objType) { + this.window = window; + this.serverId = serverId; + this.objType = objType; + setText("Elapsed"); + setId(ID); + setImageDescriptor(Images.getCounterImageDescriptor(objType, CounterConstants.WAS_ELAPSED_TIME, serverId)); + } + + public void run() { + if (window != null) { + try { + window.getActivePage().showView(ServiceGroupElapsedView.ID, serverId + "&" + objType, IWorkbenchPage.VIEW_ACTIVATE); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + } +} diff --git a/scouter.client/src/scouter/client/actions/OpenServiceGroupElapsedGroupAction.java b/scouter.client/src/scouter/client/actions/OpenServiceGroupElapsedGroupAction.java new file mode 100644 index 000000000..97d242ec4 --- /dev/null +++ b/scouter.client/src/scouter/client/actions/OpenServiceGroupElapsedGroupAction.java @@ -0,0 +1,49 @@ +/* + * Copyright 2015 the original author or authors. + * @https://github.com/scouter-project/scouter + * + * 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 scouter.client.actions; + +import org.eclipse.jface.action.Action; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; + +import scouter.client.group.view.ServiceGroupElapsedGroupView; + +public class OpenServiceGroupElapsedGroupAction extends Action { + public final static String ID = OpenServiceGroupElapsedGroupAction.class.getName(); + + private final IWorkbenchWindow window; + String grpName; + + public OpenServiceGroupElapsedGroupAction(IWorkbenchWindow window, String grpName) { + this.window = window; + this.grpName = grpName; + setText("Elapsed"); + setId(ID); + } + + public void run() { + if (window != null) { + try { + window.getActivePage().showView(ServiceGroupElapsedGroupView.ID, grpName, IWorkbenchPage.VIEW_ACTIVATE); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + } +} diff --git a/scouter.client/src/scouter/client/actions/OpenServiceGroupAction.java b/scouter.client/src/scouter/client/actions/OpenServiceGroupTPSAction.java similarity index 68% rename from scouter.client/src/scouter/client/actions/OpenServiceGroupAction.java rename to scouter.client/src/scouter/client/actions/OpenServiceGroupTPSAction.java index 274a154b8..43a2c8628 100644 --- a/scouter.client/src/scouter/client/actions/OpenServiceGroupAction.java +++ b/scouter.client/src/scouter/client/actions/OpenServiceGroupTPSAction.java @@ -1,54 +1,54 @@ -/* +/* * Copyright 2015 the original author or authors. - * @https://github.com/scouter-project/scouter - * - * 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 scouter.client.actions; - -import org.eclipse.jface.action.Action; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; - -import scouter.client.Images; -import scouter.client.util.ImageUtil; -import scouter.client.views.ServiceGroupView; - -public class OpenServiceGroupAction extends Action { - public final static String ID = OpenServiceGroupAction.class.getName(); - - private final IWorkbenchWindow window; - int serverId; - String objType; - - public OpenServiceGroupAction(IWorkbenchWindow window, int serverId, String objType) { - this.window = window; - this.serverId = serverId; - this.objType = objType; - setText("Serivce Group"); - setId(ID); - setImageDescriptor(ImageUtil.getImageDescriptor(Images.sum)); - } - - public void run() { - if (window != null) { - try { - window.getActivePage().showView(ServiceGroupView.ID, serverId + "&" + objType, IWorkbenchPage.VIEW_ACTIVATE); - } catch (PartInitException e) { - e.printStackTrace(); - } - } - } -} + * @https://github.com/scouter-project/scouter + * + * 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 scouter.client.actions; + +import org.eclipse.jface.action.Action; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; + +import scouter.client.Images; +import scouter.client.views.ServiceGroupTPSView; +import scouter.lang.counters.CounterConstants; + +public class OpenServiceGroupTPSAction extends Action { + public final static String ID = OpenServiceGroupTPSAction.class.getName(); + + private final IWorkbenchWindow window; + int serverId; + String objType; + + public OpenServiceGroupTPSAction(IWorkbenchWindow window, int serverId, String objType) { + this.window = window; + this.serverId = serverId; + this.objType = objType; + setText("Throughput"); + setId(ID); + setImageDescriptor(Images.getCounterImageDescriptor(objType, CounterConstants.WAS_TPS, serverId)); + } + + public void run() { + if (window != null) { + try { + window.getActivePage().showView(ServiceGroupTPSView.ID, serverId + "&" + objType, IWorkbenchPage.VIEW_ACTIVATE); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + } +} diff --git a/scouter.client/src/scouter/client/actions/OpenServiceGroupGroupAction.java b/scouter.client/src/scouter/client/actions/OpenServiceGroupTPSGroupAction.java similarity index 69% rename from scouter.client/src/scouter/client/actions/OpenServiceGroupGroupAction.java rename to scouter.client/src/scouter/client/actions/OpenServiceGroupTPSGroupAction.java index 2b0317aea..ebde25a69 100644 --- a/scouter.client/src/scouter/client/actions/OpenServiceGroupGroupAction.java +++ b/scouter.client/src/scouter/client/actions/OpenServiceGroupTPSGroupAction.java @@ -1,52 +1,51 @@ -/* +/* * Copyright 2015 the original author or authors. - * @https://github.com/scouter-project/scouter - * - * 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 scouter.client.actions; - -import org.eclipse.jface.action.Action; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.PartInitException; - -import scouter.client.Images; -import scouter.client.group.view.ServiceGroupGroupView; -import scouter.client.util.ImageUtil; - -public class OpenServiceGroupGroupAction extends Action { - public final static String ID = OpenServiceGroupGroupAction.class.getName(); - - private final IWorkbenchWindow window; - String grpName; - - public OpenServiceGroupGroupAction(IWorkbenchWindow window, String grpName) { - this.window = window; - this.grpName = grpName; - setText("Service Group"); - setId(ID); - setImageDescriptor(ImageUtil.getImageDescriptor(Images.sum)); - } - - public void run() { - if (window != null) { - try { - window.getActivePage().showView(ServiceGroupGroupView.ID, grpName, IWorkbenchPage.VIEW_ACTIVATE); - } catch (PartInitException e) { - e.printStackTrace(); - } - } - } -} + * @https://github.com/scouter-project/scouter + * + * 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 scouter.client.actions; + +import org.eclipse.jface.action.Action; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; + +import scouter.client.Images; +import scouter.client.group.view.ServiceGroupTPSGroupView; +import scouter.client.util.ImageUtil; + +public class OpenServiceGroupTPSGroupAction extends Action { + public final static String ID = OpenServiceGroupTPSGroupAction.class.getName(); + + private final IWorkbenchWindow window; + String grpName; + + public OpenServiceGroupTPSGroupAction(IWorkbenchWindow window, String grpName) { + this.window = window; + this.grpName = grpName; + setText("Throughput"); + setId(ID); + } + + public void run() { + if (window != null) { + try { + window.getActivePage().showView(ServiceGroupTPSGroupView.ID, grpName, IWorkbenchPage.VIEW_ACTIVATE); + } catch (PartInitException e) { + e.printStackTrace(); + } + } + } +} diff --git a/scouter.client/src/scouter/client/counter/actions/OpenDailyServiceCountAction.java b/scouter.client/src/scouter/client/counter/actions/OpenDailyServiceCountAction.java index 0a7e31b92..4c75c15f4 100644 --- a/scouter.client/src/scouter/client/counter/actions/OpenDailyServiceCountAction.java +++ b/scouter.client/src/scouter/client/counter/actions/OpenDailyServiceCountAction.java @@ -38,17 +38,17 @@ public class OpenDailyServiceCountAction extends Action implements CalendarDialo private int serverId; private String date; - public OpenDailyServiceCountAction(IWorkbenchWindow window, String label, String objType, String counter, Image image, int serverId) { - this(window, label, objType, counter, image, serverId, null); + public OpenDailyServiceCountAction(IWorkbenchWindow window, String objType, String counter, Image image, int serverId) { + this(window, objType, counter, image, serverId, null); } - public OpenDailyServiceCountAction(IWorkbenchWindow window, String label, String objType, String counter, Image image, int serverId, String date) { + public OpenDailyServiceCountAction(IWorkbenchWindow window, String objType, String counter, Image image, int serverId, String date) { this.window = window; this.objType = objType; this.counter = counter; this.serverId = serverId; this.date = date; - setText(label); + setText("24H Service Count"); setId(ID); setImageDescriptor(ImageUtil.getImageDescriptor(image)); } diff --git a/scouter.client/src/scouter/client/counter/actions/OpenPTPairAllAction.java b/scouter.client/src/scouter/client/counter/actions/OpenPTPairAllAction.java new file mode 100644 index 000000000..80df9057f --- /dev/null +++ b/scouter.client/src/scouter/client/counter/actions/OpenPTPairAllAction.java @@ -0,0 +1,60 @@ +package scouter.client.counter.actions; + +import org.eclipse.jface.action.Action; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; + +import scouter.client.Images; +import scouter.client.counter.views.CounterPTAllPairChart; +import scouter.client.popup.CalendarDialog; +import scouter.client.popup.CalendarDialog.ILoadCalendarDialog; +import scouter.client.util.ConsoleProxy; +import scouter.client.util.ImageUtil; +import scouter.client.util.TimeUtil; +import scouter.util.DateUtil; + +public class OpenPTPairAllAction extends Action implements ILoadCalendarDialog { + + IWorkbenchWindow window; + int serverId; + String objType; + String counter; + + public OpenPTPairAllAction(IWorkbenchWindow window, String name, int serverId, String objType, String counter) { + this.window = window; + this.serverId = serverId; + this.objType = objType; + this.counter = counter; + setImageDescriptor(ImageUtil.getImageDescriptor(Images.calendar)); + setText(name); + } + + public void run() { + CalendarDialog dialog = new CalendarDialog(window.getShell().getDisplay(), this); + dialog.showWithTime(-1, -1, TimeUtil.getCurrentTime(serverId) - DateUtil.MILLIS_PER_FIVE_MINUTE); + } + + public void onPressedOk(long startTime, long endTime) { + if (window != null) { + try { + CounterPTAllPairChart chart = (CounterPTAllPairChart) window.getActivePage().showView( + CounterPTAllPairChart.ID, serverId + "&" + objType + "&" + counter , + IWorkbenchPage.VIEW_ACTIVATE); + if (chart != null) { + chart.setInput(startTime, endTime); + } + } catch (PartInitException e) { + ConsoleProxy.errorSafe("Error opening view:" + e.getMessage()); + } + } + } + + public void onPressedOk(String date) { + + } + + public void onPressedCancel() { + + } +} diff --git a/scouter.client/src/scouter/client/counter/actions/OpenRTPairAllAction.java b/scouter.client/src/scouter/client/counter/actions/OpenRTPairAllAction.java new file mode 100644 index 000000000..8fb9facee --- /dev/null +++ b/scouter.client/src/scouter/client/counter/actions/OpenRTPairAllAction.java @@ -0,0 +1,39 @@ +package scouter.client.counter.actions; + +import org.eclipse.jface.action.Action; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; + +import scouter.client.Images; +import scouter.client.counter.views.CounterRTAllPairChart; +import scouter.client.util.ConsoleProxy; + +public class OpenRTPairAllAction extends Action { + + IWorkbenchWindow window; + int serverId; + String objType; + String counter; + + public OpenRTPairAllAction(IWorkbenchWindow window, String name, int serverId, String objType, String counter) { + this.window = window; + this.serverId = serverId; + this.objType = objType; + this.counter = counter; + setImageDescriptor(Images.getCounterImageDescriptor(objType, counter, serverId)); + setText(name); + } + + public void run() { + if (window != null) { + try { + window.getActivePage().showView( + CounterRTAllPairChart.ID, serverId + "&" + objType + "&" + counter , + IWorkbenchPage.VIEW_ACTIVATE); + } catch (PartInitException e) { + ConsoleProxy.errorSafe("Error opening view:" + e.getMessage()); + } + } + } +} diff --git a/scouter.client/src/scouter/client/counter/views/CounterPTAllPairChart.java b/scouter.client/src/scouter/client/counter/views/CounterPTAllPairChart.java new file mode 100644 index 000000000..9daaa2618 --- /dev/null +++ b/scouter.client/src/scouter/client/counter/views/CounterPTAllPairChart.java @@ -0,0 +1,386 @@ +package scouter.client.counter.views; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.csstudio.swt.xygraph.dataprovider.CircularBufferDataProvider; +import org.csstudio.swt.xygraph.dataprovider.ISample; +import org.csstudio.swt.xygraph.dataprovider.Sample; +import org.csstudio.swt.xygraph.figures.Trace; +import org.csstudio.swt.xygraph.figures.Trace.PointStyle; +import org.csstudio.swt.xygraph.figures.Trace.TraceType; +import org.csstudio.swt.xygraph.figures.XYGraph; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.window.DefaultToolTip; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.ControlListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IViewSite; +import org.eclipse.ui.PartInitException; + +import scouter.client.counter.actions.OpenPTPairAllAction; +import scouter.client.listeners.RangeMouseListener; +import scouter.client.model.AgentColorManager; +import scouter.client.model.TextProxy; +import scouter.client.net.INetReader; +import scouter.client.net.TcpProxy; +import scouter.client.preferences.PManager; +import scouter.client.preferences.PreferenceConstants; +import scouter.client.server.Server; +import scouter.client.server.ServerManager; +import scouter.client.threads.ObjectSelectManager; +import scouter.client.threads.ObjectSelectManager.IObjectCheckListener; +import scouter.client.util.ChartUtil; +import scouter.client.util.ColorUtil; +import scouter.client.util.ConsoleProxy; +import scouter.client.util.CounterUtil; +import scouter.client.util.ExUtil; +import scouter.client.util.ScouterUtil; +import scouter.client.views.ScouterViewPart; +import scouter.io.DataInputX; +import scouter.lang.counters.CounterEngine; +import scouter.lang.pack.MapPack; +import scouter.lang.value.ListValue; +import scouter.lang.value.Value; +import scouter.lang.value.ValueEnum; +import scouter.net.RequestCmd; +import scouter.util.CastUtil; +import scouter.util.DateUtil; +import scouter.util.FormatUtil; +import scouter.util.StringUtil; + +public class CounterPTAllPairChart extends ScouterViewPart implements IObjectCheckListener { + + public final static String ID = CounterPTAllPairChart.class.getName(); + + private int serverId; + private String objType; + private String counter; + private long stime; + private long etime; + + protected XYGraph xyGraph; + protected Map dataMap = new HashMap(); + TracePair nearestTracePair; + protected FigureCanvas canvas; + + public void init(IViewSite site) throws PartInitException { + super.init(site); + String secId = site.getSecondaryId(); + String[] ids = StringUtil.split(secId, "&"); + this.serverId = CastUtil.cint(ids[0]); + this.objType = ids[1]; + this.counter = ids[2]; + } + + public void createPartControl(Composite parent) { + GridLayout layout = new GridLayout(1, true); + layout.marginHeight = 5; + layout.marginWidth = 5; + parent.setLayout(layout); + parent.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE)); + parent.setBackgroundMode(SWT.INHERIT_FORCE); + + canvas = new FigureCanvas(parent); + canvas.setLayoutData(new GridData(GridData.FILL_BOTH)); + canvas.setScrollBarVisibility(FigureCanvas.NEVER); + canvas.addControlListener(new ControlListener() { + boolean lock = false; + + public void controlResized(ControlEvent e) { + org.eclipse.swt.graphics.Rectangle r = canvas.getClientArea(); + if (!lock) { + lock = true; + if (ChartUtil.isShowDescriptionAllowSize(r.height)) { + CounterPTAllPairChart.this.setContentDescription(desc); + } else { + CounterPTAllPairChart.this.setContentDescription(""); + } + r = canvas.getClientArea(); + xyGraph.setSize(r.width, r.height); + lock = false; + } + } + + public void controlMoved(ControlEvent e) { + } + }); + + xyGraph = new XYGraph(); + xyGraph.setShowLegend(false); + xyGraph.setShowTitle(false); + canvas.setContents(xyGraph); + + xyGraph.primaryXAxis.setDateEnabled(true); + xyGraph.primaryXAxis.setShowMajorGrid(true); + + xyGraph.primaryYAxis.setAutoScale(true); + xyGraph.primaryYAxis.setShowMajorGrid(true); + + xyGraph.primaryXAxis.setTitle(""); + xyGraph.primaryYAxis.setTitle(""); + + xyGraph.primaryXAxis.setFormatPattern("HH:mm:ss"); + xyGraph.primaryYAxis.setFormatPattern("#,##0"); + + xyGraph.primaryYAxis.addMouseListener(new RangeMouseListener(getViewSite().getShell(), xyGraph.primaryYAxis)); + + final DefaultToolTip toolTip = new DefaultToolTip(canvas, DefaultToolTip.RECREATE, true); + toolTip.setFont(new Font(null, "Arial", 10, SWT.BOLD)); + toolTip.setBackgroundColor(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + + canvas.addMouseListener(new MouseListener() { + public void mouseUp(MouseEvent e) { + if (nearestTracePair != null) { + int width = PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH); + nearestTracePair.setLineWidth(width); + nearestTracePair = null; + } + toolTip.hide(); + } + public void mouseDown(MouseEvent e) { + double x = xyGraph.primaryXAxis.getPositionValue(e.x, false); + double y = xyGraph.primaryYAxis.getPositionValue(e.y, false); + if (x < 0 || y < 0) { + return; + } + double minDistance = 30.0d; + long time = 0; + double max = 0; + double value = 0; + Iterator keys = dataMap.keySet().iterator(); + while (keys.hasNext()) { + int objHash = keys.next(); + TracePair tp = dataMap.get(objHash); + Trace t1 = tp.t1; + ISample s1 = ScouterUtil.getNearestPoint(t1.getDataProvider(), x); + Trace t2 = tp.t2; + ISample s2 = ScouterUtil.getNearestPoint(t2.getDataProvider(), x); + if (s1 != null && s2 != null) { + int x1 = xyGraph.primaryXAxis.getValuePosition(s1.getXValue(), false); + int y1 = xyGraph.primaryYAxis.getValuePosition(s1.getYValue(), false); + int x2 = xyGraph.primaryXAxis.getValuePosition(s2.getXValue(), false); + int y2 = xyGraph.primaryYAxis.getValuePosition(s2.getYValue(), false); + double distance1 = ScouterUtil.getPointDistance(e.x, e.y, x1, y1); + double distance2 = ScouterUtil.getPointDistance(e.x, e.y, x2, y2); + double distance = distance1 > distance2 ? distance2 : distance1; + if (minDistance > distance) { + minDistance = distance; + nearestTracePair = tp; + time = (long) s1.getXValue(); + max = s1.getYValue(); + value = s2.getYValue(); + } + } + + } + if (nearestTracePair != null) { + int width = PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH); + nearestTracePair.setLineWidth(width + 2); + toolTip.setText(TextProxy.object.getText(nearestTracePair.objHash) + + "\nTime : " + DateUtil.format(time, "HH:mm:ss") + + "\nMax : " + FormatUtil.print(max, "#,###.##") + + "\nValue : " + FormatUtil.print(value, "#,###.##")); + toolTip.show(new Point(e.x, e.y)); + } + } + public void mouseDoubleClick(MouseEvent e) {} + }); + + IToolBarManager man = getViewSite().getActionBars().getToolBarManager(); + man.add(new OpenPTPairAllAction(getViewSite().getWorkbenchWindow(), "Load", serverId, objType, counter)); + + ObjectSelectManager.getInstance().addObjectCheckStateListener(this); + } + + public void setInput(long stime, long etime) { + this.stime = stime; + this.etime = etime; + try { + setViewTab(objType, counter, serverId); + Server server = ServerManager.getInstance().getServer(serverId); + CounterEngine ce = server.getCounterEngine(); + String counterName = ce.getCounterDisplayName(objType, counter); + desc = "ⓢ" + server.getName() + " | (Past All) " + counterName + "(" + ce.getCounterUnit(objType, counter) + ") " + + DateUtil.format(stime, "yyyyMMdd HH:mm:ss") + " ~ " + DateUtil.format(etime, "HH:mm:ss"); + this.xyGraph.primaryXAxis.setRange(stime, etime); + } catch (Exception e1) { + e1.printStackTrace(); + } + Set keySet = dataMap.keySet(); + for (Integer key : keySet) { + TracePair tp = dataMap.get(key); + xyGraph.removeTrace(tp.t1); + xyGraph.removeTrace(tp.t2); + } + dataMap.clear(); + load(); + } + + private void load() { + CounterEngine counterEngine = ServerManager.getInstance().getServer(serverId).getCounterEngine(); + new Job("Load " + counterEngine.getCounterDisplayName(objType, counter)) { + protected IStatus run(IProgressMonitor monitor) { + final List values = new ArrayList(); + TcpProxy tcp = TcpProxy.getTcpProxy(serverId); + try { + MapPack param = new MapPack(); + param.put("stime", stime); + param.put("etime", etime); + param.put("objType", objType); + param.put("counter", counter); + + tcp.process(RequestCmd.COUNTER_PAST_TIME_ALL, param, new INetReader() { + public void process(DataInputX in) throws IOException { + MapPack mpack = (MapPack) in.readPack(); + values.add(mpack); + }; + }); + } catch (Throwable t) { + ConsoleProxy.errorSafe(t.toString()); + } finally { + TcpProxy.putTcpProxy(tcp); + } + + ExUtil.exec(canvas, new Runnable() { + public void run() { + double max = 0; + for (MapPack mpack : values) { + int objHash = mpack.getInt("objHash"); + ListValue time = mpack.getList("time"); + ListValue value = mpack.getList("value"); + TracePair tp = getTracePair(objHash); + CircularBufferDataProvider maxProvider = (CircularBufferDataProvider) tp.t1.getDataProvider(); + CircularBufferDataProvider valueProvider = (CircularBufferDataProvider) tp.t2.getDataProvider(); + maxProvider.clearTrace(); + valueProvider.clearTrace(); + for (int i = 0; time != null && i < time.size(); i++) { + long x = time.getLong(i); + Value v = value.get(i); + if (v != null && v.getValueType() == ValueEnum.LIST) { + ListValue lv = (ListValue) v; + maxProvider.addSample(new Sample(x, lv.getDouble(0))); + valueProvider.addSample(new Sample(x, lv.getDouble(1))); + } + } + max = Math.max(ChartUtil.getMax(maxProvider.iterator()), max); + } + if (CounterUtil.isPercentValue(objType, counter)) { + xyGraph.primaryYAxis.setRange(0, 100); + } else { + xyGraph.primaryYAxis.setRange(0, max); + } + redraw(); + } + }); + + return Status.OK_STATUS; + } + + }.schedule(); + } + + public void notifyChangeState() { + ExUtil.asyncRun(new Runnable() { + public void run() { + for (TracePair tp : dataMap.values()) { + if (ObjectSelectManager.getInstance().isUnselectedObject(tp.objHash)) { + tp.setVisible(false); + } else { + tp.setVisible(true); + } + } + ExUtil.exec(canvas, new Runnable() { + public void run() { + redraw(); + } + }); + } + }); + } + + private TracePair getTracePair(int objHash) { + TracePair tp = dataMap.get(objHash); + if (tp == null) { + tp = new TracePair(); + tp.objHash = objHash; + + CircularBufferDataProvider data1 = new CircularBufferDataProvider(true); + data1.setBufferSize((int) ((etime - stime) / (DateUtil.MILLIS_PER_SECOND * 2))); + data1.setCurrentXDataArray(new double[] {}); + data1.setCurrentYDataArray(new double[] {}); + String name = StringUtil.trimToEmpty(TextProxy.object.getLoadText( + DateUtil.yyyymmdd(stime), objHash, + serverId)); + Trace trace1 = new Trace(name+"(Max)", xyGraph.primaryXAxis, xyGraph.primaryYAxis, data1); + trace1.setPointStyle(PointStyle.NONE); + trace1.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH)); + trace1.setTraceType(TraceType.SOLID_LINE); + trace1.setTraceColor(AgentColorManager.getInstance().assignColor(objType, objHash)); + xyGraph.addTrace(trace1); + tp.t1 = trace1; + + CircularBufferDataProvider data2 = new CircularBufferDataProvider(true); + data2.setBufferSize((int) ((etime - stime) / (DateUtil.MILLIS_PER_SECOND * 2))); + data2.setCurrentXDataArray(new double[] {}); + data2.setCurrentYDataArray(new double[] {}); + Trace trace2 = new Trace(name+"(Value)", xyGraph.primaryXAxis, xyGraph.primaryYAxis, data2); + trace2.setPointStyle(PointStyle.NONE); + trace2.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH)); + trace2.setTraceType(TraceType.SOLID_LINE); + trace2.setTraceColor(AgentColorManager.getInstance().assignColor(objType, objHash)); + xyGraph.addTrace(trace2); + tp.t2 = trace2; + + dataMap.put(objHash, tp); + } + return tp; + } + + @Override + public void dispose() { + super.dispose(); + ObjectSelectManager.getInstance().removeObjectCheckStateListener(this); + } + + public void redraw() { + if (canvas != null && canvas.isDisposed() == false) { + canvas.redraw(); + xyGraph.repaint(); + } + } + + private static class TracePair { + int objHash; + Trace t1; + Trace t2; + + public void setLineWidth(int width) { + if (t1 != null) t1.setLineWidth(width); + if (t2 != null) t2.setLineWidth(width); + } + + public void setVisible(boolean visible) { + if (t1 != null) t1.setVisible(visible); + if (t2 != null) t2.setVisible(visible); + } + } +} diff --git a/scouter.client/src/scouter/client/counter/views/CounterPastCountView.java b/scouter.client/src/scouter/client/counter/views/CounterPastCountView.java index bc3f93b41..26d5a246b 100644 --- a/scouter.client/src/scouter/client/counter/views/CounterPastCountView.java +++ b/scouter.client/src/scouter/client/counter/views/CounterPastCountView.java @@ -106,7 +106,7 @@ public void setInput(final String date, final String objType, final String count final IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); mgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager mgr) { - mgr.add(new OpenDailyServiceCountAction(win, "Load", objType, counter, Images.bar, serverId, date)); + mgr.add(new OpenDailyServiceCountAction(win, objType, counter, Images.bar, serverId, date)); } }); Menu menu = mgr.createContextMenu(canvas); diff --git a/scouter.client/src/scouter/client/counter/views/CounterPastLongDateAllView.java b/scouter.client/src/scouter/client/counter/views/CounterPastLongDateAllView.java index 9b4b397db..2a987636a 100644 --- a/scouter.client/src/scouter/client/counter/views/CounterPastLongDateAllView.java +++ b/scouter.client/src/scouter/client/counter/views/CounterPastLongDateAllView.java @@ -26,6 +26,7 @@ import java.util.Map; import org.csstudio.swt.xygraph.dataprovider.CircularBufferDataProvider; +import org.csstudio.swt.xygraph.dataprovider.ISample; import org.csstudio.swt.xygraph.dataprovider.Sample; import org.csstudio.swt.xygraph.figures.Trace; import org.csstudio.swt.xygraph.figures.Trace.PointStyle; @@ -40,13 +41,18 @@ import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; +import org.eclipse.jface.window.DefaultToolTip; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.ControlListener; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -79,6 +85,7 @@ import scouter.client.util.ExUtil; import scouter.client.util.ImageUtil; import scouter.client.util.MenuUtil; +import scouter.client.util.ScouterUtil; import scouter.client.util.TimeUtil; import scouter.client.util.TimedSeries; import scouter.client.util.UIUtil; @@ -104,6 +111,7 @@ public class CounterPastLongDateAllView extends ScouterViewPart implements DualC Combo periodCombo; Composite headerComp; Button applyBtn; + Trace nearestTrace; IWorkbenchWindow window; IToolBarManager man; @@ -135,9 +143,9 @@ public void setInput(String sDate, String eDate, String objType, String counter, if(server != null){ counterUnit = server.getCounterEngine().getCounterUnit(objType, counter); counterDisplay = server.getCounterEngine().getCounterDisplayName(objType, counter); - desc = "(Period) [" + sDate.substring(0, 4) + "-" + sDate.substring(4, 6) + "-" + sDate.substring(6, 8) + + desc = "(Daily All) [" + sDate.substring(0, 4) + "-" + sDate.substring(4, 6) + "-" + sDate.substring(6, 8) + " ~ " + eDate.substring(0, 4) + "-" + eDate.substring(4, 6) + "-" + eDate.substring(6, 8) + - "] All " + counterDisplay; + "]" + counterDisplay; } serverText.setText("ⓢ"+((server == null)? "?":server.getName())+" |"+(!"".equals(counterUnit)?" ("+counterUnit+")":"")); sDateText.setText(DateUtil.format(stime, "yyyy-MM-dd")); @@ -296,7 +304,52 @@ public void controlMoved(ControlEvent e) { man = getViewSite().getActionBars().getToolBarManager(); - + final DefaultToolTip toolTip = new DefaultToolTip(canvas, DefaultToolTip.RECREATE, true); + toolTip.setFont(new Font(null, "Arial", 10, SWT.BOLD)); + toolTip.setBackgroundColor(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + canvas.addMouseListener(new MouseListener() { + public void mouseUp(MouseEvent e) { + if (nearestTrace != null) { + nearestTrace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH)); + nearestTrace = null; + } + toolTip.hide(); + } + + public void mouseDown(MouseEvent e) { + double x = xyGraph.primaryXAxis.getPositionValue(e.x, false); + double y = xyGraph.primaryYAxis.getPositionValue(e.y, false); + if (x < 0 || y < 0) { + return; + } + double minDistance = 30.0d; + long time = 0; + double value = 0; + for (Trace t : traces.values()) { + ISample s = ScouterUtil.getNearestPoint(t.getDataProvider(), x); + if (s != null) { + int x2 = xyGraph.primaryXAxis.getValuePosition(s.getXValue(), false); + int y2 = xyGraph.primaryYAxis.getValuePosition(s.getYValue(), false); + double distance = ScouterUtil.getPointDistance(e.x, e.y, x2, y2); + if (minDistance > distance) { + minDistance = distance; + nearestTrace = t; + time = (long) s.getXValue(); + value = s.getYValue(); + } + } + } + if (nearestTrace != null) { + int width = PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH); + nearestTrace.setLineWidth(width + 2); + toolTip.setText(nearestTrace.getName() + + "\nTime : " + DateUtil.format(time, "HH:mm") + + "\nValue : " + FormatUtil.print(value, "#,###.##")); + toolTip.show(new Point(e.x, e.y)); + } + } + public void mouseDoubleClick(MouseEvent e) {} + }); canvas.addKeyListener(new KeyListener() { public void keyReleased(KeyEvent e) { } diff --git a/scouter.client/src/scouter/client/counter/views/CounterPastTimeAllView.java b/scouter.client/src/scouter/client/counter/views/CounterPastTimeAllView.java index 3bdfa4cf6..2bf087c8a 100644 --- a/scouter.client/src/scouter/client/counter/views/CounterPastTimeAllView.java +++ b/scouter.client/src/scouter/client/counter/views/CounterPastTimeAllView.java @@ -27,6 +27,7 @@ import java.util.Map; import org.csstudio.swt.xygraph.dataprovider.CircularBufferDataProvider; +import org.csstudio.swt.xygraph.dataprovider.ISample; import org.csstudio.swt.xygraph.dataprovider.Sample; import org.csstudio.swt.xygraph.figures.Trace; import org.csstudio.swt.xygraph.figures.Trace.PointStyle; @@ -41,11 +42,16 @@ import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.Separator; +import org.eclipse.jface.window.DefaultToolTip; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ControlEvent; import org.eclipse.swt.events.ControlListener; import org.eclipse.swt.events.KeyEvent; import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; @@ -78,6 +84,7 @@ import scouter.client.util.ExUtil; import scouter.client.util.ImageUtil; import scouter.client.util.MenuUtil; +import scouter.client.util.ScouterUtil; import scouter.client.util.TimeUtil; import scouter.client.util.TimedSeries; import scouter.client.util.UIUtil; @@ -102,6 +109,7 @@ public class CounterPastTimeAllView extends ScouterViewPart implements CalendarD Label serverText, sDateText, sTimeText, eTimeText; CalendarDialog calDialog; Composite headerComp; + Trace nearestTrace; IWorkbenchWindow window; IToolBarManager man; @@ -123,7 +131,7 @@ public void setInput(long stime, long etime, String objType, String counter, int String counterDisplay = ""; if(server != null){ counterDisplay = server.getCounterEngine().getCounterDisplayName(objType, counter); - desc = "(Past) [" + DateUtil.format(stime, "yyyy-MM-dd HH:mm:ss") + " ~ " + DateUtil.format(etime, "HH:mm:ss") + "] All " + counterDisplay; + desc = "(Past All) [" + DateUtil.format(stime, "yyyy-MM-dd HH:mm:ss") + " ~ " + DateUtil.format(etime, "HH:mm:ss") + "]" + counterDisplay; } serverText.setText("ⓢ"+((server == null)? "?":server.getName())+" |"); @@ -312,7 +320,52 @@ public void controlMoved(ControlEvent e) { xyGraph.primaryXAxis.setTitle(""); xyGraph.primaryYAxis.setTitle(""); - + final DefaultToolTip toolTip = new DefaultToolTip(canvas, DefaultToolTip.RECREATE, true); + toolTip.setFont(new Font(null, "Arial", 10, SWT.BOLD)); + toolTip.setBackgroundColor(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + canvas.addMouseListener(new MouseListener() { + public void mouseUp(MouseEvent e) { + if (nearestTrace != null) { + nearestTrace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH)); + nearestTrace = null; + } + toolTip.hide(); + } + + public void mouseDown(MouseEvent e) { + double x = xyGraph.primaryXAxis.getPositionValue(e.x, false); + double y = xyGraph.primaryYAxis.getPositionValue(e.y, false); + if (x < 0 || y < 0) { + return; + } + double minDistance = 30.0d; + long time = 0; + double value = 0; + for (Trace t : traces.values()) { + ISample s = ScouterUtil.getNearestPoint(t.getDataProvider(), x); + if (s != null) { + int x2 = xyGraph.primaryXAxis.getValuePosition(s.getXValue(), false); + int y2 = xyGraph.primaryYAxis.getValuePosition(s.getYValue(), false); + double distance = ScouterUtil.getPointDistance(e.x, e.y, x2, y2); + if (minDistance > distance) { + minDistance = distance; + nearestTrace = t; + time = (long) s.getXValue(); + value = s.getYValue(); + } + } + } + if (nearestTrace != null) { + int width = PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH); + nearestTrace.setLineWidth(width + 2); + toolTip.setText(nearestTrace.getName() + + "\nTime : " + DateUtil.format(time, "HH:mm:ss") + + "\nValue : " + FormatUtil.print(value, "#,###.##")); + toolTip.show(new Point(e.x, e.y)); + } + } + public void mouseDoubleClick(MouseEvent e) {} + }); canvas.addKeyListener(new KeyListener() { public void keyReleased(KeyEvent e) { } @@ -401,7 +454,7 @@ private synchronized Trace intern(int objHash) { return trace; CircularBufferDataProvider traceDataProvider = new CircularBufferDataProvider(true); - traceDataProvider.setBufferSize(7200); + traceDataProvider.setBufferSize((int) ((endTime - startTime) / (DateUtil.MILLIS_PER_SECOND * 2)) + 1); traceDataProvider.setCurrentXDataArray(new double[] {}); traceDataProvider.setCurrentYDataArray(new double[] {}); diff --git a/scouter.client/src/scouter/client/counter/views/CounterRTAllPairChart.java b/scouter.client/src/scouter/client/counter/views/CounterRTAllPairChart.java new file mode 100644 index 000000000..50053b7ff --- /dev/null +++ b/scouter.client/src/scouter/client/counter/views/CounterRTAllPairChart.java @@ -0,0 +1,397 @@ +package scouter.client.counter.views; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.csstudio.swt.xygraph.dataprovider.CircularBufferDataProvider; +import org.csstudio.swt.xygraph.dataprovider.ISample; +import org.csstudio.swt.xygraph.dataprovider.Sample; +import org.csstudio.swt.xygraph.figures.Trace; +import org.csstudio.swt.xygraph.figures.Trace.PointStyle; +import org.csstudio.swt.xygraph.figures.Trace.TraceType; +import org.csstudio.swt.xygraph.figures.XYGraph; +import org.csstudio.swt.xygraph.linearscale.Range; +import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.window.DefaultToolTip; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.ControlListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.IViewSite; +import org.eclipse.ui.PartInitException; + +import scouter.client.counter.actions.OpenPTPairAllAction; +import scouter.client.listeners.RangeMouseListener; +import scouter.client.maria.actions.OpenDbDailyConnView; +import scouter.client.model.AgentColorManager; +import scouter.client.model.RefreshThread; +import scouter.client.model.RefreshThread.Refreshable; +import scouter.client.model.TextProxy; +import scouter.client.net.TcpProxy; +import scouter.client.preferences.PManager; +import scouter.client.preferences.PreferenceConstants; +import scouter.client.server.Server; +import scouter.client.server.ServerManager; +import scouter.client.threads.ObjectSelectManager; +import scouter.client.threads.ObjectSelectManager.IObjectCheckListener; +import scouter.client.util.ChartUtil; +import scouter.client.util.ColorUtil; +import scouter.client.util.ConsoleProxy; +import scouter.client.util.CounterUtil; +import scouter.client.util.ExUtil; +import scouter.client.util.ScouterUtil; +import scouter.client.util.TimeUtil; +import scouter.client.views.ScouterViewPart; +import scouter.lang.counters.CounterEngine; +import scouter.lang.pack.MapPack; +import scouter.lang.value.ListValue; +import scouter.lang.value.Value; +import scouter.lang.value.ValueEnum; +import scouter.net.RequestCmd; +import scouter.util.CastUtil; +import scouter.util.DateUtil; +import scouter.util.FormatUtil; +import scouter.util.StringUtil; + +public class CounterRTAllPairChart extends ScouterViewPart implements Refreshable, IObjectCheckListener { + + public final static String ID = CounterRTAllPairChart.class.getName(); + + protected RefreshThread thread = null; + + private int serverId; + private String objType; + private String counter; + + protected XYGraph xyGraph; + protected Map dataMap = new HashMap(); + TracePair nearestTracePair; + protected FigureCanvas canvas; + boolean isActive = false; + + public void init(IViewSite site) throws PartInitException { + super.init(site); + String secId = site.getSecondaryId(); + String[] ids = StringUtil.split(secId, "&"); + this.serverId = CastUtil.cint(ids[0]); + this.objType = ids[1]; + this.counter = ids[2]; + } + + public void createPartControl(Composite parent) { + GridLayout layout = new GridLayout(1, true); + layout.marginHeight = 5; + layout.marginWidth = 5; + parent.setLayout(layout); + parent.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE)); + parent.setBackgroundMode(SWT.INHERIT_FORCE); + + canvas = new FigureCanvas(parent); + canvas.setLayoutData(new GridData(GridData.FILL_BOTH)); + canvas.setScrollBarVisibility(FigureCanvas.NEVER); + canvas.addControlListener(new ControlListener() { + boolean lock = false; + + public void controlResized(ControlEvent e) { + org.eclipse.swt.graphics.Rectangle r = canvas.getClientArea(); + if (!lock) { + lock = true; + if (ChartUtil.isShowDescriptionAllowSize(r.height)) { + CounterRTAllPairChart.this.setContentDescription(desc); + } else { + CounterRTAllPairChart.this.setContentDescription(""); + } + r = canvas.getClientArea(); + xyGraph.setSize(r.width, r.height); + lock = false; + } + } + + public void controlMoved(ControlEvent e) { + } + }); + + xyGraph = new XYGraph(); + xyGraph.setShowLegend(false); + xyGraph.setShowTitle(false); + canvas.setContents(xyGraph); + + xyGraph.primaryXAxis.setDateEnabled(true); + xyGraph.primaryXAxis.setShowMajorGrid(true); + + xyGraph.primaryYAxis.setAutoScale(true); + xyGraph.primaryYAxis.setShowMajorGrid(true); + + xyGraph.primaryXAxis.setTitle(""); + xyGraph.primaryYAxis.setTitle(""); + + xyGraph.primaryXAxis.setFormatPattern("HH:mm:ss"); + xyGraph.primaryYAxis.setFormatPattern("#,##0"); + + xyGraph.primaryYAxis.addMouseListener(new RangeMouseListener(getViewSite().getShell(), xyGraph.primaryYAxis)); + + final DefaultToolTip toolTip = new DefaultToolTip(canvas, DefaultToolTip.RECREATE, true); + toolTip.setFont(new Font(null, "Arial", 10, SWT.BOLD)); + toolTip.setBackgroundColor(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + + canvas.addMouseListener(new MouseListener() { + public void mouseUp(MouseEvent e) { + if (nearestTracePair != null) { + int width = PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH); + nearestTracePair.setLineWidth(width); + nearestTracePair = null; + } + toolTip.hide(); + } + public void mouseDown(MouseEvent e) { + double x = xyGraph.primaryXAxis.getPositionValue(e.x, false); + double y = xyGraph.primaryYAxis.getPositionValue(e.y, false); + if (x < 0 || y < 0) { + return; + } + double minDistance = 30.0d; + long time = 0; + double max = 0; + double value = 0; + Iterator keys = dataMap.keySet().iterator(); + while (keys.hasNext()) { + int objHash = keys.next(); + TracePair tp = dataMap.get(objHash); + Trace t1 = tp.t1; + ISample s1 = ScouterUtil.getNearestPoint(t1.getDataProvider(), x); + Trace t2 = tp.t2; + ISample s2 = ScouterUtil.getNearestPoint(t2.getDataProvider(), x); + if (s1 != null && s2 != null) { + int x1 = xyGraph.primaryXAxis.getValuePosition(s1.getXValue(), false); + int y1 = xyGraph.primaryYAxis.getValuePosition(s1.getYValue(), false); + int x2 = xyGraph.primaryXAxis.getValuePosition(s2.getXValue(), false); + int y2 = xyGraph.primaryYAxis.getValuePosition(s2.getYValue(), false); + double distance1 = ScouterUtil.getPointDistance(e.x, e.y, x1, y1); + double distance2 = ScouterUtil.getPointDistance(e.x, e.y, x2, y2); + double distance = distance1 > distance2 ? distance2 : distance1; + if (minDistance > distance) { + minDistance = distance; + nearestTracePair = tp; + time = (long) s1.getXValue(); + max = s1.getYValue(); + value = s2.getYValue(); + } + } + + } + if (nearestTracePair != null) { + int width = PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH); + nearestTracePair.setLineWidth(width + 2); + toolTip.setText(TextProxy.object.getText(nearestTracePair.objHash) + + "\nTime : " + DateUtil.format(time, "HH:mm:ss") + + "\nMax : " + FormatUtil.print(max, "#,###.##") + + "\nValue : " + FormatUtil.print(value, "#,###.##")); + toolTip.show(new Point(e.x, e.y)); + } + } + public void mouseDoubleClick(MouseEvent e) {} + }); + + ObjectSelectManager.getInstance().addObjectCheckStateListener(this); + try { + setViewTab(objType, counter, serverId); + Server server = ServerManager.getInstance().getServer(serverId); + CounterEngine ce = server.getCounterEngine(); + String counterName = ce.getCounterDisplayName(objType, counter); + desc = "ⓢ" + server.getName() + " | (Current All) " + counterName + "(" + ce.getCounterUnit(objType, counter) + ")"; + } catch (Exception e1) { + e1.printStackTrace(); + } + + IToolBarManager man = getViewSite().getActionBars().getToolBarManager(); + man.add(new OpenPTPairAllAction(getViewSite().getWorkbenchWindow(), "Load", serverId, objType, counter)); + + thread = new RefreshThread(this, 2000); + thread.setName(this.toString() + " - " + "objType:" + objType + ", counter:" + counter + ", serverId:" + serverId); + thread.start(); + } + + public void notifyChangeState() { + ExUtil.asyncRun(new Runnable() { + public void run() { + for (TracePair tp : dataMap.values()) { + if (ObjectSelectManager.getInstance().isUnselectedObject(tp.objHash)) { + tp.setVisible(false); + } else { + tp.setVisible(true); + } + } + ExUtil.exec(canvas, new Runnable() { + public void run() { + redraw(); + } + }); + } + }); + } + + private TracePair getTracePair(int objHash) { + TracePair tp = dataMap.get(objHash); + if (tp == null) { + tp = new TracePair(); + tp.objHash = objHash; + + CircularBufferDataProvider data1 = new CircularBufferDataProvider(true); + data1.setBufferSize(155); + data1.setCurrentXDataArray(new double[] {}); + data1.setCurrentYDataArray(new double[] {}); + String name = StringUtil.trimToEmpty(TextProxy.object.getLoadText( + DateUtil.yyyymmdd(TimeUtil.getCurrentTime(serverId)), objHash, + serverId)); + Trace trace1 = new Trace(name+"(Max)", xyGraph.primaryXAxis, xyGraph.primaryYAxis, data1); + trace1.setPointStyle(PointStyle.NONE); + trace1.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH)); + trace1.setTraceType(TraceType.SOLID_LINE); + trace1.setTraceColor(AgentColorManager.getInstance().assignColor(objType, objHash)); + xyGraph.addTrace(trace1); + tp.t1 = trace1; + + CircularBufferDataProvider data2 = new CircularBufferDataProvider(true); + data2.setBufferSize(155); + data2.setCurrentXDataArray(new double[] {}); + data2.setCurrentYDataArray(new double[] {}); + Trace trace2 = new Trace(name+"(Value)", xyGraph.primaryXAxis, xyGraph.primaryYAxis, data2); + trace2.setPointStyle(PointStyle.NONE); + trace2.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH)); + trace2.setTraceType(TraceType.SOLID_LINE); + trace2.setTraceColor(AgentColorManager.getInstance().assignColor(objType, objHash)); + xyGraph.addTrace(trace2); + tp.t2 = trace2; + + dataMap.put(objHash, tp); + } + return tp; + } + + private double getMaxValue() { + Iterator objHashs = dataMap.keySet().iterator(); + double max = 0.0; + Range xRange = xyGraph.primaryXAxis.getRange(); + double lower = xRange.getLower(); + double upper = xRange.getUpper(); + while (objHashs.hasNext()) { + int objHash = objHashs.next(); + CircularBufferDataProvider data = (CircularBufferDataProvider) dataMap.get(objHash).t1.getDataProvider(); + if (data != null) { + for (int inx = 0; inx < data.getSize(); inx++) { + Sample sample = (Sample) data.getSample(inx); + double x = sample.getXValue(); + if(x < lower || x > upper) { + continue; + } + double y = sample.getYValue(); + if (y > max) { + max = y; + } + } + } + } + return ChartUtil.getMaxValue(max); + } + + public void refresh() { + final HashMap values = new HashMap(); + TcpProxy tcp = TcpProxy.getTcpProxy(serverId); + try { + MapPack param = new MapPack(); + + param.put("objType", objType); + param.put("counter", counter); + + MapPack out = (MapPack) tcp.getSingle(RequestCmd.COUNTER_REAL_TIME_ALL, param); + isActive = false; + if (out != null) { + ListValue objHash = out.getList("objHash"); + ListValue v = out.getList("value"); + for (int i = 0; i < objHash.size(); i++) { + values.put(CastUtil.cint(objHash.get(i)), v.get(i)); + isActive = true; + } + } + } catch (Throwable t) { + ConsoleProxy.errorSafe(t.toString()); + } finally { + TcpProxy.putTcpProxy(tcp); + } + + ExUtil.exec(canvas, new Runnable() { + public void run() { + if (isActive) { + setActive(); + } else { + setInactive(); + } + + long now = TimeUtil.getCurrentTime(serverId); + xyGraph.primaryXAxis.setRange(now - DateUtil.MILLIS_PER_MINUTE * 5, now + 1); + Iterator itr = values.keySet().iterator(); + while (itr.hasNext()) { + int objHash = itr.next(); + Value value = values.get(objHash); + if (value != null && value.getValueType() == ValueEnum.LIST) { + ListValue lv = (ListValue) value; + TracePair tp = getTracePair(objHash); + CircularBufferDataProvider provider1 = (CircularBufferDataProvider) tp.t1.getDataProvider(); + CircularBufferDataProvider provider2 = (CircularBufferDataProvider) tp.t2.getDataProvider(); + provider1.addSample(new Sample(now, CastUtil.cdouble(lv.get(0)))); + provider2.addSample(new Sample(now, CastUtil.cdouble(lv.get(1)))); + } + + } + if (CounterUtil.isPercentValue(objType, counter)) { + xyGraph.primaryYAxis.setRange(0, 100); + } else { + double max = getMaxValue(); + xyGraph.primaryYAxis.setRange(0, max); + } + redraw(); + } + }); + } + + @Override + public void dispose() { + super.dispose(); + if (this.thread != null) { + this.thread.shutdown(); + } + ObjectSelectManager.getInstance().removeObjectCheckStateListener(this); + } + + public void redraw() { + if (canvas != null && canvas.isDisposed() == false) { + canvas.redraw(); + xyGraph.repaint(); + } + } + + private static class TracePair { + int objHash; + Trace t1; + Trace t2; + + public void setLineWidth(int width) { + if (t1 != null) t1.setLineWidth(width); + if (t2 != null) t2.setLineWidth(width); + } + + public void setVisible(boolean visible) { + if (t1 != null) t1.setVisible(visible); + if (t2 != null) t2.setVisible(visible); + } + } +} diff --git a/scouter.client/src/scouter/client/counter/views/CounterRealTimeAllView.java b/scouter.client/src/scouter/client/counter/views/CounterRealTimeAllView.java index 32647295b..935545102 100644 --- a/scouter.client/src/scouter/client/counter/views/CounterRealTimeAllView.java +++ b/scouter.client/src/scouter/client/counter/views/CounterRealTimeAllView.java @@ -24,6 +24,7 @@ import java.util.Map; import org.csstudio.swt.xygraph.dataprovider.CircularBufferDataProvider; +import org.csstudio.swt.xygraph.dataprovider.ISample; import org.csstudio.swt.xygraph.dataprovider.Sample; import org.csstudio.swt.xygraph.figures.Trace; import org.csstudio.swt.xygraph.figures.Trace.PointStyle; @@ -42,12 +43,7 @@ import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.PaletteData; import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; @@ -109,6 +105,7 @@ public class CounterRealTimeAllView extends ScouterViewPart implements Refreshab protected XYGraph xyGraph; protected Map datas = new HashMap(); protected FigureCanvas canvas; + Trace nearestTrace; ArrayList traces = new ArrayList(); @@ -183,52 +180,46 @@ public void controlMoved(ControlEvent e) { toolTip.setFont(new Font(null, "Arial", 10, SWT.BOLD)); toolTip.setBackgroundColor(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); canvas.addMouseListener(new MouseListener() { + public void mouseUp(MouseEvent e) { - onDeselectObject(); + if (nearestTrace != null) { + nearestTrace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH)); + nearestTrace = null; + } toolTip.hide(); } + public void mouseDown(MouseEvent e) { double x = xyGraph.primaryXAxis.getPositionValue(e.x, false); double y = xyGraph.primaryYAxis.getPositionValue(e.y, false); if (x < 0 || y < 0) { return; } - Image image = new Image(e.display, 1, 10); - GC gc = new GC((FigureCanvas)e.widget); - gc.copyArea(image, e.x, e.y > 5 ? e.y - 5 : 0); - ImageData imageData = image.getImageData(); - PaletteData palette = imageData.palette; - RGB white = new RGB(255, 255, 255); - int point = 5; - int offset = 0; - while (point >= 0 && point < 10) { - int pixelValue = imageData.getPixel(0, point); - RGB rgb = palette.getRGB(pixelValue); - if (white.equals(rgb) == false) { - int objHash = AgentColorManager.getInstance().getObjectHash(rgb); - if (objHash != 0) { - String objName = TextProxy.object.getText(objHash); - double time = xyGraph.primaryXAxis.getPositionValue(e.x, false); - double v = 0.0d; - for (Trace t : traces) { - if (t.getName().equals(objName)) { - v = ScouterUtil.getNearestValue(t.getDataProvider(), time); - String value = FormatUtil.print(v, "#,###.##"); - toolTip.setText(objName + "\nvalue : " + value); - toolTip.show(new Point(e.x, e.y)); - onSelectObject(objHash, objName, objType); - break; - } - } - break; + double minDistance = 30.0d; + long time = 0; + double value = 0; + for (Trace t : traces) { + ISample s = ScouterUtil.getNearestPoint(t.getDataProvider(), x); + if (s != null) { + int x2 = xyGraph.primaryXAxis.getValuePosition(s.getXValue(), false); + int y2 = xyGraph.primaryYAxis.getValuePosition(s.getYValue(), false); + double distance = ScouterUtil.getPointDistance(e.x, e.y, x2, y2); + if (minDistance > distance) { + minDistance = distance; + nearestTrace = t; + time = (long) s.getXValue(); + value = s.getYValue(); } } - offset = offset >= 0 ? offset + 1 : offset - 1; - offset *= -1; - point += offset; } - gc.dispose(); - image.dispose(); + if (nearestTrace != null) { + int width = PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH); + nearestTrace.setLineWidth(width + 2); + toolTip.setText(nearestTrace.getName() + + "\nTime : " + DateUtil.format(time, "HH:mm:ss") + + "\nValue : " + FormatUtil.print(value, "#,###.##")); + toolTip.show(new Point(e.x, e.y)); + } } public void mouseDoubleClick(MouseEvent e) {} }); @@ -270,7 +261,7 @@ public void run() { counterDisplay = server.getCounterEngine().getCounterDisplayName(objType, counter); counterUnit = server.getCounterEngine().getCounterUnit(objType, counter); } - desc = "ⓢ" + svrName + " | (Realtime) All " + counterDisplay + (!"".equals(counterUnit) ? " (" + counterUnit + ")" : ""); + desc = "ⓢ" + svrName + " | (Current All) " + counterDisplay + (!"".equals(counterUnit) ? " (" + counterUnit + ")" : ""); try { setViewTab(objType, counter, serverId); } catch (Exception e1) { @@ -355,7 +346,7 @@ public void run() { int width = PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH); synchronized (traces) { for (Trace t : traces) { - if (selectedMode == false && t.getLineWidth() != width) { + if (nearestTrace == null && t.getLineWidth() != width) { t.setLineWidth(width); } int objHash = HashUtil.hash(t.getName()); @@ -491,38 +482,6 @@ public void redraw() { } } - boolean selectedMode = false; - - public void onSelectObject(int objHash, final String objName, String objType) { - if (this.objType.equals(objType) == false) { - return; - } - ExUtil.exec(canvas, new Runnable() { - public void run() { - int width = PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH); - for (Trace t : traces) { - if (t.getName().equals(objName)) { - t.setLineWidth(width + 2); - selectedMode = true; - break; - } - } - } - }); - } - - public void onDeselectObject() { - ExUtil.exec(canvas, new Runnable() { - public void run() { - int width = PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH); - for (Trace t : traces) { - t.setLineWidth(width); - } - selectedMode = false; - } - }); - } - public void notifyChangeState() { ExUtil.asyncRun(new Runnable() { public void run() { diff --git a/scouter.client/src/scouter/client/counter/views/CounterRealTimeTotalView.java b/scouter.client/src/scouter/client/counter/views/CounterRealTimeTotalView.java index b1fef149b..fb1228855 100644 --- a/scouter.client/src/scouter/client/counter/views/CounterRealTimeTotalView.java +++ b/scouter.client/src/scouter/client/counter/views/CounterRealTimeTotalView.java @@ -194,7 +194,7 @@ public void run() { counterDisplay = server.getCounterEngine().getCounterDisplayName(objType, counter); counterUnit = server.getCounterEngine().getCounterUnit(objType, counter); } - desc = "ⓢ"+svrName+" | (Realtime) Total " + counterDisplay + (!"".equals(counterUnit)?" ("+counterUnit+")":""); + desc = "ⓢ"+svrName+" | (Current Total) " + counterDisplay + (!"".equals(counterUnit)?" ("+counterUnit+")":""); try { setViewTab(objType, counter, serverId); } catch (Exception e1) { diff --git a/scouter.client/src/scouter/client/counter/views/CounterTodayAllView.java b/scouter.client/src/scouter/client/counter/views/CounterTodayAllView.java index 33928bc74..634b184af 100644 --- a/scouter.client/src/scouter/client/counter/views/CounterTodayAllView.java +++ b/scouter.client/src/scouter/client/counter/views/CounterTodayAllView.java @@ -23,6 +23,7 @@ import java.util.Map; import org.csstudio.swt.xygraph.dataprovider.CircularBufferDataProvider; +import org.csstudio.swt.xygraph.dataprovider.ISample; import org.csstudio.swt.xygraph.dataprovider.Sample; import org.csstudio.swt.xygraph.figures.Trace; import org.csstudio.swt.xygraph.figures.Trace.PointStyle; @@ -101,6 +102,7 @@ public class CounterTodayAllView extends ScouterViewPart implements Refreshable, IWorkbenchWindow window; IToolBarManager man; + Trace nearestTrace; public void init(IViewSite site) throws PartInitException { super.init(site); @@ -187,7 +189,7 @@ public void run() { int width = PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH); synchronized (traces) { for (Trace t : traces) { - if (selectedMode == false && t.getLineWidth() != width) { + if (nearestTrace == null && t.getLineWidth() != width) { t.setLineWidth(width); } int objHash = HashUtil.hash(t.getName()); @@ -283,51 +285,44 @@ public void controlMoved(ControlEvent e) { toolTip.setBackgroundColor(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); canvas.addMouseListener(new MouseListener() { public void mouseUp(MouseEvent e) { - onDeselectObject(); + if (nearestTrace != null) { + nearestTrace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH)); + nearestTrace = null; + } toolTip.hide(); } + public void mouseDown(MouseEvent e) { double x = xyGraph.primaryXAxis.getPositionValue(e.x, false); double y = xyGraph.primaryYAxis.getPositionValue(e.y, false); if (x < 0 || y < 0) { return; } - Image image = new Image(e.display, 1, 10); - GC gc = new GC((FigureCanvas)e.widget); - gc.copyArea(image, e.x, e.y > 5 ? e.y - 5 : 0); - ImageData imageData = image.getImageData(); - PaletteData palette = imageData.palette; - RGB white = new RGB(255, 255, 255); - int point = 5; - int offset = 0; - while (point >= 0 && point < 10) { - int pixelValue = imageData.getPixel(0, point); - RGB rgb = palette.getRGB(pixelValue); - if (white.equals(rgb) == false) { - int objHash = AgentColorManager.getInstance().getObjectHash(rgb); - if (objHash != 0) { - String objName = TextProxy.object.getText(objHash); - double time = xyGraph.primaryXAxis.getPositionValue(e.x, false); - double v = 0.0d; - for (Trace t : traces) { - if (t.getName().equals(objName)) { - v = ScouterUtil.getNearestValue(t.getDataProvider(), time); - String value = FormatUtil.print(v, "#,###.##"); - toolTip.setText(objName + "\nvalue : " + value); - toolTip.show(new Point(e.x, e.y)); - onSelectObject(objHash, objName, objType); - break; - } - } - break; + double minDistance = 30.0d; + long time = 0; + double value = 0; + for (Trace t : traces) { + ISample s = ScouterUtil.getNearestPoint(t.getDataProvider(), x); + if (s != null) { + int x2 = xyGraph.primaryXAxis.getValuePosition(s.getXValue(), false); + int y2 = xyGraph.primaryYAxis.getValuePosition(s.getYValue(), false); + double distance = ScouterUtil.getPointDistance(e.x, e.y, x2, y2); + if (minDistance > distance) { + minDistance = distance; + nearestTrace = t; + time = (long) s.getXValue(); + value = s.getYValue(); } } - offset = offset >= 0 ? offset + 1 : offset - 1; - offset *= -1; - point += offset; } - gc.dispose(); - image.dispose(); + if (nearestTrace != null) { + int width = PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH); + nearestTrace.setLineWidth(width + 2); + toolTip.setText(nearestTrace.getName() + + "\nTime : " + DateUtil.format(time, "HH:mm") + + "\nValue : " + FormatUtil.print(value, "#,###.##")); + toolTip.show(new Point(e.x, e.y)); + } } public void mouseDoubleClick(MouseEvent e) {} }); @@ -358,7 +353,7 @@ public void keyPressed(KeyEvent e) { counterDisplay = server.getCounterEngine().getCounterDisplayName(objType, counter); counterUnit = server.getCounterEngine().getCounterUnit(objType, counter); } - desc = "ⓢ"+svrName+" | (Today) [" + date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6, 8) + "] All " + counterDisplay+(!"".equals(counterUnit)?" ("+counterUnit+")":""); + desc = "ⓢ"+svrName+" | (Today All) [" + date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6, 8) + "]" + counterDisplay+(!"".equals(counterUnit)?" ("+counterUnit+")":""); try { setViewTab(objType, counter, serverId); } catch (Exception e1) { @@ -412,38 +407,6 @@ public void dispose() { ObjectSelectManager.getInstance().removeObjectCheckStateListener(this); } - boolean selectedMode = false; - - public void onSelectObject(int objHash, final String objName, String objType) { - if (this.objType.equals(objType) == false) { - return; - } - ExUtil.exec(canvas, new Runnable() { - public void run() { - int width = PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH); - for (Trace t : traces) { - if (t.getName().equals(objName)) { - t.setLineWidth(width + 2); - selectedMode = true; - break; - } - } - } - }); - } - - public void onDeselectObject() { - ExUtil.exec(canvas, new Runnable() { - public void run() { - int width = PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH); - for (Trace t : traces) { - t.setLineWidth(width); - } - selectedMode = false; - } - }); - } - public void redraw() { if (canvas != null && canvas.isDisposed() == false) { canvas.redraw(); diff --git a/scouter.client/src/scouter/client/counter/views/CounterTodayCountView.java b/scouter.client/src/scouter/client/counter/views/CounterTodayCountView.java index dfa4ddb02..052cdae93 100644 --- a/scouter.client/src/scouter/client/counter/views/CounterTodayCountView.java +++ b/scouter.client/src/scouter/client/counter/views/CounterTodayCountView.java @@ -322,7 +322,7 @@ public void mouseDoubleClick(MouseEvent e) {} final IWorkbenchWindow win = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); mgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager mgr) { - mgr.add(new OpenDailyServiceCountAction(win, "Load", objType, counter, Images.bar, serverId)); + mgr.add(new OpenDailyServiceCountAction(win, objType, counter, Images.bar, serverId)); } }); Menu menu = mgr.createContextMenu(canvas); diff --git a/scouter.client/src/scouter/client/counter/views/CounterTodayTotalView.java b/scouter.client/src/scouter/client/counter/views/CounterTodayTotalView.java index 04503164b..b783d78d5 100644 --- a/scouter.client/src/scouter/client/counter/views/CounterTodayTotalView.java +++ b/scouter.client/src/scouter/client/counter/views/CounterTodayTotalView.java @@ -291,7 +291,7 @@ public void keyPressed(KeyEvent e) { counterDisplay = server.getCounterEngine().getCounterDisplayName(objType, counter); counterUnit = server.getCounterEngine().getCounterUnit(objType, counter); } - desc = "ⓢ"+svrName+" | (Today) [" + date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6, 8) + "] Total " + counterDisplay+(!"".equals(counterUnit)?" ("+counterUnit+")":""); + desc = "ⓢ"+svrName+" | (Today Total) [" + date.substring(0, 4) + "-" + date.substring(4, 6) + "-" + date.substring(6, 8) + "]" + counterDisplay+(!"".equals(counterUnit)?" ("+counterUnit+")":""); try { setViewTab(objType, counter, serverId); } catch (Exception e1) { diff --git a/scouter.client/src/scouter/client/group/view/GroupNavigationView.java b/scouter.client/src/scouter/client/group/view/GroupNavigationView.java index b6a4cd0b8..f1d56fba9 100644 --- a/scouter.client/src/scouter/client/group/view/GroupNavigationView.java +++ b/scouter.client/src/scouter/client/group/view/GroupNavigationView.java @@ -59,7 +59,8 @@ import scouter.client.actions.OpenAddGroupAction; import scouter.client.actions.OpenEQGroupViewAction; import scouter.client.actions.OpenManageGroupAction; -import scouter.client.actions.OpenServiceGroupGroupAction; +import scouter.client.actions.OpenServiceGroupElapsedGroupAction; +import scouter.client.actions.OpenServiceGroupTPSGroupAction; import scouter.client.constants.MenuStr; import scouter.client.context.actions.OpenCxtmenuAssginGroupAction; import scouter.client.counter.actions.OpenActiveSpeedGroupViewAction; @@ -204,26 +205,21 @@ public void menuAboutToShow(IMenuManager manager){ } } manager.add(new Separator()); - if (isActionEnable(objType, CounterConstants.ACTIVE_EQ)) { + if (isChildOf(objType, CounterConstants.FAMILY_JAVAEE)) { manager.add(new OpenEQGroupViewAction(win, grpObj.getName())); - } - if (isActionEnable(objType, CounterConstants.TOTAL_ACTIVE_SPEED)) { manager.add(new OpenActiveSpeedGroupViewAction(win, MenuStr.ACTIVE_SPEED_REAL, grpObj)); - } - MenuManager xLogMenu = new MenuManager(MenuStr.XLOG, ImageUtil.getImageDescriptor(Images.transrealtime), MenuStr.XLOG_ID); - manager.add(xLogMenu); - if (isActionEnable(objType, CounterConstants.TRANX_REALTIME)) { - xLogMenu.add(new OpenRealTimeTranXGroupViewAction(win, MenuStr.REALTIME_XLOG, grpObj)); - xLogMenu.add(new OpenPastTimeTranXGroupViewAction(win, MenuStr.PASTTIME_XLOG, grpObj)); - } - MenuManager scMenu = new MenuManager(MenuStr.HOURLY_CHART, ImageUtil.getImageDescriptor(Images.bar), MenuStr.HOURLY_CHART_ID); - manager.add(scMenu); - if (isActionEnable(objType, CounterConstants.TODAY_SERVICE_COUNT)) { - scMenu.add(new OpenTodayGroupCountViewAction(win, MenuStr.TODAY_SERVICE_COUNT, CounterConstants.WAS_SERVICE_COUNT, grpObj)); - scMenu.add(new OpenPastDateGroupCountViewAction(win, MenuStr.LOAD_SERVICE_COUNT, CounterConstants.WAS_SERVICE_COUNT, grpObj)); - } - if (isActionEnable(objType, CounterConstants.SERVICE_GROUP)) { - manager.add(new OpenServiceGroupGroupAction(win, grpName)); + MenuManager xLogMenu = new MenuManager(MenuStr.XLOG, ImageUtil.getImageDescriptor(Images.transrealtime), MenuStr.XLOG_ID); + manager.add(xLogMenu); + xLogMenu.add(new OpenRealTimeTranXGroupViewAction(win, MenuStr.REALTIME_XLOG, grpObj)); + xLogMenu.add(new OpenPastTimeTranXGroupViewAction(win, MenuStr.PASTTIME_XLOG, grpObj)); + MenuManager scMenu = new MenuManager(MenuStr.HOURLY_CHART, ImageUtil.getImageDescriptor(Images.bar), MenuStr.HOURLY_CHART_ID); + manager.add(scMenu); + scMenu.add(new OpenPastDateGroupCountViewAction(win, MenuStr.LOAD_SERVICE_COUNT, CounterConstants.WAS_SERVICE_COUNT, grpObj)); + scMenu.add(new OpenTodayGroupCountViewAction(win, MenuStr.TODAY_SERVICE_COUNT, CounterConstants.WAS_SERVICE_COUNT, grpObj)); + MenuManager serviceGroupMgr = new MenuManager("Serivce Group", ImageUtil.getImageDescriptor(Images.sum), "scouter.menu.id.group.javee.servicegroup"); + manager.add(serviceGroupMgr); + serviceGroupMgr.add(new OpenServiceGroupTPSGroupAction(win, grpName)); + serviceGroupMgr.add(new OpenServiceGroupElapsedGroupAction(win, grpName)); } } } else if (selObject instanceof AgentObject) { @@ -335,6 +331,20 @@ private boolean isActionEnable(String objType, String attrName) { return result; } + private boolean isChildOf(String objType, String family) { + boolean result = false; + Set serverList = ServerManager.getInstance().getOpenServerList(); + for (int serverId : serverList) { + Server server = ServerManager.getInstance().getServer(serverId); + CounterEngine engine = server.getCounterEngine(); + if (engine.isChildOf(objType, family)) { + result = true; + break; + } + } + return result; + } + class TreeContentProvider implements ITreeContentProvider { public void dispose() { diff --git a/scouter.client/src/scouter/client/group/view/ServiceGroupElapsedGroupView.java b/scouter.client/src/scouter/client/group/view/ServiceGroupElapsedGroupView.java new file mode 100644 index 000000000..c9c293a0e --- /dev/null +++ b/scouter.client/src/scouter/client/group/view/ServiceGroupElapsedGroupView.java @@ -0,0 +1,123 @@ +/* + * Copyright 2015 the original author or authors. + * @https://github.com/scouter-project/scouter + * + * 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 scouter.client.group.view; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IViewSite; +import org.eclipse.ui.PartInitException; + +import scouter.client.net.TcpProxy; +import scouter.client.util.ScouterUtil; +import scouter.client.util.TimeUtil; +import scouter.client.views.AbstractServiceGroupElapsedView; +import scouter.lang.pack.MapPack; +import scouter.lang.value.ListValue; +import scouter.net.RequestCmd; +import scouter.util.CastUtil; + +public class ServiceGroupElapsedGroupView extends AbstractServiceGroupElapsedView { + + public final static String ID = ServiceGroupElapsedGroupView.class.getName(); + + String grpName; + private Map serverObjMap = new HashMap(); + + public void init(IViewSite site) throws PartInitException { + super.init(site); + String secId = site.getSecondaryId(); + grpName = secId; + } + + public void createPartControl(Composite parent) { + this.setPartName("Service[Elapsed] - " + grpName); + super.createPartControl(parent); + } + + @Override + public MapPack fetch() { + ScouterUtil.collectGroupObjcts(grpName, serverObjMap); + HashMap valueMap = new HashMap(); + Iterator itr = serverObjMap.keySet().iterator(); + while (itr.hasNext()) { + int serverId = itr.next(); + TcpProxy tcp = TcpProxy.getTcpProxy(serverId); + try { + MapPack param = new MapPack(); + param.put("objHash", serverObjMap.get(serverId)); + MapPack p = (MapPack) tcp.getSingle(RequestCmd.REALTIME_SERVICE_GROUP, param); + if (p != null) { + ListValue nameLv = p.getList("name"); + ListValue countLv = p.getList("count"); + ListValue elapsedLv = p.getList("elapsed"); + ListValue errorLv = p.getList("error"); + for (int i = 0, max = (nameLv == null ? 0 : nameLv.size()) ; i < max; i++) { + String name = nameLv.getString(i); + PerfStat perf = valueMap.get(name); + if (perf == null) { + perf = new PerfStat(); + valueMap.put(name, perf); + } + perf.count += CastUtil.cint(countLv.get(i)); + perf.elapsed += CastUtil.clong(elapsedLv.get(i)); + perf.error += CastUtil.cint(errorLv.get(i)); + } + } + } catch (Throwable th) { + th.printStackTrace(); + } finally { + TcpProxy.putTcpProxy(tcp); + } + } + MapPack m = null; + if (valueMap.size() > 0) { + m = new MapPack(); + ListValue nameLv = m.newList("name"); + ListValue countLv = m.newList("count"); + ListValue elapsedLv = m.newList("elapsed"); + ListValue errorLv = m.newList("error"); + Iterator itrr = valueMap.keySet().iterator(); + while (itrr.hasNext()) { + String name = itrr.next(); + PerfStat perf = valueMap.get(name); + nameLv.add(name); + countLv.add(perf.count); + elapsedLv.add(perf.elapsed); + errorLv.add(perf.error); + } + long time = TimeUtil.getCurrentTime(); + m.put("time", time); + } + return m; + } + + public static class PerfStat { + public int count; + public int error; + public long elapsed; + + public void add(PerfStat o) { + this.count += o.count; + this.error += o.error; + this.elapsed += o.elapsed; + } + } +} diff --git a/scouter.client/src/scouter/client/group/view/ServiceGroupGroupView.java b/scouter.client/src/scouter/client/group/view/ServiceGroupTPSGroupView.java similarity index 85% rename from scouter.client/src/scouter/client/group/view/ServiceGroupGroupView.java rename to scouter.client/src/scouter/client/group/view/ServiceGroupTPSGroupView.java index 6fb1ce20b..3e96802db 100644 --- a/scouter.client/src/scouter/client/group/view/ServiceGroupGroupView.java +++ b/scouter.client/src/scouter/client/group/view/ServiceGroupTPSGroupView.java @@ -1,136 +1,123 @@ -/* +/* * Copyright 2015 the original author or authors. - * @https://github.com/scouter-project/scouter - * - * 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 scouter.client.group.view; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IViewSite; -import org.eclipse.ui.PartInitException; - -import scouter.client.net.TcpProxy; -import scouter.client.util.TimeUtil; -import scouter.client.util.ScouterUtil; -import scouter.client.views.ServiceGroupCommonView; -import scouter.lang.pack.MapPack; -import scouter.lang.value.ListValue; -import scouter.net.RequestCmd; -import scouter.util.CastUtil; - -public class ServiceGroupGroupView extends ServiceGroupCommonView { - - public final static String ID = ServiceGroupGroupView.class.getName(); - - String grpName; - private Map serverObjMap = new HashMap(); - - public void init(IViewSite site) throws PartInitException { - super.init(site); - String secId = site.getSecondaryId(); - grpName = secId; - } - - public void createPartControl(Composite parent) { - this.setPartName("Service[Throughput] - " + grpName); - super.createPartControl(parent); - } - - @Override - public MapPack fetch() { - ScouterUtil.collectGroupObjcts(grpName, serverObjMap); - HashMap valueMap = new HashMap(); - Iterator itr = serverObjMap.keySet().iterator(); - while (itr.hasNext()) { - int serverId = itr.next(); - TcpProxy tcp = TcpProxy.getTcpProxy(serverId); - try { - MapPack param = new MapPack(); - param.put("objHash", serverObjMap.get(serverId)); - MapPack p = (MapPack) tcp.getSingle(RequestCmd.REALTIME_SERVICE_GROUP, param); - if (p != null) { - ListValue nameLv = p.getList("name"); - ListValue countLv = p.getList("count"); - ListValue elapsedLv = p.getList("elapsed"); - ListValue errorLv = p.getList("error"); - for (int i = 0, max = (nameLv == null ? 0 : nameLv.size()) ; i < max; i++) { - String name = nameLv.getString(i); - PerfStat perf = valueMap.get(name); - if (perf == null) { - perf = new PerfStat(); - valueMap.put(name, perf); - } - perf.count += CastUtil.cint(countLv.get(i)); - perf.elapsed += CastUtil.clong(elapsedLv.get(i)); - perf.error += CastUtil.cint(errorLv.get(i)); - } - } - } catch (Throwable th) { - th.printStackTrace(); - } finally { - TcpProxy.putTcpProxy(tcp); - } - } - MapPack m = null; - if (valueMap.size() > 0) { - m = new MapPack(); - ListValue nameLv = m.newList("name"); - ListValue countLv = m.newList("count"); - ListValue elapsedLv = m.newList("elapsed"); - ListValue errorLv = m.newList("error"); - Iterator itrr = valueMap.keySet().iterator(); - while (itrr.hasNext()) { - String name = itrr.next(); - PerfStat perf = valueMap.get(name); - nameLv.add(name); - countLv.add(perf.count); - elapsedLv.add(perf.elapsed); - errorLv.add(perf.error); - } - long time = TimeUtil.getCurrentTime(); - m.put("time", time); - fiveMinMap.put(time, m); - } - return m; - } - - public static class PerfStat { - public int count; - public int error; - public long elapsed; - - public void add(PerfStat o) { - this.count += o.count; - this.error += o.error; - this.elapsed += o.elapsed; - } - } - - @Override - public void setTitleName(MODE mode) { - switch (mode) { - case THROUGHPUT: - this.setPartName("Service[Throughput] - " + grpName); - break; - case ELASPED: - this.setPartName("Service[Elapsed Time] - " + grpName); - break; - } - } -} + * @https://github.com/scouter-project/scouter + * + * 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 scouter.client.group.view; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IViewSite; +import org.eclipse.ui.PartInitException; + +import scouter.client.net.TcpProxy; +import scouter.client.util.TimeUtil; +import scouter.client.util.ScouterUtil; +import scouter.client.views.AbstractServiceGroupTPSView; +import scouter.lang.pack.MapPack; +import scouter.lang.value.ListValue; +import scouter.net.RequestCmd; +import scouter.util.CastUtil; + +public class ServiceGroupTPSGroupView extends AbstractServiceGroupTPSView { + + public final static String ID = ServiceGroupTPSGroupView.class.getName(); + + String grpName; + private Map serverObjMap = new HashMap(); + + public void init(IViewSite site) throws PartInitException { + super.init(site); + String secId = site.getSecondaryId(); + grpName = secId; + } + + public void createPartControl(Composite parent) { + this.setPartName("Service[Throughput] - " + grpName); + super.createPartControl(parent); + } + + @Override + public MapPack fetch() { + ScouterUtil.collectGroupObjcts(grpName, serverObjMap); + HashMap valueMap = new HashMap(); + Iterator itr = serverObjMap.keySet().iterator(); + while (itr.hasNext()) { + int serverId = itr.next(); + TcpProxy tcp = TcpProxy.getTcpProxy(serverId); + try { + MapPack param = new MapPack(); + param.put("objHash", serverObjMap.get(serverId)); + MapPack p = (MapPack) tcp.getSingle(RequestCmd.REALTIME_SERVICE_GROUP, param); + if (p != null) { + ListValue nameLv = p.getList("name"); + ListValue countLv = p.getList("count"); + ListValue elapsedLv = p.getList("elapsed"); + ListValue errorLv = p.getList("error"); + for (int i = 0, max = (nameLv == null ? 0 : nameLv.size()) ; i < max; i++) { + String name = nameLv.getString(i); + PerfStat perf = valueMap.get(name); + if (perf == null) { + perf = new PerfStat(); + valueMap.put(name, perf); + } + perf.count += CastUtil.cint(countLv.get(i)); + perf.elapsed += CastUtil.clong(elapsedLv.get(i)); + perf.error += CastUtil.cint(errorLv.get(i)); + } + } + } catch (Throwable th) { + th.printStackTrace(); + } finally { + TcpProxy.putTcpProxy(tcp); + } + } + MapPack m = null; + if (valueMap.size() > 0) { + m = new MapPack(); + ListValue nameLv = m.newList("name"); + ListValue countLv = m.newList("count"); + ListValue elapsedLv = m.newList("elapsed"); + ListValue errorLv = m.newList("error"); + Iterator itrr = valueMap.keySet().iterator(); + while (itrr.hasNext()) { + String name = itrr.next(); + PerfStat perf = valueMap.get(name); + nameLv.add(name); + countLv.add(perf.count); + elapsedLv.add(perf.elapsed); + errorLv.add(perf.error); + } + long time = TimeUtil.getCurrentTime(); + m.put("time", time); + } + return m; + } + + public static class PerfStat { + public int count; + public int error; + public long elapsed; + + public void add(PerfStat o) { + this.count += o.count; + this.error += o.error; + this.elapsed += o.elapsed; + } + } +} diff --git a/scouter.client/src/scouter/client/net/ClientTCP.java b/scouter.client/src/scouter/client/net/ClientTCP.java index e3bc7245f..20d470072 100644 --- a/scouter.client/src/scouter/client/net/ClientTCP.java +++ b/scouter.client/src/scouter/client/net/ClientTCP.java @@ -60,8 +60,8 @@ public void open(int serverId) { //*************// if (server.isConnected() == false) { System.out.println("Success to connect " + server.getIp() + ":" + server.getPort()); - server.setConnected(true); } + server.setConnected(true); } catch (Throwable t) { System.out.println(t.getMessage()); close(); diff --git a/scouter.client/src/scouter/client/util/MenuUtil.java b/scouter.client/src/scouter/client/util/MenuUtil.java index 8eb309837..796696523 100644 --- a/scouter.client/src/scouter/client/util/MenuUtil.java +++ b/scouter.client/src/scouter/client/util/MenuUtil.java @@ -41,7 +41,8 @@ import scouter.client.actions.OpenActiveServiceListAction; import scouter.client.actions.OpenActiveSpeedAction; import scouter.client.actions.OpenEQViewAction; -import scouter.client.actions.OpenServiceGroupAction; +import scouter.client.actions.OpenServiceGroupElapsedAction; +import scouter.client.actions.OpenServiceGroupTPSAction; import scouter.client.actions.SetColorAction; import scouter.client.configuration.actions.DefineObjectTypeAction; import scouter.client.configuration.actions.OpenAgentConfigureAction; @@ -69,6 +70,7 @@ import scouter.client.counter.actions.OpenPastTimeAllAction; import scouter.client.counter.actions.OpenPastTimeTotalAction; import scouter.client.counter.actions.OpenPastTimeViewAction; +import scouter.client.counter.actions.OpenRTPairAllAction; import scouter.client.counter.actions.OpenRealTimeAllAction; import scouter.client.counter.actions.OpenRealTimeMultiAction; import scouter.client.counter.actions.OpenRealTimeStackAction; @@ -206,9 +208,7 @@ public static void createMenu(IWorkbenchWindow window, IToolBarManager man, } public static HashMap getCounterActionList(IWorkbenchWindow window, CounterEngine counterEngine, int serverId){ - HashMap actions = new HashMap(); - ArrayList objTypeAndCounter = counterEngine.getAllCounterList(); for (int inx = 0; inx < objTypeAndCounter.size(); inx++) { String[] splitedKey = objTypeAndCounter.get(inx).split(":"); @@ -220,77 +220,6 @@ public static HashMap getCounterActionList(IWorkbenchWindow wind new OpenRealTimeAllAction(window, label, objType, counterName, Images .getCounterImage(objType, counterName, serverId), serverId)); } - - ArrayList objTypeList = counterEngine.getObjTypeListWithDisplay(CounterConstants.TOTAL_ACTIVE_SPEED); - for (int inx = 0; inx < objTypeList.size(); inx++) { - String[] splitedKey = objTypeList.get(inx).split(":"); - String objTypeDisplay = splitedKey[0]; - String objType = splitedKey[1]; - actions.put(objType + ":" + CounterConstants.TOTAL_ACTIVE_SPEED, new OpenActiveSpeedAction(window, - objTypeDisplay, objType, Images.getObjectIcon(objType, true, serverId), serverId)); - } - - objTypeList = counterEngine.getObjTypeListWithDisplay(CounterConstants.ACTIVE_EQ); - for (int inx = 0; inx < objTypeList.size(); inx++) { - String[] splitedKey = objTypeList.get(inx).split(":"); - String objType = splitedKey[1]; - actions.put(objType + ":" + CounterConstants.ACTIVE_EQ, new OpenEQViewAction(window, serverId, objType)); - } - - objTypeList = counterEngine.getObjTypeListWithDisplay(CounterConstants.ACTIVE_THREAD_LIST); - for (int inx = 0; inx < objTypeList.size(); inx++) { - String[] splitedKey = objTypeList.get(inx).split(":"); - String objTypeDisplay = splitedKey[0]; - String objType = splitedKey[1]; - actions.put(objType + ":" + CounterConstants.ACTIVE_THREAD_LIST, new OpenActiveServiceListAction(window, - objTypeDisplay, objType, Images.getObjectIcon(objType, true, serverId), serverId)); - } - - objTypeList = counterEngine.getObjTypeListWithDisplay(CounterConstants.TRANX_REALTIME); - for (int inx = 0; inx < objTypeList.size(); inx++) { - String[] splitedKey = objTypeList.get(inx).split(":"); - String objType = splitedKey[1]; - actions.put( - objType + ":" + CounterConstants.TRANX_REALTIME, - new OpenXLogRealTimeAction(window, MenuStr.XLOG, objType, Images.star, serverId)); - } - - objTypeList = counterEngine.getObjTypeListWithDisplay(CounterConstants.TODAY_SERVICE_COUNT); - for (int inx = 0; inx < objTypeList.size(); inx++) { - String[] splitedKey = objTypeList.get(inx).split(":"); - String objType = splitedKey[1]; - actions.put( - objType + ":" + CounterConstants.TODAY_SERVICE_COUNT, - new OpenTodayServiceCountAction(window, MenuStr.SERVICE_COUNT, objType, CounterConstants.WAS_SERVICE_COUNT, Images.bar, serverId)); - } - - objTypeList = counterEngine.getObjTypeListWithDisplay(CounterConstants.SERVICE_GROUP); - for (int inx = 0; inx < objTypeList.size(); inx++) { - String[] splitedKey = objTypeList.get(inx).split(":"); - String objType = splitedKey[1]; - actions.put( - objType + ":" + CounterConstants.SERVICE_GROUP, - new OpenServiceGroupAction(window, serverId, objType)); - } - - objTypeList = counterEngine.getObjTypeListWithDisplay(CounterConstants.UNIQUE_VISITOR); - for (int inx = 0; inx < objTypeList.size(); inx++) { - String[] splitedKey = objTypeList.get(inx).split(":"); - String objType = splitedKey[1]; - actions.put( - objType + ":" + CounterConstants.UNIQUE_VISITOR, - new OpenUniqueTotalVisitorAction(window, serverId, objType)); - } - - objTypeList = counterEngine.getObjTypeListWithDisplay(CounterConstants.SERVICE_SUMMARY); - for (int inx = 0; inx < objTypeList.size(); inx++) { - String[] splitedKey = objTypeList.get(inx).split(":"); - String objType = splitedKey[1]; - actions.put( - objType + ":" + CounterConstants.SERVICE_SUMMARY, - new OpenTypeSummaryAction(window, serverId, objType)); - } - return actions; } @@ -341,28 +270,6 @@ public static HashMap getPastCounterActionList(IWorkbenchWindow new OpenPastLongDateTotalAction(window, label, objType, counterName, Images.getCounterImage(objType, counterName, serverId), curdate, curdate, serverId)); } - - ArrayList objTypeList = counterEngine.getObjTypeListWithDisplay(CounterConstants.TRANX_REALTIME); - for (int inx = 0; inx < objTypeList.size(); inx++) { - String[] splitedKey = objTypeList.get(inx).split(":"); - String objTypeDisplay = splitedKey[0]; - String objType = splitedKey[1]; - actions.put( - objType + ":" + CounterConstants.TRANX_REALTIME, - new OpenXLogLoadTimeAction(window, objTypeDisplay, objType, Images.getObjectIcon( - objType, true, serverId), serverId, st, et)); - } - - objTypeList = counterEngine.getObjTypeListWithDisplay(CounterConstants.TODAY_SERVICE_COUNT); - for (int inx = 0; inx < objTypeList.size(); inx++) { - String[] splitedKey = objTypeList.get(inx).split(":"); - String objTypeDisplay = splitedKey[0]; - String objType = splitedKey[1]; - actions.put( - objType + ":" + CounterConstants.TODAY_SERVICE_COUNT, - new OpenDailyServiceCountAction(window, objTypeDisplay, objType, CounterConstants.WAS_SERVICE_COUNT, Images.getObjectIcon( - objType, true, serverId), serverId, curdate)); - } return actions; } @@ -580,4 +487,32 @@ public void menuAboutToShow(IMenuManager mgr) { Menu menu = mgr.createContextMenu(control); control.setMenu(menu); } + + public static void addObjTypeSpecialMenu(IWorkbenchWindow win, IMenuManager mgr, int serverId, String objType, CounterEngine counterEngine) { + if (counterEngine.isChildOf(objType, CounterConstants.FAMILY_JAVAEE)) { + mgr.add(new Separator()); + mgr.add(new OpenRTPairAllAction(win, "Heap Memory", serverId, objType, CounterConstants.JAVA_HEAP_TOT_USAGE)); + mgr.add(new OpenEQViewAction(win, serverId, objType)); + mgr.add(new OpenActiveServiceListAction(win, objType, Images.thread, serverId)); + mgr.add(new OpenActiveSpeedAction(win,objType, Images.TYPE_ACTSPEED, serverId)); + mgr.add(new OpenXLogRealTimeAction(win, MenuStr.XLOG, objType, Images.star, serverId)); + mgr.add(new OpenTodayServiceCountAction(win, MenuStr.SERVICE_COUNT, objType, CounterConstants.WAS_SERVICE_COUNT, Images.bar, serverId)); + MenuManager serviceGroupMgr = new MenuManager("Serivce Group", ImageUtil.getImageDescriptor(Images.sum), "scouter.menu.id.javee.servicegroup"); + mgr.add(serviceGroupMgr); + serviceGroupMgr.add(new OpenServiceGroupTPSAction(win, serverId, objType)); + serviceGroupMgr.add(new OpenServiceGroupElapsedAction(win, serverId, objType)); + mgr.add(new OpenUniqueTotalVisitorAction(win, serverId, objType)); + mgr.add(new OpenTypeSummaryAction(win, serverId, objType)); + } + } + + public static void addPastObjTypeSpecialMenu(IWorkbenchWindow win, IMenuManager mgr, int serverId, String objType, CounterEngine counterEngine, String date) { + long st = DateUtil.yyyymmdd(date); + long et = st + DateUtil.MILLIS_PER_FIVE_MINUTE; + if (counterEngine.isChildOf(objType, CounterConstants.FAMILY_JAVAEE)) { + mgr.add(new Separator()); + mgr.add(new OpenXLogLoadTimeAction(win, objType, Images.transrealtime, serverId, st, et)); + mgr.add(new OpenDailyServiceCountAction(win, objType, CounterConstants.WAS_SERVICE_COUNT, Images.TYPE_SERVICE_COUNT, serverId, date)); + } + } } diff --git a/scouter.client/src/scouter/client/util/ScouterUtil.java b/scouter.client/src/scouter/client/util/ScouterUtil.java index dea5e33cf..834cea69d 100644 --- a/scouter.client/src/scouter/client/util/ScouterUtil.java +++ b/scouter.client/src/scouter/client/util/ScouterUtil.java @@ -41,22 +41,14 @@ import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.events.MouseListener; import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.PaletteData; import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.IViewReference; -import org.eclipse.ui.part.ViewPart; import scouter.client.Images; import scouter.client.constants.MenuStr; import scouter.client.group.GroupManager; import scouter.client.model.AgentModelThread; import scouter.client.model.AgentObject; -import scouter.client.model.DetachedManager; import scouter.client.net.INetReader; import scouter.client.net.TcpProxy; import scouter.io.DataInputX; @@ -268,34 +260,34 @@ public void mouseUp(MouseEvent e) { } public void mouseDown(MouseEvent e) { - Image image = new Image(e.display, 1, 10); - GC gc = new GC((FigureCanvas) e.widget); - gc.copyArea(image, e.x, e.y > 5 ? e.y - 5 : 0); - ImageData imageData = image.getImageData(); - PaletteData palette = imageData.palette; - int point = 5; - int offset = 0; - while (point >= 0 && point < 10) { - int pixelValue = imageData.getPixel(0, point); - RGB rgb = palette.getRGB(pixelValue); - if (ColorUtil.getInstance().TOTAL_CHART_COLOR.getRGB().equals(rgb)) { - double time = xyGraph.primaryXAxis.getPositionValue(e.x, false); - Trace t = xyGraph.getPlotArea().getTraceList().get(0); - if (t == null) { - return; - } - double d = getNearestValue(t.getDataProvider(), time); - String value = FormatUtil.print(d, "#,###.##"); - toolTip.setText("value : " + value); - toolTip.show(new Point(e.x, e.y)); - break; + double x = xyGraph.primaryXAxis.getPositionValue(e.x, false); + double y = xyGraph.primaryYAxis.getPositionValue(e.y, false); + if (x < 0 || y < 0) { + return; + } + double minDistance = 30.0d; + long time = 0; + double value = 0; + Trace t = xyGraph.getPlotArea().getTraceList().get(0); + if (t == null) { + return; + } + ISample s = getNearestPoint(t.getDataProvider(), x); + if (s != null) { + int x2 = xyGraph.primaryXAxis.getValuePosition(s.getXValue(), false); + int y2 = xyGraph.primaryYAxis.getValuePosition(s.getYValue(), false); + double distance = ScouterUtil.getPointDistance(e.x, e.y, x2, y2); + if (minDistance > distance) { + minDistance = distance; + time = (long) s.getXValue(); + value = s.getYValue(); } - offset = offset >= 0 ? offset + 1 : offset - 1; - offset *= -1; - point += offset; } - gc.dispose(); - image.dispose(); + if (t != null) { + toolTip.setText("Time : " + DateUtil.format(time, "HH:mm:ss") + + "\nValue : " + FormatUtil.print(value, "#,###.##")); + toolTip.show(new Point(e.x, e.y)); + } } public void mouseDoubleClick(MouseEvent e) { @@ -523,6 +515,46 @@ public static double getNearestValue(IDataProvider provider, double time) { } } } + + public static ISample getNearestPoint(IDataProvider provider, double time) { + int high = provider.getSize() - 1; + int low = 0; + while (high >= low) { + int mid = (high + low) / 2; + ISample s = provider.getSample(mid); + double x = s.getXValue(); + if (x == time) { + return s; + } else { + if (x > time) { + high = mid; + } else { + low = mid; + } + if ((high - low) <= 1) { + ISample highSample = provider.getSample(high); + ISample lowSample = provider.getSample(low); + if (highSample == null && lowSample == null) { + return null; + } + if (highSample == null) { + return lowSample; + } + if (lowSample == null) { + return highSample; + } + double highGap = highSample.getXValue() - time; + double lowGqp = time - lowSample.getXValue(); + if (highGap < lowGqp) { + return highSample; + } else { + return lowSample; + } + } + } + } + return null; + } public static String humanReadableByteCount(long bytes, boolean si) { int unit = 1024; @@ -547,4 +579,8 @@ public static void addHorizontalRangeListener(PlotArea plotArea, PropertyChangeL plotArea.enableZoom(withZoom); plotArea.addPropertyChangeListener("horizontal_range", listener); } + + public static double getPointDistance(double x1, double y1, double x2, double y2) { + return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)); + } } diff --git a/scouter.client/src/scouter/client/views/AbstractServiceGroupElapsedView.java b/scouter.client/src/scouter/client/views/AbstractServiceGroupElapsedView.java new file mode 100644 index 000000000..1c4c658af --- /dev/null +++ b/scouter.client/src/scouter/client/views/AbstractServiceGroupElapsedView.java @@ -0,0 +1,327 @@ +/* + * Copyright 2015 the original author or authors. + * @https://github.com/scouter-project/scouter + * + * 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 scouter.client.views; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.csstudio.swt.xygraph.dataprovider.CircularBufferDataProvider; +import org.csstudio.swt.xygraph.dataprovider.ISample; +import org.csstudio.swt.xygraph.dataprovider.Sample; +import org.csstudio.swt.xygraph.figures.Trace; +import org.csstudio.swt.xygraph.figures.Trace.PointStyle; +import org.csstudio.swt.xygraph.figures.Trace.TraceType; +import org.csstudio.swt.xygraph.figures.XYGraph; +import org.csstudio.swt.xygraph.linearscale.Range; +import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.jface.window.DefaultToolTip; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.ControlListener; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.part.ViewPart; + +import scouter.client.Images; +import scouter.client.listeners.RangeMouseListener; +import scouter.client.model.RefreshThread; +import scouter.client.model.RefreshThread.Refreshable; +import scouter.client.model.ServiceGroupColorManager; +import scouter.client.preferences.PManager; +import scouter.client.preferences.PreferenceConstants; +import scouter.client.util.ChartUtil; +import scouter.client.util.ColorUtil; +import scouter.client.util.ExUtil; +import scouter.client.util.ScouterUtil; +import scouter.client.util.TimeUtil; +import scouter.client.util.UIUtil; +import scouter.lang.pack.MapPack; +import scouter.lang.value.ListValue; +import scouter.util.CastUtil; +import scouter.util.DateUtil; +import scouter.util.FormatUtil; + +public abstract class AbstractServiceGroupElapsedView extends ViewPart implements Refreshable { + + public final static String ID = AbstractServiceGroupElapsedView.class.getName(); + + private final static int BUFFER_SIZE = 200; + protected RefreshThread thread; + + protected XYGraph xyGraph; + protected FigureCanvas canvas; + + protected Map traces = new HashMap(); + Trace nearestTrace = null; + + private int manualRangeCount; + private double manualY; + + public void createPartControl(Composite parent) { + parent.setLayout(UIUtil.formLayout(0, 0)); + canvas = new FigureCanvas(parent); + canvas.setScrollBarVisibility(FigureCanvas.NEVER); + canvas.setLayoutData(UIUtil.formData(0, 0, 0, 0, 100, 0, 100, 0)); + canvas.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE)); + canvas.addControlListener(new ControlListener() { + boolean lock = false; + public void controlResized(ControlEvent e) { + org.eclipse.swt.graphics.Rectangle r = canvas.getClientArea(); + if (!lock) { + lock = true; + xyGraph.setSize(r.width, r.height); + lock = false; + } + } + public void controlMoved(ControlEvent e) { + } + }); + final DefaultToolTip toolTip = new DefaultToolTip(canvas, DefaultToolTip.RECREATE, true); + toolTip.setFont(new Font(null, "Arial", 10, SWT.BOLD)); + toolTip.setBackgroundColor(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + canvas.addMouseListener(new MouseListener() { + public void mouseUp(MouseEvent e) { + if (nearestTrace != null) { + nearestTrace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH)); + nearestTrace = null; + } + toolTip.hide(); + } + + public void mouseDown(MouseEvent e) { + double x = xyGraph.primaryXAxis.getPositionValue(e.x, false); + double y = xyGraph.primaryYAxis.getPositionValue(e.y, false); + if (x < 0 || y < 0) { + return; + } + double minDistance = 30.0d; + long time = 0; + double value = 0; + for (Trace t : traces.values()) { + ISample s = ScouterUtil.getNearestPoint(t.getDataProvider(), x); + if (s != null) { + int x2 = xyGraph.primaryXAxis.getValuePosition(s.getXValue(), false); + int y2 = xyGraph.primaryYAxis.getValuePosition(s.getYValue(), false); + double distance = ScouterUtil.getPointDistance(e.x, e.y, x2, y2); + if (minDistance > distance) { + minDistance = distance; + nearestTrace = t; + time = (long) s.getXValue(); + value = s.getYValue(); + } + } + } + if (nearestTrace != null) { + int width = PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH); + nearestTrace.setLineWidth(width + 2); + toolTip.setText(nearestTrace.getName() + + "\nTime : " + DateUtil.format(time, "HH:mm:ss") + + "\nValue : " + FormatUtil.print(value, "#,###.##")); + toolTip.show(new Point(e.x, e.y)); + } + } + public void mouseDoubleClick(MouseEvent e) {} + }); + canvas.addKeyListener(new KeyListener() { + public void keyReleased(KeyEvent e) { + } + + public void keyPressed(KeyEvent e) { + switch (e.keyCode) { + case 16777217:// UP Key + double max = xyGraph.primaryYAxis.getRange().getUpper(); + if (max > 10000) { + manualY = max + 1000; + } else if (max > 1000) { + manualY = max + 100; + } else if (max > 100) { + manualY = max + 10; + } else if (max == 3) { + manualY = 5; + } else { + manualY = max + 5; + } + manualRangeCount = 5; + xyGraph.primaryYAxis.setRange(0, manualY); + break; + case 16777218: // DOWN Key + max = xyGraph.primaryYAxis.getRange().getUpper(); + if (max > 10000) { + manualY = max - 1000; + } else if (max > 1000) { + manualY =max - 100; + } else if (max > 100) { + manualY =max - 10; + } else { + manualY = (max - 5) > 3 ? max -5 : 3; + } + manualRangeCount = 5; + xyGraph.primaryYAxis.setRange(0, manualY); + break; + } + } + }); + xyGraph = new XYGraph(); + xyGraph.setShowLegend(true); + xyGraph.setShowTitle(false); + canvas.setContents(xyGraph); + xyGraph.primaryXAxis.setDateEnabled(true); + xyGraph.primaryXAxis.setShowMajorGrid(true); + xyGraph.primaryYAxis.setAutoScale(true); + xyGraph.primaryYAxis.setShowMajorGrid(true); + xyGraph.primaryXAxis.setTitle(""); + xyGraph.primaryYAxis.setTitle(""); + + xyGraph.primaryYAxis.addMouseListener(new RangeMouseListener(getViewSite().getShell(), xyGraph.primaryYAxis)); + thread = new RefreshThread(this, 2000); + thread.start(); + } + + public void setFocus() {} + + @Override + public void dispose() { + super.dispose(); + if (this.thread != null) { + this.thread.shutdown(); + } + } + + boolean stopRefresh = false; + + public void refresh() { + if (stopRefresh) { + return; + } + MapPack m = fetch(); + if (m == null) { + ExUtil.exec(canvas, new Runnable() { + public void run() { + setTitleImage(Images.inactive); + long now = TimeUtil.getCurrentTime(); + xyGraph.primaryXAxis.setRange(now - DateUtil.MILLIS_PER_FIVE_MINUTE, now + 1); + } + }); + return; + } + removeDeadGroup(m); + processElapsedData(m); + } + + public abstract MapPack fetch(); + + private void removeDeadGroup(MapPack m) { + ListValue nameLv = m.getList("name"); + + ArrayList grpSet = new ArrayList(); + Iterator enu = traces.keySet().iterator(); + while(enu.hasNext()){ + grpSet.add(enu.next()); + } + for (int i = 0; i < nameLv.size(); i++) { + String name = nameLv.getString(i); + grpSet.remove(name); + } + for (String dead : grpSet) { + final Trace t = traces.get(dead); + if (t == null) continue; + ExUtil.exec(canvas, new Runnable() { + public void run() { + xyGraph.removeTrace(t); + } + }); + traces.remove(dead); + } + } + + private void processElapsedData(final MapPack m) { + final ListValue nameLv = m.getList("name"); + final ListValue elapsedLv = m.getList("elapsed"); + ExUtil.exec(canvas, new Runnable() { + public void run() { + setTitleImage(Images.active); + long now = m.getLong("time"); + long stime = now - DateUtil.MILLIS_PER_FIVE_MINUTE; + xyGraph.primaryXAxis.setRange(stime, now + 1); + for (int i = 0; i < nameLv.size(); i++) { + String name = nameLv.getString(i); + double value = CastUtil.cdouble(elapsedLv.get(i)) / 30.0d; + CircularBufferDataProvider provider = (CircularBufferDataProvider) getTrace(name).getDataProvider(); + provider.addSample(new Sample(now, value)); + } + xyGraph.primaryYAxis.setRange(0, getMaxValue()); + } + }); + } + + private Trace getTrace(String name) { + Trace trace = traces.get(name); + if (trace == null) { + CircularBufferDataProvider provider = new CircularBufferDataProvider(true); + provider.setBufferSize(BUFFER_SIZE); + trace = new Trace(name, xyGraph.primaryXAxis, xyGraph.primaryYAxis, provider); + trace.setPointStyle(PointStyle.NONE); + trace.getXAxis().setFormatPattern("HH:mm:ss"); + trace.getYAxis().setFormatPattern("#,##0"); + trace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH)); + trace.setTraceType(TraceType.SOLID_LINE); + trace.setTraceColor(ServiceGroupColorManager.getInstance().assignColor(name)); + xyGraph.addTrace(trace); + traces.put(name, trace); + } + return trace; + } + + private double getMaxValue() { + Range xRange = xyGraph.primaryXAxis.getRange(); + double lower = xRange.getLower(); + double upper = xRange.getUpper(); + if (manualRangeCount > 0 && manualY > 0) { + manualRangeCount--; + return manualY; + } + double max = 0.0; + Iterator itr = traces.keySet().iterator(); + while (itr.hasNext()) { + String name = itr.next(); + CircularBufferDataProvider data = (CircularBufferDataProvider) traces.get(name).getDataProvider(); + if (data != null) { + for (int inx = 0; inx < data.getSize(); inx++) { + Sample sample = (Sample) data.getSample(inx); + double x = sample.getXValue(); + if(x < lower || x > upper) { + continue; + } + double y = sample.getYValue(); + if (y > max) { + max = y; + } + } + } + } + return ChartUtil.getGroupMaxValue(max); + } +} diff --git a/scouter.client/src/scouter/client/views/ServiceGroupCommonView.java b/scouter.client/src/scouter/client/views/AbstractServiceGroupTPSView.java similarity index 65% rename from scouter.client/src/scouter/client/views/ServiceGroupCommonView.java rename to scouter.client/src/scouter/client/views/AbstractServiceGroupTPSView.java index e1620abe9..fa33b433e 100644 --- a/scouter.client/src/scouter/client/views/ServiceGroupCommonView.java +++ b/scouter.client/src/scouter/client/views/AbstractServiceGroupTPSView.java @@ -1,518 +1,353 @@ -/* +/* * Copyright 2015 the original author or authors. - * @https://github.com/scouter-project/scouter - * - * 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 scouter.client.views; - -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.csstudio.swt.xygraph.dataprovider.CircularBufferDataProvider; -import org.csstudio.swt.xygraph.dataprovider.Sample; -import org.csstudio.swt.xygraph.figures.Trace; -import org.csstudio.swt.xygraph.figures.Trace.PointStyle; -import org.csstudio.swt.xygraph.figures.Trace.TraceType; -import org.csstudio.swt.xygraph.figures.XYGraph; -import org.csstudio.swt.xygraph.linearscale.Range; -import org.eclipse.draw2d.FigureCanvas; -import org.eclipse.jface.action.Action; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.window.DefaultToolTip; -import org.eclipse.swt.SWT; -import org.eclipse.swt.events.ControlEvent; -import org.eclipse.swt.events.ControlListener; -import org.eclipse.swt.events.KeyEvent; -import org.eclipse.swt.events.KeyListener; -import org.eclipse.swt.events.MouseEvent; -import org.eclipse.swt.events.MouseListener; -import org.eclipse.swt.graphics.Font; -import org.eclipse.swt.graphics.GC; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.PaletteData; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.graphics.RGB; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.part.ViewPart; - -import scouter.client.Activator; -import scouter.client.Images; -import scouter.client.model.RefreshThread; -import scouter.client.model.ServiceGroupColorManager; -import scouter.client.model.RefreshThread.Refreshable; -import scouter.client.preferences.PManager; -import scouter.client.preferences.PreferenceConstants; -import scouter.client.util.ChartUtil; -import scouter.client.util.ColorUtil; -import scouter.client.util.ExUtil; -import scouter.client.util.MenuUtil; -import scouter.client.util.TimeUtil; -import scouter.client.util.UIUtil; -import scouter.lang.pack.MapPack; -import scouter.lang.value.ListValue; -import scouter.util.CastUtil; -import scouter.util.DateUtil; -import scouter.util.LinkedMap; -import scouter.util.LongEnumer; -import scouter.util.LongKeyLinkedMap; - -public abstract class ServiceGroupCommonView extends ViewPart implements Refreshable { - - public final static String ID = ServiceGroupCommonView.class.getName(); - - private final static int BUFFER_SIZE = 200; - protected RefreshThread thread; - - protected XYGraph xyGraph; - protected FigureCanvas canvas; - - public MODE mode = MODE.THROUGHPUT; - - protected Map traces = new HashMap(); - protected LongKeyLinkedMap< MapPack> fiveMinMap = new LongKeyLinkedMap< MapPack>().setMax(BUFFER_SIZE); - private LinkedMap stackValueMap = new LinkedMap(); - - private int manualRangeCount; - private double manualY; - - public void createPartControl(Composite parent) { - parent.setLayout(UIUtil.formLayout(0, 0)); - canvas = new FigureCanvas(parent); - canvas.setScrollBarVisibility(FigureCanvas.NEVER); - canvas.setLayoutData(UIUtil.formData(0, 0, 0, 0, 100, 0, 100, 0)); - canvas.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE)); - canvas.addControlListener(new ControlListener() { - boolean lock = false; - public void controlResized(ControlEvent e) { - org.eclipse.swt.graphics.Rectangle r = canvas.getClientArea(); - if (!lock) { - lock = true; - xyGraph.setSize(r.width, r.height); - lock = false; - } - } - public void controlMoved(ControlEvent e) { - } - }); - final DefaultToolTip toolTip = new DefaultToolTip(canvas, DefaultToolTip.RECREATE, true); - toolTip.setFont(new Font(null, "Arial", 10, SWT.BOLD)); - toolTip.setBackgroundColor(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); - canvas.addMouseListener(new MouseListener() { - - String selectedName; - - public void mouseUp(MouseEvent e) { - if (selectedName == null) { - return; - } - Trace trace = traces.get(selectedName); - trace.setTraceColor(ServiceGroupColorManager.getInstance().assignColor(selectedName)); - toolTip.hide(); - selectedName = null; - } - public void mouseDown(MouseEvent e) { - Image image = new Image(e.display, 1, 1); - GC gc = new GC((FigureCanvas)e.widget); - gc.copyArea(image, e.x, e.y); - ImageData imageData = image.getImageData(); - PaletteData palette = imageData.palette; - int pixelValue = imageData.getPixel(0, 0); - RGB rgb = palette.getRGB(pixelValue); - selectedName = ServiceGroupColorManager.getInstance().getServiceGroup(rgb); - if (selectedName != null) { - Trace trace = traces.get(selectedName); - trace.setTraceColor(ColorUtil.getInstance().getColor("dark magenta")); - toolTip.setText(selectedName); - toolTip.show(new Point(e.x, e.y)); - } - gc.dispose(); - image.dispose(); - } - public void mouseDoubleClick(MouseEvent e) {} - }); - canvas.addKeyListener(new KeyListener() { - public void keyReleased(KeyEvent e) { - } - - public void keyPressed(KeyEvent e) { - switch (e.keyCode) { - case 16777217:// UP Key - double max = xyGraph.primaryYAxis.getRange().getUpper(); - if (max > 10000) { - manualY = max + 1000; - } else if (max > 1000) { - manualY = max + 100; - } else if (max > 100) { - manualY = max + 10; - } else if (max == 3) { - manualY = 5; - } else { - manualY = max + 5; - } - manualRangeCount = 5; - xyGraph.primaryYAxis.setRange(0, manualY); - break; - case 16777218: // DOWN Key - max = xyGraph.primaryYAxis.getRange().getUpper(); - if (max > 10000) { - manualY = max - 1000; - } else if (max > 1000) { - manualY =max - 100; - } else if (max > 100) { - manualY =max - 10; - } else { - manualY = (max - 5) > 3 ? max -5 : 3; - } - manualRangeCount = 5; - xyGraph.primaryYAxis.setRange(0, manualY); - break; - } - } - }); - IToolBarManager man = getViewSite().getActionBars().getToolBarManager(); - ArrayList menus = new ArrayList(); - menus.add(new ChangeThroughput()); - menus.add(new ChangeElasped()); - MenuUtil.createMenu(getSite().getWorkbenchWindow(), man, menus, Images.arrow_rotate); - xyGraph = new XYGraph(); - xyGraph.setShowLegend(true); - xyGraph.setShowTitle(false); - canvas.setContents(xyGraph); - xyGraph.primaryXAxis.setDateEnabled(true); - xyGraph.primaryXAxis.setShowMajorGrid(true); - xyGraph.primaryYAxis.setAutoScale(true); - xyGraph.primaryYAxis.setShowMajorGrid(true); - xyGraph.primaryXAxis.setTitle(""); - xyGraph.primaryYAxis.setTitle(""); - thread = new RefreshThread(this, 2000); - thread.start(); - } - - public void setFocus() {} - - @Override - public void dispose() { - super.dispose(); - if (this.thread != null) { - this.thread.shutdown(); - } - } - - private void changeMode(MODE mode) { - if (this.mode == mode) { - return; - } - for (Trace trace : traces.values()) { - xyGraph.removeTrace(trace); - } - traces.clear(); - manualRangeCount = 0; - this.mode = mode; - setTitleName(mode); - try { - stopRefresh = true; - applyPrevData(); - } catch (Exception e) { - e.printStackTrace(); - } finally { - stopRefresh = false; - } - } - - boolean stopRefresh = false; - - private void applyPrevData() { - final LinkedMap> tempMap = new LinkedMap>(); - LongEnumer keys = fiveMinMap.keys(); - while (keys.hasMoreElements()) { - long time = keys.nextLong(); - MapPack m = fiveMinMap.get(time); - ListValue nameLv = m.getList("name"); - ListValue countLv = m.getList("count"); - ListValue elapsedLv = m.getList("elapsed"); - switch (mode) { - case THROUGHPUT : - for (int i = 0; i < nameLv.size(); i++) { - String name = nameLv.getString(i); - double count = CastUtil.cdouble(countLv.get(i)) / 30.0d; - StackValue sv = stackValueMap.get(name); - if (sv == null) { - continue; - } - sv.actualValue = count; - sv.lastUpdateTime = time; - } - Enumeration itr = stackValueMap.keys(); - double stackValue = 0.0; - while (itr.hasMoreElements()) { - String name = itr.nextElement(); - StackValue sv = stackValueMap.get(name); - if (sv != null) { - if (tempMap.containsKey(name) == false) { - tempMap.putFirst(name, new ArrayList()); - } - if (sv.lastUpdateTime == time) { - stackValue += sv.actualValue; - List list = tempMap.get(name); - list.add(new Sample(time, stackValue)); - } - } - } - break; - case ELASPED: - for (int i = 0; i < nameLv.size(); i++) { - String name = nameLv.getString(i); - if (stackValueMap.containsKey(name) == false) { - continue; - } - double value = CastUtil.cdouble(elapsedLv.get(i)) / 30.0d; - List list = tempMap.get(name); - if (list == null) { - list = new ArrayList(); - tempMap.put(name, list); - } - list.add(new Sample(time, value)); - } - break; - } - } - - ExUtil.exec(canvas, new Runnable() { - public void run() { - Enumeration itr = tempMap.keys(); - while (itr.hasMoreElements()) { - String name = itr.nextElement(); - List list = tempMap.get(name); - CircularBufferDataProvider provider = (CircularBufferDataProvider) getTrace(name).getDataProvider(); - for (int i = 0; i < list.size(); i++) { - provider.addSample(list.get(i)); - } - } - } - }); - } - - public void refresh() { - if (stopRefresh) { - return; - } - MapPack m = fetch(); - if (m == null) { - ExUtil.exec(canvas, new Runnable() { - public void run() { - setTitleImage(Images.inactive); - long now = TimeUtil.getCurrentTime(); - xyGraph.primaryXAxis.setRange(now - DateUtil.MILLIS_PER_FIVE_MINUTE, now + 1); - } - }); - return; - } - removeDeadGroup(m); - switch (mode) { - case THROUGHPUT : - processThroughputData(m); - break; - case ELASPED: - processElapsedData(m); - break; - } - } - - public abstract void setTitleName(MODE mode); - public abstract MapPack fetch(); - - private void removeDeadGroup(MapPack m) { - ListValue nameLv = m.getList("name"); - - ArrayList grpSet = new ArrayList(); - Enumeration enu =stackValueMap.keys(); - while(enu.hasMoreElements()){ - grpSet.add(enu.nextElement()); - } - for (int i = 0; i < nameLv.size(); i++) { - String name = nameLv.getString(i); - grpSet.remove(name); - } - for (String dead : grpSet) { - stackValueMap.remove(dead); - final Trace t = traces.get(dead); - if (t == null) continue; - ExUtil.exec(canvas, new Runnable() { - public void run() { - xyGraph.removeTrace(t); - } - }); - traces.remove(dead); - } - } - - private void processThroughputData(MapPack m) { - ListValue nameLv = m.getList("name"); - ListValue countLv = m.getList("count"); - final long now = m.getLong("time"); - final long stime = now - DateUtil.MILLIS_PER_FIVE_MINUTE; - for (int i = 0; i < nameLv.size(); i++) { - String name = nameLv.getString(i); - double value = CastUtil.cdouble(countLv.get(i)) / 30.0d; - if (stackValueMap.containsKey(name)) { - StackValue sv = stackValueMap.get(name); - sv.actualValue = value; - sv.lastUpdateTime = now; - } else { - StackValue sv = new StackValue(); - sv.actualValue = value; - sv.lastUpdateTime = now; - stackValueMap.putFirst(name, sv); - } - } - Enumeration itr = stackValueMap.keys(); - final LinkedMap tempMap = new LinkedMap(); - double stackValue = 0.0; - while (itr.hasMoreElements()) { - String name = itr.nextElement(); - StackValue sv = stackValueMap.get(name); - if (sv.lastUpdateTime == now) { - stackValue += sv.actualValue; - sv.stackedValue = stackValue; - tempMap.putFirst(name, sv); - } - } - ExUtil.exec(canvas, new Runnable() { - public void run() { - setTitleImage(Images.active); - xyGraph.primaryXAxis.setRange(stime, now + 1); - Enumeration itr = tempMap.keys(); - while (itr.hasMoreElements()) { - String name = itr.nextElement(); - StackValue sv = tempMap.get(name); - CircularBufferDataProvider provider = (CircularBufferDataProvider) getTrace(name).getDataProvider(); - provider.addSample(new Sample(now, sv.stackedValue)); - } - xyGraph.primaryYAxis.setRange(0, getMaxValue()); - } - }); - } - - private void processElapsedData(final MapPack m) { - final ListValue nameLv = m.getList("name"); - final ListValue elapsedLv = m.getList("elapsed"); - ExUtil.exec(canvas, new Runnable() { - public void run() { - setTitleImage(Images.active); - long now = m.getLong("time"); - long stime = now - DateUtil.MILLIS_PER_FIVE_MINUTE; - xyGraph.primaryXAxis.setRange(stime, now + 1); - for (int i = 0; i < nameLv.size(); i++) { - String name = nameLv.getString(i); - double value = CastUtil.cdouble(elapsedLv.get(i)) / 30.0d; - CircularBufferDataProvider provider = (CircularBufferDataProvider) getTrace(name).getDataProvider(); - provider.addSample(new Sample(now, value)); - } - xyGraph.primaryYAxis.setRange(0, getMaxValue()); - } - }); - } - - private Trace getTrace(String name) { - Trace trace = traces.get(name); - if (trace == null) { - CircularBufferDataProvider provider = new CircularBufferDataProvider(true); - provider.setBufferSize(BUFFER_SIZE); - trace = new Trace(name, xyGraph.primaryXAxis, xyGraph.primaryYAxis, provider); - trace.setPointStyle(PointStyle.NONE); - trace.getXAxis().setFormatPattern("HH:mm:ss"); - trace.getYAxis().setFormatPattern("#,##0"); - if (this.mode == MODE.ELASPED) { - trace.setLineWidth(PManager.getInstance().getInt(PreferenceConstants.P_CHART_LINE_WIDTH)); - trace.setTraceType(TraceType.SOLID_LINE); - } else if (this.mode == MODE.THROUGHPUT) { - trace.setTraceType(TraceType.AREA); - trace.setAreaAlpha(255); - } - trace.setTraceColor(ServiceGroupColorManager.getInstance().assignColor(name)); - xyGraph.addTrace(trace); - traces.put(name, trace); - } - return trace; - } - - private double getMaxValue() { - Range xRange = xyGraph.primaryXAxis.getRange(); - double lower = xRange.getLower(); - double upper = xRange.getUpper(); - if (manualRangeCount > 0 && manualY > 0) { - manualRangeCount--; - return manualY; - } - double max = 0.0; - Iterator itr = traces.keySet().iterator(); - while (itr.hasNext()) { - String name = itr.next(); - CircularBufferDataProvider data = (CircularBufferDataProvider) traces.get(name).getDataProvider(); - if (data != null) { - for (int inx = 0; inx < data.getSize(); inx++) { - Sample sample = (Sample) data.getSample(inx); - double x = sample.getXValue(); - if(x < lower || x > upper) { - continue; - } - double y = sample.getYValue(); - if (y > max) { - max = y; - } - } - } - } - return ChartUtil.getGroupMaxValue(max); - } - - static class StackValue { - double actualValue; - double stackedValue; - long lastUpdateTime; - } - - public enum MODE { - THROUGHPUT, - ELASPED - } - - class ChangeThroughput extends Action { - ChangeThroughput () { - setText("Throughput"); - setImageDescriptor(Activator.getImageDescriptor("/icons/counter/transaction.png")); - } - - public void run() { - changeMode(MODE.THROUGHPUT); - } - } - - class ChangeElasped extends Action { - ChangeElasped () { - setText("Elapsed Time"); - setImageDescriptor(Activator.getImageDescriptor("/icons/counter/time.png")); - } - public void run() { - changeMode(MODE.ELASPED); - } - } -} + * @https://github.com/scouter-project/scouter + * + * 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 scouter.client.views; + +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.csstudio.swt.xygraph.dataprovider.CircularBufferDataProvider; +import org.csstudio.swt.xygraph.dataprovider.Sample; +import org.csstudio.swt.xygraph.figures.Trace; +import org.csstudio.swt.xygraph.figures.Trace.PointStyle; +import org.csstudio.swt.xygraph.figures.Trace.TraceType; +import org.csstudio.swt.xygraph.figures.XYGraph; +import org.csstudio.swt.xygraph.linearscale.Range; +import org.eclipse.draw2d.FigureCanvas; +import org.eclipse.jface.window.DefaultToolTip; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.ControlListener; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.KeyListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.PaletteData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.ui.part.ViewPart; + +import scouter.client.Images; +import scouter.client.listeners.RangeMouseListener; +import scouter.client.model.RefreshThread; +import scouter.client.model.RefreshThread.Refreshable; +import scouter.client.model.ServiceGroupColorManager; +import scouter.client.util.ChartUtil; +import scouter.client.util.ColorUtil; +import scouter.client.util.ExUtil; +import scouter.client.util.TimeUtil; +import scouter.client.util.UIUtil; +import scouter.lang.pack.MapPack; +import scouter.lang.value.ListValue; +import scouter.util.CastUtil; +import scouter.util.DateUtil; +import scouter.util.LinkedMap; + +public abstract class AbstractServiceGroupTPSView extends ViewPart implements Refreshable { + + public final static String ID = AbstractServiceGroupTPSView.class.getName(); + + private final static int BUFFER_SIZE = 200; + protected RefreshThread thread; + + protected XYGraph xyGraph; + protected FigureCanvas canvas; + + protected Map traces = new HashMap(); + private LinkedMap stackValueMap = new LinkedMap(); + + private int manualRangeCount; + private double manualY; + + public void createPartControl(Composite parent) { + parent.setLayout(UIUtil.formLayout(0, 0)); + canvas = new FigureCanvas(parent); + canvas.setScrollBarVisibility(FigureCanvas.NEVER); + canvas.setLayoutData(UIUtil.formData(0, 0, 0, 0, 100, 0, 100, 0)); + canvas.setBackground(ColorUtil.getInstance().getColor(SWT.COLOR_WHITE)); + canvas.addControlListener(new ControlListener() { + boolean lock = false; + public void controlResized(ControlEvent e) { + org.eclipse.swt.graphics.Rectangle r = canvas.getClientArea(); + if (!lock) { + lock = true; + xyGraph.setSize(r.width, r.height); + lock = false; + } + } + public void controlMoved(ControlEvent e) { + } + }); + final DefaultToolTip toolTip = new DefaultToolTip(canvas, DefaultToolTip.RECREATE, true); + toolTip.setFont(new Font(null, "Arial", 10, SWT.BOLD)); + toolTip.setBackgroundColor(Display.getCurrent().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); + canvas.addMouseListener(new MouseListener() { + + String selectedName; + + public void mouseUp(MouseEvent e) { + if (selectedName == null) { + return; + } + Trace trace = traces.get(selectedName); + trace.setTraceColor(ServiceGroupColorManager.getInstance().assignColor(selectedName)); + toolTip.hide(); + selectedName = null; + } + public void mouseDown(MouseEvent e) { + Image image = new Image(e.display, 1, 1); + GC gc = new GC((FigureCanvas)e.widget); + gc.copyArea(image, e.x, e.y); + ImageData imageData = image.getImageData(); + PaletteData palette = imageData.palette; + int pixelValue = imageData.getPixel(0, 0); + RGB rgb = palette.getRGB(pixelValue); + selectedName = ServiceGroupColorManager.getInstance().getServiceGroup(rgb); + if (selectedName != null) { + Trace trace = traces.get(selectedName); + trace.setTraceColor(ColorUtil.getInstance().getColor("dark magenta")); + toolTip.setText(selectedName); + toolTip.show(new Point(e.x, e.y)); + } + gc.dispose(); + image.dispose(); + } + public void mouseDoubleClick(MouseEvent e) {} + }); + canvas.addKeyListener(new KeyListener() { + public void keyReleased(KeyEvent e) { + } + + public void keyPressed(KeyEvent e) { + switch (e.keyCode) { + case 16777217:// UP Key + double max = xyGraph.primaryYAxis.getRange().getUpper(); + if (max > 10000) { + manualY = max + 1000; + } else if (max > 1000) { + manualY = max + 100; + } else if (max > 100) { + manualY = max + 10; + } else if (max == 3) { + manualY = 5; + } else { + manualY = max + 5; + } + manualRangeCount = 5; + xyGraph.primaryYAxis.setRange(0, manualY); + break; + case 16777218: // DOWN Key + max = xyGraph.primaryYAxis.getRange().getUpper(); + if (max > 10000) { + manualY = max - 1000; + } else if (max > 1000) { + manualY =max - 100; + } else if (max > 100) { + manualY =max - 10; + } else { + manualY = (max - 5) > 3 ? max -5 : 3; + } + manualRangeCount = 5; + xyGraph.primaryYAxis.setRange(0, manualY); + break; + } + } + }); + xyGraph = new XYGraph(); + xyGraph.setShowLegend(true); + xyGraph.setShowTitle(false); + canvas.setContents(xyGraph); + xyGraph.primaryXAxis.setDateEnabled(true); + xyGraph.primaryXAxis.setShowMajorGrid(true); + xyGraph.primaryYAxis.setAutoScale(true); + xyGraph.primaryYAxis.setShowMajorGrid(true); + xyGraph.primaryXAxis.setTitle(""); + xyGraph.primaryYAxis.setTitle(""); + + xyGraph.primaryYAxis.addMouseListener(new RangeMouseListener(getViewSite().getShell(), xyGraph.primaryYAxis)); + thread = new RefreshThread(this, 2000); + thread.start(); + } + + public void setFocus() {} + + @Override + public void dispose() { + super.dispose(); + if (this.thread != null) { + this.thread.shutdown(); + } + } + + boolean stopRefresh = false; + + public void refresh() { + if (stopRefresh) { + return; + } + MapPack m = fetch(); + if (m == null) { + ExUtil.exec(canvas, new Runnable() { + public void run() { + setTitleImage(Images.inactive); + long now = TimeUtil.getCurrentTime(); + xyGraph.primaryXAxis.setRange(now - DateUtil.MILLIS_PER_FIVE_MINUTE, now + 1); + } + }); + return; + } + removeDeadGroup(m); + processThroughputData(m); + } + + public abstract MapPack fetch(); + + private void removeDeadGroup(MapPack m) { + ListValue nameLv = m.getList("name"); + + ArrayList grpSet = new ArrayList(); + Enumeration enu =stackValueMap.keys(); + while(enu.hasMoreElements()){ + grpSet.add(enu.nextElement()); + } + for (int i = 0; i < nameLv.size(); i++) { + String name = nameLv.getString(i); + grpSet.remove(name); + } + for (String dead : grpSet) { + stackValueMap.remove(dead); + final Trace t = traces.get(dead); + if (t == null) continue; + ExUtil.exec(canvas, new Runnable() { + public void run() { + xyGraph.removeTrace(t); + } + }); + traces.remove(dead); + } + } + + private void processThroughputData(MapPack m) { + ListValue nameLv = m.getList("name"); + ListValue countLv = m.getList("count"); + final long now = m.getLong("time"); + final long stime = now - DateUtil.MILLIS_PER_FIVE_MINUTE; + for (int i = 0; i < nameLv.size(); i++) { + String name = nameLv.getString(i); + double value = CastUtil.cdouble(countLv.get(i)) / 30.0d; + if (stackValueMap.containsKey(name)) { + StackValue sv = stackValueMap.get(name); + sv.actualValue = value; + sv.lastUpdateTime = now; + } else { + StackValue sv = new StackValue(); + sv.actualValue = value; + sv.lastUpdateTime = now; + stackValueMap.putFirst(name, sv); + } + } + Enumeration itr = stackValueMap.keys(); + final LinkedMap tempMap = new LinkedMap(); + double stackValue = 0.0; + while (itr.hasMoreElements()) { + String name = itr.nextElement(); + StackValue sv = stackValueMap.get(name); + if (sv.lastUpdateTime == now) { + stackValue += sv.actualValue; + sv.stackedValue = stackValue; + tempMap.putFirst(name, sv); + } + } + ExUtil.exec(canvas, new Runnable() { + public void run() { + setTitleImage(Images.active); + xyGraph.primaryXAxis.setRange(stime, now + 1); + Enumeration itr = tempMap.keys(); + while (itr.hasMoreElements()) { + String name = itr.nextElement(); + StackValue sv = tempMap.get(name); + CircularBufferDataProvider provider = (CircularBufferDataProvider) getTrace(name).getDataProvider(); + provider.addSample(new Sample(now, sv.stackedValue)); + } + xyGraph.primaryYAxis.setRange(0, getMaxValue()); + } + }); + } + + private Trace getTrace(String name) { + Trace trace = traces.get(name); + if (trace == null) { + CircularBufferDataProvider provider = new CircularBufferDataProvider(true); + provider.setBufferSize(BUFFER_SIZE); + trace = new Trace(name, xyGraph.primaryXAxis, xyGraph.primaryYAxis, provider); + trace.setPointStyle(PointStyle.NONE); + trace.getXAxis().setFormatPattern("HH:mm:ss"); + trace.getYAxis().setFormatPattern("#,##0"); + trace.setTraceType(TraceType.AREA); + trace.setAreaAlpha(255); + trace.setTraceColor(ServiceGroupColorManager.getInstance().assignColor(name)); + xyGraph.addTrace(trace); + traces.put(name, trace); + } + return trace; + } + + private double getMaxValue() { + Range xRange = xyGraph.primaryXAxis.getRange(); + double lower = xRange.getLower(); + double upper = xRange.getUpper(); + if (manualRangeCount > 0 && manualY > 0) { + manualRangeCount--; + return manualY; + } + double max = 0.0; + Iterator itr = traces.keySet().iterator(); + while (itr.hasNext()) { + String name = itr.next(); + CircularBufferDataProvider data = (CircularBufferDataProvider) traces.get(name).getDataProvider(); + if (data != null) { + for (int inx = 0; inx < data.getSize(); inx++) { + Sample sample = (Sample) data.getSample(inx); + double x = sample.getXValue(); + if(x < lower || x > upper) { + continue; + } + double y = sample.getYValue(); + if (y > max) { + max = y; + } + } + } + } + return ChartUtil.getGroupMaxValue(max); + } + + static class StackValue { + double actualValue; + double stackedValue; + long lastUpdateTime; + } +} diff --git a/scouter.client/src/scouter/client/views/CounterStackCommonView.java b/scouter.client/src/scouter/client/views/CounterStackCommonView.java index beca1059f..57a0e421b 100644 --- a/scouter.client/src/scouter/client/views/CounterStackCommonView.java +++ b/scouter.client/src/scouter/client/views/CounterStackCommonView.java @@ -56,7 +56,7 @@ import scouter.client.util.ExUtil; import scouter.client.util.TimeUtil; import scouter.client.util.UIUtil; -import scouter.client.views.ServiceGroupCommonView.StackValue; +import scouter.client.views.AbstractServiceGroupTPSView.StackValue; import scouter.lang.value.MapValue; import scouter.util.CastUtil; import scouter.util.DateUtil; diff --git a/scouter.client/src/scouter/client/views/ObjectDailyListView.java b/scouter.client/src/scouter/client/views/ObjectDailyListView.java index 183de1ef4..3de14b192 100644 --- a/scouter.client/src/scouter/client/views/ObjectDailyListView.java +++ b/scouter.client/src/scouter/client/views/ObjectDailyListView.java @@ -264,20 +264,7 @@ private void fillTreeViewerContextMenu(IMenuManager mgr){ objTitle.add(counterMenuManager); } - objTitle.add(new Separator()); - - Action act = actions.get(objType + ":" + CounterConstants.TRANX_REALTIME); - if(act != null){ - act.setText(MenuStr.PASTTIME_XLOG); - act.setImageDescriptor(ImageUtil.getImageDescriptor(Images.transrealtime)); - objTitle.add(act); - } - act = actions.get(objType + ":" + CounterConstants.TODAY_SERVICE_COUNT); - if(act != null){ - act.setText(MenuStr.LOAD_SERVICE_COUNT); - act.setImageDescriptor(ImageUtil.getImageDescriptor(Images.TYPE_SERVICE_COUNT)); - objTitle.add(act); - } + MenuUtil.addPastObjTypeSpecialMenu(win, objTitle, serverId, objType, counterEngine, curdate); } } } diff --git a/scouter.client/src/scouter/client/views/ObjectNavigationView.java b/scouter.client/src/scouter/client/views/ObjectNavigationView.java index 6ac61fb9e..da7b15ad4 100644 --- a/scouter.client/src/scouter/client/views/ObjectNavigationView.java +++ b/scouter.client/src/scouter/client/views/ObjectNavigationView.java @@ -116,7 +116,6 @@ import scouter.lang.counters.CounterEngine; import scouter.lang.value.Value; import scouter.util.CastUtil; -import scouter.util.CompareUtil; import scouter.util.FormatUtil; import scouter.util.HashUtil; @@ -146,9 +145,6 @@ enum PresentMode { HIERACHY_MODE, FLAT_MODE } IMenuManager collectorMenuManager; IMenuManager hostMenuManager; IMenuManager objectMenuManager; - HierarchyObject lastSelectedCollector; - HierarchyObject lastSelectedHost; - HierarchyObject lastSelectedObject; public void refresh() { if (mode == PresentMode.HIERACHY_MODE) { @@ -270,70 +266,6 @@ public void handleEvent(Event event) { TreeItem item = objTreeViewer.getTree().getItem(point); if (item != null) { selectedItem = true; - ISelection selection = objTreeViewer.getSelection(); - if (selection instanceof IStructuredSelection) { - IStructuredSelection sel = (IStructuredSelection)selection; - Object[] elements = sel.toArray(); - if (elements == null || elements.length < 1) { - return; - } - Object selObject = elements[elements.length - 1]; - if (selObject instanceof ServerObject) { - if (!CompareUtil.equals(selObject, lastSelectedCollector)) { - // Update Collector TopMenu - lastSelectedCollector = fillTopMenu((HierarchyObject) selObject, collectorMenuManager); - resetTopMenu(hostMenuManager, "Choose Host in ObjectView"); - lastSelectedHost = null; - resetTopMenu(objectMenuManager, "Choose Object in ObjectView"); - lastSelectedObject = null; - topMenuManager.update(true); - } - } else if (selObject instanceof AgentObject) { - AgentObject agent = (AgentObject) selObject; - int serverId = agent.getServerId(); - Server server = ServerManager.getInstance().getServer(serverId); - ServerObject serverObject = root.get(server.getName()); - CounterEngine engine = server.getCounterEngine(); - if (engine.isChildOf(agent.getObjType(), CounterConstants.FAMILY_HOST)) { - if (!CompareUtil.equals(agent, lastSelectedHost)) { - // Update Host TopMenu - resetTopMenu(objectMenuManager, "Choose Object in ObjectView"); - lastSelectedObject = null; - lastSelectedHost = fillTopMenu(agent, hostMenuManager); - if (!CompareUtil.equals(serverObject, lastSelectedCollector)) { - // Update Collector TopMenu - if (serverObject != null) { - lastSelectedCollector = fillTopMenu(serverObject, collectorMenuManager); - } - } - topMenuManager.update(true); - } - } else { - if (!CompareUtil.equals(agent, lastSelectedObject)) { - // Update Object TopMenu - lastSelectedObject = fillTopMenu(agent, objectMenuManager); - String objName = agent.getObjName(); - String host = objName.substring(0, objName.indexOf("/", 1)); - AgentObject hostAgent = agentThread.getAgentObject(HashUtil.hash(host)); - if (hostAgent == null) { - resetTopMenu(hostMenuManager, "Cannot find Host agent"); - lastSelectedHost = null; - } else { - if (!CompareUtil.equals(hostAgent, lastSelectedHost)) { - lastSelectedHost = fillTopMenu(hostAgent, hostMenuManager); - } - } - if (!CompareUtil.equals(serverObject, lastSelectedCollector)) { - // Update Collector TopMenu - if (serverObject != null) { - lastSelectedCollector = fillTopMenu(serverObject, collectorMenuManager); - } - } - topMenuManager.update(true); - } - } - } - } } else { selectedItem = false; } @@ -409,6 +341,97 @@ private void initTopMenuMangers() { hostMenuManager.add(new DummyAction("Choose Host in ObjectView", Images.alert)); objectMenuManager.add(new DummyAction("Choose Object in ObjectView", Images.alert)); topMenuManager.update(true); + collectorMenuManager.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager mgr) { + ISelection selection = objTreeViewer.getSelection(); + if (selection instanceof IStructuredSelection) { + IStructuredSelection sel = (IStructuredSelection)selection; + Object[] elements = sel.toArray(); + ServerObject serverObject = null; + if (elements == null || elements.length < 1) { + Server defServer = ServerManager.getInstance().getDefaultServer(); + serverObject = root.get(defServer.getName()); + } else { + Object selObject = elements[elements.length - 1]; + if (selObject instanceof ServerObject) { + serverObject = (ServerObject) selObject; + } else if (selObject instanceof AgentObject) { + AgentObject ao = (AgentObject) selObject; + Server server = ServerManager.getInstance().getServer(ao.getServerId()); + serverObject = root.get(server.getName()); + } + } + if (serverObject != null) { + fillTopMenu(serverObject, mgr); + } else { + resetTopMenu(collectorMenuManager, "Choose Collector in ObjectView"); + } + + } + } + }); + hostMenuManager.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager mgr) { + ISelection selection = objTreeViewer.getSelection(); + if (selection instanceof IStructuredSelection) { + IStructuredSelection sel = (IStructuredSelection)selection; + Object[] elements = sel.toArray(); + AgentObject hostObject = null; + if (elements == null || elements.length < 1) { + return; + } else { + Object selObject = elements[elements.length - 1]; + if (selObject instanceof AgentObject) { + AgentObject agent = (AgentObject) selObject; + int serverId = agent.getServerId(); + Server server = ServerManager.getInstance().getServer(serverId); + CounterEngine engine = server.getCounterEngine(); + if (engine.isChildOf(agent.getObjType(), CounterConstants.FAMILY_HOST)) { + hostObject = agent; + } else { + String objName = agent.getObjName(); + String host = objName.substring(0, objName.indexOf("/", 1)); + hostObject = agentThread.getAgentObject(HashUtil.hash(host)); + } + } + } + if (hostObject != null) { + fillTopMenu(hostObject, mgr); + } else { + resetTopMenu(hostMenuManager, "Choose Host in ObjectView"); + } + } + } + }); + objectMenuManager.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager mgr) { + ISelection selection = objTreeViewer.getSelection(); + if (selection instanceof IStructuredSelection) { + IStructuredSelection sel = (IStructuredSelection)selection; + Object[] elements = sel.toArray(); + AgentObject object = null; + if (elements == null || elements.length < 1) { + return; + } else { + Object selObject = elements[elements.length - 1]; + if (selObject instanceof AgentObject) { + AgentObject agent = (AgentObject) selObject; + int serverId = agent.getServerId(); + Server server = ServerManager.getInstance().getServer(serverId); + CounterEngine engine = server.getCounterEngine(); + if (!engine.isChildOf(agent.getObjType(), CounterConstants.FAMILY_HOST)) { + object = agent; + } + } + } + if (object != null) { + fillTopMenu(object, mgr); + } else { + resetTopMenu(objectMenuManager, "Choose Object in ObjectView"); + } + } + } + }); } private void createQuickMenus(){ @@ -598,6 +621,7 @@ private void addExistObjectTypeMenus(IWorkbenchWindow win, IMenuManager mgr, Cou MenuManager objTitle = new MenuManager(displayName, objImage, "scouter.menu.id."+displayName); mgr.add(objTitle); addObjectTypeMenu(objTitle, counterEngine, actionMap, serverId, objType); + MenuUtil.addObjTypeSpecialMenu(win, objTitle, serverId, objType, counterEngine); } } @@ -611,52 +635,6 @@ private void addObjectTypeMenu(IMenuManager objTitle, CounterEngine counterEngin objTitle.add(realtimeAllAct); } } - - objTitle.add(new Separator()); - - Action act = actionMap.get(objType + ":" + CounterConstants.ACTIVE_EQ); - if(act != null){ - objTitle.add(act); - } - - act = actionMap.get(objType + ":" + CounterConstants.ACTIVE_THREAD_LIST); - if(act != null){ - act.setText(MenuStr.ACTIVE_SERVICE_LIST); - act.setImageDescriptor(ImageUtil.getImageDescriptor(Images.thread)); - objTitle.add(act); - } - - act = actionMap.get(objType + ":" + CounterConstants.TOTAL_ACTIVE_SPEED); - if(act != null){ - act.setText(MenuStr.ACTIVE_SPEED_REAL); - act.setImageDescriptor(ImageUtil.getImageDescriptor(Images.TYPE_ACTSPEED)); - objTitle.add(act); - } - - act = actionMap.get(objType + ":" + CounterConstants.TRANX_REALTIME); - if(act != null){ - objTitle.add(act); - } - - act = actionMap.get(objType + ":" + CounterConstants.TODAY_SERVICE_COUNT); - if(act != null){ - objTitle.add(act); - } - - act = actionMap.get(objType + ":" + CounterConstants.SERVICE_GROUP); - if(act != null){ - objTitle.add(act); - } - - act = actionMap.get(objType + ":" + CounterConstants.UNIQUE_VISITOR); - if(act != null){ - objTitle.add(act); - } - - act = actionMap.get(objType + ":" + CounterConstants.SERVICE_SUMMARY); - if(act != null){ - objTitle.add(act); - } } private static void removeActionCache(int serverId) { diff --git a/scouter.client/src/scouter/client/views/ServiceGroupElapsedView.java b/scouter.client/src/scouter/client/views/ServiceGroupElapsedView.java new file mode 100644 index 000000000..a93b3a0c7 --- /dev/null +++ b/scouter.client/src/scouter/client/views/ServiceGroupElapsedView.java @@ -0,0 +1,86 @@ +/* + * Copyright 2015 the original author or authors. + * @https://github.com/scouter-project/scouter + * + * 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 scouter.client.views; + +import java.util.Map; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IViewSite; +import org.eclipse.ui.PartInitException; + +import scouter.client.model.AgentModelThread; +import scouter.client.model.AgentObject; +import scouter.client.net.TcpProxy; +import scouter.client.server.Server; +import scouter.client.server.ServerManager; +import scouter.client.util.TimeUtil; +import scouter.lang.pack.MapPack; +import scouter.lang.pack.Pack; +import scouter.lang.value.ListValue; +import scouter.net.RequestCmd; + +public class ServiceGroupElapsedView extends AbstractServiceGroupElapsedView { + + public final static String ID = ServiceGroupElapsedView.class.getName(); + + int serverId; + String objType; + String displayObjType; + + public void init(IViewSite site) throws PartInitException { + super.init(site); + String secId = site.getSecondaryId(); + String ids[] = secId.split("&"); + serverId = Integer.valueOf(ids[0]); + objType = ids[1]; + } + + public void createPartControl(Composite parent) { + Server server = ServerManager.getInstance().getServer(serverId); + if (server != null ) displayObjType = server.getCounterEngine().getDisplayNameObjectType(objType); + this.setPartName("Service[Elapsed] - " + displayObjType); + super.createPartControl(parent); + } + + public MapPack fetch() { + TcpProxy tcp = TcpProxy.getTcpProxy(serverId); + Pack pack = null; + try { + MapPack param = new MapPack(); + ListValue objLv = param.newList("objHash"); + Map agentMap = AgentModelThread.getInstance().getAgentObjectMap(); + for (AgentObject p : agentMap.values()) { + if (p.getObjType().equals(objType)) { + objLv.add(p.getObjHash()); + } + } + pack = tcp.getSingle(RequestCmd.REALTIME_SERVICE_GROUP, param); + } catch (Throwable th) { + th.printStackTrace(); + } finally { + TcpProxy.putTcpProxy(tcp); + } + MapPack m = null; + if (pack != null) { + m = (MapPack) pack; + long time = TimeUtil.getCurrentTime(serverId); + m.put("time", time); + } + return m; + } +} diff --git a/scouter.client/src/scouter/client/views/ServiceGroupView.java b/scouter.client/src/scouter/client/views/ServiceGroupTPSView.java similarity index 82% rename from scouter.client/src/scouter/client/views/ServiceGroupView.java rename to scouter.client/src/scouter/client/views/ServiceGroupTPSView.java index 7b9d2f158..9d81d08d3 100644 --- a/scouter.client/src/scouter/client/views/ServiceGroupView.java +++ b/scouter.client/src/scouter/client/views/ServiceGroupTPSView.java @@ -1,99 +1,86 @@ -/* +/* * Copyright 2015 the original author or authors. - * @https://github.com/scouter-project/scouter - * - * 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 scouter.client.views; - -import java.util.Map; - -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.IViewSite; -import org.eclipse.ui.PartInitException; - -import scouter.client.model.AgentModelThread; -import scouter.client.model.AgentObject; -import scouter.client.net.TcpProxy; -import scouter.client.server.Server; -import scouter.client.server.ServerManager; -import scouter.client.util.TimeUtil; -import scouter.lang.pack.MapPack; -import scouter.lang.pack.Pack; -import scouter.lang.value.ListValue; -import scouter.net.RequestCmd; - -public class ServiceGroupView extends ServiceGroupCommonView { - - public final static String ID = ServiceGroupView.class.getName(); - - int serverId; - String objType; - String displayObjType; - - public void init(IViewSite site) throws PartInitException { - super.init(site); - String secId = site.getSecondaryId(); - String ids[] = secId.split("&"); - serverId = Integer.valueOf(ids[0]); - objType = ids[1]; - } - - public void createPartControl(Composite parent) { - Server server = ServerManager.getInstance().getServer(serverId); - if (server != null ) displayObjType = server.getCounterEngine().getDisplayNameObjectType(objType); - this.setPartName("Service[Throughput] - " + displayObjType); - super.createPartControl(parent); - } - - public MapPack fetch() { - TcpProxy tcp = TcpProxy.getTcpProxy(serverId); - Pack pack = null; - try { - MapPack param = new MapPack(); - ListValue objLv = param.newList("objHash"); - Map agentMap = AgentModelThread.getInstance().getAgentObjectMap(); - for (AgentObject p : agentMap.values()) { - if (p.getObjType().equals(objType)) { - objLv.add(p.getObjHash()); - } - } - pack = tcp.getSingle(RequestCmd.REALTIME_SERVICE_GROUP, param); - } catch (Throwable th) { - th.printStackTrace(); - } finally { - TcpProxy.putTcpProxy(tcp); - } - MapPack m = null; - if (pack != null) { - m = (MapPack) pack; - long time = TimeUtil.getCurrentTime(serverId); - m.put("time", time); - fiveMinMap.put(time, m); - } - return m; - } - - @Override - public void setTitleName(MODE mode) { - switch (mode) { - case THROUGHPUT: - this.setPartName("Service[Throughput] - " + displayObjType); - break; - case ELASPED: - this.setPartName("Service[Elapsed Time] - " + displayObjType); - break; - } - } -} + * @https://github.com/scouter-project/scouter + * + * 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 scouter.client.views; + +import java.util.Map; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IViewSite; +import org.eclipse.ui.PartInitException; + +import scouter.client.model.AgentModelThread; +import scouter.client.model.AgentObject; +import scouter.client.net.TcpProxy; +import scouter.client.server.Server; +import scouter.client.server.ServerManager; +import scouter.client.util.TimeUtil; +import scouter.lang.pack.MapPack; +import scouter.lang.pack.Pack; +import scouter.lang.value.ListValue; +import scouter.net.RequestCmd; + +public class ServiceGroupTPSView extends AbstractServiceGroupTPSView { + + public final static String ID = ServiceGroupTPSView.class.getName(); + + int serverId; + String objType; + String displayObjType; + + public void init(IViewSite site) throws PartInitException { + super.init(site); + String secId = site.getSecondaryId(); + String ids[] = secId.split("&"); + serverId = Integer.valueOf(ids[0]); + objType = ids[1]; + } + + public void createPartControl(Composite parent) { + Server server = ServerManager.getInstance().getServer(serverId); + if (server != null ) displayObjType = server.getCounterEngine().getDisplayNameObjectType(objType); + this.setPartName("Service[Throughput] - " + displayObjType); + super.createPartControl(parent); + } + + public MapPack fetch() { + TcpProxy tcp = TcpProxy.getTcpProxy(serverId); + Pack pack = null; + try { + MapPack param = new MapPack(); + ListValue objLv = param.newList("objHash"); + Map agentMap = AgentModelThread.getInstance().getAgentObjectMap(); + for (AgentObject p : agentMap.values()) { + if (p.getObjType().equals(objType)) { + objLv.add(p.getObjHash()); + } + } + pack = tcp.getSingle(RequestCmd.REALTIME_SERVICE_GROUP, param); + } catch (Throwable th) { + th.printStackTrace(); + } finally { + TcpProxy.putTcpProxy(tcp); + } + MapPack m = null; + if (pack != null) { + m = (MapPack) pack; + long time = TimeUtil.getCurrentTime(serverId); + m.put("time", time); + } + return m; + } +} diff --git a/scouter.client/src/scouter/client/xlog/actions/OpenXLogLoadTimeAction.java b/scouter.client/src/scouter/client/xlog/actions/OpenXLogLoadTimeAction.java index b14fdc698..78a892466 100644 --- a/scouter.client/src/scouter/client/xlog/actions/OpenXLogLoadTimeAction.java +++ b/scouter.client/src/scouter/client/xlog/actions/OpenXLogLoadTimeAction.java @@ -39,19 +39,19 @@ public class OpenXLogLoadTimeAction extends Action implements CalendarDialog.ILo private long stime, etime; - public OpenXLogLoadTimeAction(IWorkbenchWindow window, String label, String objType, Image image, int serverId, long stime, long etime) { + public OpenXLogLoadTimeAction(IWorkbenchWindow window, String objType, Image image, int serverId, long stime, long etime) { this.window = window; this.objType = objType; this.serverId = serverId; this.stime = stime; this.etime = etime; - setText(label); + setText("XLog"); setId(ID); setImageDescriptor(ImageUtil.getImageDescriptor(image)); } public OpenXLogLoadTimeAction(IWorkbenchWindow window, String label, String objType, Image image, int serverId) { - this(window, label, objType, image, serverId, 0, 0); + this(window, objType, image, serverId, 0, 0); } public void run() { diff --git a/scouter.client/src/scouter/client/xlog/views/XLogLoadTimeView.java b/scouter.client/src/scouter/client/xlog/views/XLogLoadTimeView.java index 7fb185ef7..f6292d9ed 100644 --- a/scouter.client/src/scouter/client/xlog/views/XLogLoadTimeView.java +++ b/scouter.client/src/scouter/client/xlog/views/XLogLoadTimeView.java @@ -117,7 +117,7 @@ public void run() { loadXLogItem.setText("Load"); loadXLogItem.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { - new OpenXLogLoadTimeAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), "Load XLog", objType, Images.server, serverId, stime, etime).run(); + new OpenXLogLoadTimeAction(PlatformUI.getWorkbench().getActiveWorkbenchWindow(), objType, Images.server, serverId, stime, etime).run(); } }); diff --git a/scouter.common/pom.xml b/scouter.common/pom.xml new file mode 100644 index 000000000..e28dd93d2 --- /dev/null +++ b/scouter.common/pom.xml @@ -0,0 +1,29 @@ + + 4.0.0 + + scouter + common + 1.0 + jar + scouter-common + + + UTF-8 + + + + + junit + junit + 4.12 + test + + + org.assertj + assertj-core + 2.3.0 + test + + + diff --git a/scouter.common/src/scouter/lang/counters/CounterConstants.java b/scouter.common/src/scouter/lang/counters/CounterConstants.java index 52738ed33..8d14768aa 100644 --- a/scouter.common/src/scouter/lang/counters/CounterConstants.java +++ b/scouter.common/src/scouter/lang/counters/CounterConstants.java @@ -122,15 +122,6 @@ public class CounterConstants { public final static String PAST_TIME = "pt"; public final static String PAST_DATE = "pd"; - public final static String TOTAL_ACTIVE_SPEED = "totactsp"; - public final static String ACTIVE_EQ = "acteq"; - public final static String TRANX_REALTIME = "txreal"; - public final static String ACTIVE_THREAD_LIST = "actthrli"; - public final static String TODAY_SERVICE_COUNT = "tdservcnt"; - public final static String SERVICE_GROUP = "svcgrp"; - public final static String UNIQUE_VISITOR = "unqvst"; - public final static String SERVICE_SUMMARY = "sersum"; - public final static String[] COUNTER_MENU_ARRAY = { REAL_TIME_ALL, REAL_TIME_TOTAL, TODAY_ALL, TODAY_TOTAL, PAST_TIME_ALL, PAST_TIME_TOTAL, PAST_DATE_ALL, PAST_DATE_TOTAL }; diff --git a/scouter.common/src/scouter/lang/counters/CounterEngine.java b/scouter.common/src/scouter/lang/counters/CounterEngine.java index 8382945c7..02642bfd7 100644 --- a/scouter.common/src/scouter/lang/counters/CounterEngine.java +++ b/scouter.common/src/scouter/lang/counters/CounterEngine.java @@ -479,7 +479,6 @@ public static void main(String[] args) { CounterEngine ce = new CounterEngine(); ce.parse(content); System.out.println(ce.getAllObjectType()); - System.out.println(ce.getObjTypeListWithDisplay(CounterConstants.TOTAL_ACTIVE_SPEED)); System.out.println(ce.getDisplayNameObjectType("tomcat")); System.out.println(ce.getAllCounterList()); System.out.println(ce.getTotalCounterList()); diff --git a/scouter.common/src/scouter/lang/counters/counters.xml b/scouter.common/src/scouter/lang/counters/counters.xml index 1a1047fe9..338caa794 100644 --- a/scouter.common/src/scouter/lang/counters/counters.xml +++ b/scouter.common/src/scouter/lang/counters/counters.xml @@ -1,14 +1,5 @@