diff --git a/scouter.agent.java/src/scouter/agent/Configure.java b/scouter.agent.java/src/scouter/agent/Configure.java index 76334583f..f8b71683b 100644 --- a/scouter.agent.java/src/scouter/agent/Configure.java +++ b/scouter.agent.java/src/scouter/agent/Configure.java @@ -171,6 +171,9 @@ public final static synchronized Configure getInstance() { public boolean hook_method_access_protected = false; public boolean hook_method_access_none = false; + public boolean trace_method_enabled=true; + + public String hook_service = ""; public String hook_apicall = ""; public String hook_apicall_info = ""; @@ -313,7 +316,7 @@ public File getPropertyFile() { } long last_check = 0; - + public synchronized boolean reload(boolean force) { long now = System.currentTimeMillis(); @@ -441,6 +444,8 @@ private void apply() { this._hook_method_ignore_classes = new StringSet(StringUtil.tokenizer( this.hook_method_ignore_classes.replace('.', '/'), ",")); + this.trace_method_enabled=getBoolean("trace_method_enabled", true); + this.hook_service = getValue("hook_service", ""); this.hook_apicall = getValue("hook_apicall", ""); this.hook_apicall_info = getValue("hook_apicall_info", ""); diff --git a/scouter.agent.java/src/scouter/agent/counter/task/JBossJMXPerf.java b/scouter.agent.java/src/scouter/agent/counter/task/JBossJMXPerf.java index 6e20857ae..3e6d7ac12 100644 --- a/scouter.agent.java/src/scouter/agent/counter/task/JBossJMXPerf.java +++ b/scouter.agent.java/src/scouter/agent/counter/task/JBossJMXPerf.java @@ -33,6 +33,8 @@ import scouter.agent.counter.CounterBasket; import scouter.agent.counter.anotation.Counter; import scouter.agent.counter.meter.MeterResource; +import scouter.agent.counter.task.TomcatJMXPerf.CtxObj; +import scouter.agent.counter.task.TomcatJMXPerf.MeterKey; import scouter.lang.TimeTypeEnum; import scouter.lang.conf.ConfObserver; import scouter.lang.counters.CounterConstants; @@ -78,22 +80,22 @@ private MeterResource getMeter(MeterKey key) { static class MeterKey { - String objName; + int mbeanHash; String counter; - public MeterKey(String objName, String counter) { - this.objName = objName; + public MeterKey(int mbeanHash, String counter) { + this.mbeanHash = mbeanHash; this.counter = counter; } public int hashCode() { - return objName.hashCode() ^ counter.hashCode(); + return mbeanHash ^ counter.hashCode(); } public boolean equals(Object obj) { if (obj instanceof MeterKey) { MeterKey key = (MeterKey) obj; - return (this.objName.equals(key.objName)) && (this.counter.equals(key.counter)); + return (this.mbeanHash == key.mbeanHash) && (this.counter.equals(key.counter)); } return false; } @@ -110,8 +112,6 @@ public void process(CounterBasket pw) { if (CounterConstants.JBOSS.equals(ObjTypeDetector.objType) == false) { return; } - // if(CounterConstants.JBOSS.equals(conf.objType) ==false) - // return; getMBeanServer(); @@ -124,12 +124,12 @@ public void process(CounterBasket pw) { } collectCnt++; + collectCnt++; MBeanServer server = servers.get(0); - for (CtxObj ctx : ctxList) { if (ctx.valueType == ValueEnum.DECIMAL) { try { - MeterKey key = new MeterKey(ctx.objName, ctx.counter); + MeterKey key = new MeterKey(ctx.mbeanHash, ctx.counter); long v = CastUtil.clong(server.getAttribute(ctx.mbean, ctx.attrName)); if (deltas.contains(ctx.counter)) { v = getDelta(key, v); @@ -138,8 +138,8 @@ public void process(CounterBasket pw) { v = (long) meter.getSum(60); long sum = (long) meter.getSum(300) / 5; - pw.getPack(ctx.objName, TimeTypeEnum.REALTIME).put(ctx.counter, new DecimalValue(v)); - pw.getPack(ctx.objName, TimeTypeEnum.FIVE_MIN).put(ctx.counter, new DecimalValue(sum)); + pw.getPack(ctx.objName, TimeTypeEnum.REALTIME).add(ctx.counter, new DecimalValue(v)); + pw.getPack(ctx.objName, TimeTypeEnum.FIVE_MIN).add(ctx.counter, new DecimalValue(sum)); } else { MeterResource meter = getMeter(key); meter.add(v); @@ -147,8 +147,8 @@ public void process(CounterBasket pw) { double avg = meter.getAvg(300); FloatValue value = new FloatValue((float) d); FloatValue avgValue = new FloatValue((float) avg); - pw.getPack(ctx.objName, TimeTypeEnum.REALTIME).put(ctx.counter, value); - pw.getPack(ctx.objName, TimeTypeEnum.FIVE_MIN).put(ctx.counter, avgValue); + pw.getPack(ctx.objName, TimeTypeEnum.REALTIME).add(ctx.counter, value); + pw.getPack(ctx.objName, TimeTypeEnum.FIVE_MIN).add(ctx.counter, avgValue); } } catch (Exception e) { errors.add(ctx.attrName); @@ -268,23 +268,30 @@ private static String checkObjName(String name) { } class CtxObj { - private String objName; - private ObjectName mbean; - private String objType; - private byte valueType; - private String attrName; - private String counter; + public int mbeanHash; + public String objName; + public ObjectName mbean; + public String objType; + public byte valueType; + public String attrName; + public String counter; public CtxObj(String objName, ObjectName mbean, String objType, byte valueType, String attrName, String counter) { this.objName = objName; this.mbean = mbean; + this.mbeanHash = HashUtil.hash(mbean.toString()); this.objType = objType; this.valueType = valueType; this.attrName = attrName; this.counter = counter; } - } + @Override + public String toString() { + return "CtxObj [objName=" + objName + ", mbean=" + mbean + ", objType=" + objType + ", valueType=" + + valueType + ", attrName=" + attrName + ", counter=" + counter + "]"; + } + } } \ No newline at end of file diff --git a/scouter.agent.java/src/scouter/agent/counter/task/TomcatJMXPerf.java b/scouter.agent.java/src/scouter/agent/counter/task/TomcatJMXPerf.java index e0699f197..0abf310d0 100644 --- a/scouter.agent.java/src/scouter/agent/counter/task/TomcatJMXPerf.java +++ b/scouter.agent.java/src/scouter/agent/counter/task/TomcatJMXPerf.java @@ -15,8 +15,8 @@ * limitations under the License. */ -package scouter.agent.counter.task; - +package scouter.agent.counter.task; + import java.lang.management.ManagementFactory; import java.util.ArrayList; import java.util.HashMap; @@ -43,258 +43,267 @@ import scouter.util.CastUtil; import scouter.util.HashUtil; import scouter.util.StringUtil; - -public class TomcatJMXPerf { - - HashMap meters = new HashMap(); - HashMap lastValues = new HashMap(); - private static HashSet deltas = new HashSet(); - - static { - deltas.add(CounterConstants.REQUESTPROCESS_BYTES_RECEIVED); - deltas.add(CounterConstants.REQUESTPROCESS_BYTES_SENT); - deltas.add(CounterConstants.REQUESTPROCESS_ERROR_COUNT); - deltas.add(CounterConstants.REQUESTPROCESS_PROCESSING_TIME); - deltas.add(CounterConstants.REQUESTPROCESS_REQUEST_COUNT); - - ConfObserver.add("TomcatJMXPerf", new Runnable() { - public void run() { - ObjTypeDetector.dirtyConfig=true; - } - }); - } - - private long getDelta(MeterKey key, Long newValue) { - Long oldValue = lastValues.put(key, newValue); - return oldValue == null ? 0 : newValue.longValue() - oldValue.longValue(); - } - - private MeterResource getMeter(MeterKey key) { - MeterResource meter = meters.get(key); - if (meter == null) { - meter = new MeterResource(); - meters.put(key, meter); - } - return meter; - } - - static class MeterKey { - - String objName; - String counter; - - public MeterKey(String objName, String counter) { - this.objName = objName; - this.counter = counter; - } - - public int hashCode() { - return objName.hashCode() ^ counter.hashCode(); - } - - public boolean equals(Object obj) { - if (obj instanceof MeterKey) { - MeterKey key = (MeterKey) obj; - return (this.objName.equals(key.objName)) && (this.counter.equals(key.counter)); - } - return false; - } - } - - private List servers; - private String version; - - List ctxList = new ArrayList(); - - public long collectCnt = 0; - - @Counter - public void process(CounterBasket pw) { - if (CounterConstants.TOMCAT.equals(ObjTypeDetector.objType) == false) { - return; - } - - getMBeanServer(); - - if ((collectCnt <= 40 && collectCnt%5==0) || ObjTypeDetector.dirtyConfig) { + +public class TomcatJMXPerf { + + HashMap meters = new HashMap(); + HashMap lastValues = new HashMap(); + private static HashSet deltas = new HashSet(); + + static { + deltas.add(CounterConstants.REQUESTPROCESS_BYTES_RECEIVED); + deltas.add(CounterConstants.REQUESTPROCESS_BYTES_SENT); + deltas.add(CounterConstants.REQUESTPROCESS_ERROR_COUNT); + deltas.add(CounterConstants.REQUESTPROCESS_PROCESSING_TIME); + deltas.add(CounterConstants.REQUESTPROCESS_REQUEST_COUNT); + + ConfObserver.add("TomcatJMXPerf", new Runnable() { + public void run() { + ObjTypeDetector.dirtyConfig = true; + } + }); + } + + private long getDelta(MeterKey key, Long newValue) { + Long oldValue = lastValues.put(key, newValue); + return oldValue == null ? 0 : newValue.longValue() - oldValue.longValue(); + } + + private MeterResource getMeter(MeterKey key) { + MeterResource meter = meters.get(key); + if (meter == null) { + meter = new MeterResource(); + meters.put(key, meter); + } + return meter; + } + + static class MeterKey { + + int mbeanHash; + String counter; + + public MeterKey(int mbeanHash, String counter) { + this.mbeanHash = mbeanHash; + this.counter = counter; + } + + public int hashCode() { + return mbeanHash ^ counter.hashCode(); + } + + public boolean equals(Object obj) { + if (obj instanceof MeterKey) { + MeterKey key = (MeterKey) obj; + return (this.mbeanHash == key.mbeanHash) && (this.counter.equals(key.counter)); + } + return false; + } + } + + private List servers; + private String version; + + List ctxList = new ArrayList(); + + public long collectCnt = 0; + + @Counter + public void process(CounterBasket pw) { + if (CounterConstants.TOMCAT.equals(ObjTypeDetector.objType) == false) { + return; + } + + getMBeanServer(); + + if ((collectCnt <= 40 && collectCnt % 5 == 0) || ObjTypeDetector.dirtyConfig) { if (ObjTypeDetector.dirtyConfig) { AgentHeartBeat.clearSubObjects(); - ObjTypeDetector.dirtyConfig=false; - } - getContextList(); - } - collectCnt++; - MBeanServer server = servers.get(0); - - for (CtxObj ctx : ctxList) { - if (ctx.valueType == ValueEnum.DECIMAL) { - try { - MeterKey key = new MeterKey(ctx.objName, ctx.counter); - long v = CastUtil.clong(server.getAttribute(ctx.mbean, ctx.attrName)); - if (deltas.contains(ctx.counter)) { - v = getDelta(key, v); - MeterResource meter = getMeter(key); - meter.add(v); - v = (long) meter.getSum(60); - long sum = (long) meter.getSum(300) / 5; - - pw.getPack(ctx.objName, TimeTypeEnum.REALTIME).put(ctx.counter, new DecimalValue(v)); - pw.getPack(ctx.objName, TimeTypeEnum.FIVE_MIN).put(ctx.counter, new DecimalValue(sum)); - } else { - MeterResource meter = getMeter(key); - meter.add(v); - double d = meter.getAvg(30); - double avg = meter.getAvg(300); - FloatValue value = new FloatValue((float) d); - FloatValue avgValue = new FloatValue((float) avg); - pw.getPack(ctx.objName, TimeTypeEnum.REALTIME).put(ctx.counter, value); - pw.getPack(ctx.objName, TimeTypeEnum.FIVE_MIN).put(ctx.counter, avgValue); - } - } catch (Exception e) { - errors.add(ctx.attrName); - collectCnt = 0; - e.printStackTrace(); - } - } - } - - // long cpu2 = SysJMX.getCurrentThreadCPU(); - } - - private HashSet errors = new HashSet(); - - private void getMBeanServer() { - if (servers == null) { - servers = new LinkedList(); - servers.add(ManagementFactory.getPlatformMBeanServer()); - } - } - - Configure conf = Configure.getInstance(); - - private void getContextList() { - ctxList.clear(); - - for (final MBeanServer server : servers) { - Set mbeans = server.queryNames(null, null); - - for (final ObjectName mbean : mbeans) { - String type = mbean.getKeyProperty("type"); - if (type == null) { - continue; - } - if (StringUtil.isEmpty(version) && "Server".equals(type)) { // Server - // Bean - try { - Object value = server.getAttribute(mbean, "serverInfo"); - if (value != null) { - version = value.toString().split("/")[1]; - Logger.info("Tomcat version = " + version); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - if ("GlobalRequestProcessor".equals(type)) { - String port = mbean.getKeyProperty("name"); - try { + ObjTypeDetector.dirtyConfig = false; + } + getContextList(); + } + collectCnt++; + MBeanServer server = servers.get(0); + for (CtxObj ctx : ctxList) { + if (ctx.valueType == ValueEnum.DECIMAL) { + try { + MeterKey key = new MeterKey(ctx.mbeanHash, ctx.counter); + long v = CastUtil.clong(server.getAttribute(ctx.mbean, ctx.attrName)); + if (deltas.contains(ctx.counter)) { + v = getDelta(key, v); + MeterResource meter = getMeter(key); + meter.add(v); + v = (long) meter.getSum(60); + long sum = (long) meter.getSum(300) / 5; + + pw.getPack(ctx.objName, TimeTypeEnum.REALTIME).add(ctx.counter, new DecimalValue(v)); + pw.getPack(ctx.objName, TimeTypeEnum.FIVE_MIN).add(ctx.counter, new DecimalValue(sum)); + } else { + MeterResource meter = getMeter(key); + meter.add(v); + double d = meter.getAvg(30); + double avg = meter.getAvg(300); + FloatValue value = new FloatValue((float) d); + FloatValue avgValue = new FloatValue((float) avg); + pw.getPack(ctx.objName, TimeTypeEnum.REALTIME).add(ctx.counter, value); + pw.getPack(ctx.objName, TimeTypeEnum.FIVE_MIN).add(ctx.counter, avgValue); + } + } catch (Exception e) { + errors.add(ctx.attrName); + collectCnt = 0; + e.printStackTrace(); + } + } + } + + // long cpu2 = SysJMX.getCurrentThreadCPU(); + } + + private HashSet errors = new HashSet(); + + private void getMBeanServer() { + if (servers == null) { + servers = new LinkedList(); + servers.add(ManagementFactory.getPlatformMBeanServer()); + } + } + + Configure conf = Configure.getInstance(); + + private void getContextList() { + ctxList.clear(); + + for (final MBeanServer server : servers) { + Set mbeans = server.queryNames(null, null); + + for (final ObjectName mbean : mbeans) { + String type = mbean.getKeyProperty("type"); + if (type == null) { + continue; + } + if (StringUtil.isEmpty(version) && "Server".equals(type)) { // Server + // Bean + try { + Object value = server.getAttribute(mbean, "serverInfo"); + if (value != null) { + version = value.toString().split("/")[1]; + Logger.info("Tomcat version = " + version); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + if ("GlobalRequestProcessor".equals(type)) { + String port = mbean.getKeyProperty("name"); + try { String objName = conf.objName + "/" + checkObjName(port); - - String objType = getReqProcType(); - AgentHeartBeat.addObject(objType, HashUtil.hash(objName), objName); - add(objName, mbean, objType, ValueEnum.DECIMAL, "bytesReceived", - CounterConstants.REQUESTPROCESS_BYTES_RECEIVED); - add(objName, mbean, objType, ValueEnum.DECIMAL, "bytesSent", - CounterConstants.REQUESTPROCESS_BYTES_SENT); - add(objName, mbean, objType, ValueEnum.DECIMAL, "errorCount", - CounterConstants.REQUESTPROCESS_ERROR_COUNT); - add(objName, mbean, objType, ValueEnum.DECIMAL, "processingTime", - CounterConstants.REQUESTPROCESS_PROCESSING_TIME); - add(objName, mbean, objType, ValueEnum.DECIMAL, "requestCount", - CounterConstants.REQUESTPROCESS_REQUEST_COUNT); - } catch (Exception e) { - } - - } else if ("DataSource".equals(type)) { // datasource - String name = mbean.getKeyProperty("name"); - if (StringUtil.isNotEmpty(name)) { - try { - String objName = conf.objName + "/" + checkObjName(name); - String objType = getDataSourceType(); - - AgentHeartBeat.addObject(objType, HashUtil.hash(objName), objName); - - add(objName, mbean, objType, ValueEnum.DECIMAL, "numActive", - CounterConstants.DATASOURCE_CONN_ACTIVE); - add(objName, mbean, objType, ValueEnum.DECIMAL, "numIdle", - CounterConstants.DATASOURCE_CONN_IDLE); - } catch (Exception e) { - } - } - } - } - } - } - - private String getReqProcType() { - if (Configure.getInstance().enable_plus_objtype) { - return Configure.getInstance().scouter_type + "_req"; - } - return CounterConstants.REQUESTPROCESS; - } - private String getDataSourceType() { - if (Configure.getInstance().enable_plus_objtype) { - return Configure.getInstance().scouter_type + "_ds"; - } - return CounterConstants.DATASOURCE; - } - private void add(String objName, ObjectName mbean, String type, byte decimal, String attrName, String counterName) { - if (errors.contains(attrName)) - return; - CtxObj cObj = new CtxObj(objName, mbean, type, ValueEnum.DECIMAL, attrName, counterName); - ctxList.add(cObj); - } - - private static String checkObjName(String name) { - StringBuffer sb = new StringBuffer(); - char[] charArray = name.toCharArray(); - for (int i = 0; i < charArray.length; i++) { - switch (charArray[i]) { - case '-': - case '_': - sb.append(charArray[i]); - break; - case '/': - sb.append('_'); - break; - default: - if (Character.isLetterOrDigit(charArray[i])) { - sb.append(charArray[i]); - } - } - } - return sb.toString(); - } - - class CtxObj { - private String objName; - private ObjectName mbean; - private String objType; - private byte valueType; - private String attrName; - private String counter; - - public CtxObj(String objName, ObjectName mbean, String objType, byte valueType, String attrName, String counter) { - - this.objName = objName; - this.mbean = mbean; - this.objType = objType; - this.valueType = valueType; - this.attrName = attrName; - this.counter = counter; - } - - } - + + String objType = getReqProcType(); + AgentHeartBeat.addObject(objType, HashUtil.hash(objName), objName); + add(objName, mbean, objType, ValueEnum.DECIMAL, "bytesReceived", + CounterConstants.REQUESTPROCESS_BYTES_RECEIVED); + add(objName, mbean, objType, ValueEnum.DECIMAL, "bytesSent", + CounterConstants.REQUESTPROCESS_BYTES_SENT); + add(objName, mbean, objType, ValueEnum.DECIMAL, "errorCount", + CounterConstants.REQUESTPROCESS_ERROR_COUNT); + add(objName, mbean, objType, ValueEnum.DECIMAL, "processingTime", + CounterConstants.REQUESTPROCESS_PROCESSING_TIME); + add(objName, mbean, objType, ValueEnum.DECIMAL, "requestCount", + CounterConstants.REQUESTPROCESS_REQUEST_COUNT); + } catch (Exception e) { + } + + } else if ("DataSource".equals(type)) { // datasource + String name = mbean.getKeyProperty("name"); + if (StringUtil.isNotEmpty(name)) { + try { + String objName = conf.objName + "/" + checkObjName(name); + String objType = getDataSourceType(); + + AgentHeartBeat.addObject(objType, HashUtil.hash(objName), objName); + + add(objName, mbean, objType, ValueEnum.DECIMAL, "numActive", + CounterConstants.DATASOURCE_CONN_ACTIVE); + add(objName, mbean, objType, ValueEnum.DECIMAL, "numIdle", + CounterConstants.DATASOURCE_CONN_IDLE); + } catch (Exception e) { + } + } + } + } + } + } + + private String getReqProcType() { + if (Configure.getInstance().enable_plus_objtype) { + return Configure.getInstance().scouter_type + "_req"; + } + return CounterConstants.REQUESTPROCESS; + } + + private String getDataSourceType() { + if (Configure.getInstance().enable_plus_objtype) { + return Configure.getInstance().scouter_type + "_ds"; + } + return CounterConstants.DATASOURCE; + } + + private void add(String objName, ObjectName mbean, String type, byte decimal, String attrName, String counterName) { + if (errors.contains(attrName)) + return; + CtxObj cObj = new CtxObj(objName, mbean, type, ValueEnum.DECIMAL, attrName, counterName); + ctxList.add(cObj); + } + + private static String checkObjName(String name) { + StringBuffer sb = new StringBuffer(); + char[] charArray = name.toCharArray(); + for (int i = 0; i < charArray.length; i++) { + switch (charArray[i]) { + case '-': + case '_': + sb.append(charArray[i]); + break; + case '/': + sb.append('_'); + break; + default: + if (Character.isLetterOrDigit(charArray[i])) { + sb.append(charArray[i]); + } + } + } + return sb.toString(); + } + + class CtxObj { + public int mbeanHash; + public String objName; + public ObjectName mbean; + public String objType; + public byte valueType; + public String attrName; + public String counter; + + public CtxObj(String objName, ObjectName mbean, String objType, byte valueType, String attrName, String counter) { + + this.objName = objName; + this.mbean = mbean; + this.mbeanHash = HashUtil.hash(mbean.toString()); + this.objType = objType; + this.valueType = valueType; + this.attrName = attrName; + this.counter = counter; + } + + @Override + public String toString() { + return "CtxObj [objName=" + objName + ", mbean=" + mbean + ", objType=" + objType + ", valueType=" + + valueType + ", attrName=" + attrName + ", counter=" + counter + "]"; + } + + } + } \ No newline at end of file diff --git a/scouter.agent.java/src/scouter/agent/trace/TraceMain.java b/scouter.agent.java/src/scouter/agent/trace/TraceMain.java index 206345a34..c672f60d6 100644 --- a/scouter.agent.java/src/scouter/agent/trace/TraceMain.java +++ b/scouter.agent.java/src/scouter/agent/trace/TraceMain.java @@ -552,6 +552,9 @@ public static void capReturn(String className, String methodName, String methodD private static Configure conf = Configure.getInstance(); public static Object startMethod(int hash, String classMethod) { + if(conf.trace_method_enabled==false) + return null; + TraceContext ctx = TraceContextManager.getLocalContext(); if (ctx == null) { if (conf.enable_auto_service_trace) { diff --git a/scouter.client/src/scouter/client/popup/SummaryDialog.java b/scouter.client/src/scouter/client/popup/SummaryDialog.java index 0d0331788..0f747a0ea 100644 --- a/scouter.client/src/scouter/client/popup/SummaryDialog.java +++ b/scouter.client/src/scouter/client/popup/SummaryDialog.java @@ -32,6 +32,7 @@ public class SummaryDialog { TabItem apicallTab; TabItem ipTab; TabItem userAgentTab; + TabItem errorTab; public SummaryDialog(int serverId, MapPack param) { this.serverId = serverId; diff --git a/scouter.client/src/scouter/client/summary/modules/ErrorSummaryComposite.java b/scouter.client/src/scouter/client/summary/modules/ErrorSummaryComposite.java new file mode 100644 index 000000000..0022cf645 --- /dev/null +++ b/scouter.client/src/scouter/client/summary/modules/ErrorSummaryComposite.java @@ -0,0 +1,518 @@ +package scouter.client.summary.modules; + +import java.util.ArrayList; +import java.util.List; + +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.jface.action.Action; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.layout.TableColumnLayout; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ColumnWeightData; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.TableViewerColumn; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.TextTransfer; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowData; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableColumn; +import org.eclipse.swt.widgets.TableItem; + +import scouter.client.Images; +import scouter.client.model.TextProxy; +import scouter.client.net.TcpProxy; +import scouter.client.popup.CalendarDialog; +import scouter.client.popup.CalendarDialog.ILoadCounterDialog; +import scouter.client.sorter.ColumnLabelSorter; +import scouter.client.util.ExUtil; +import scouter.client.util.TimeUtil; +import scouter.lang.pack.MapPack; +import scouter.lang.pack.Pack; +import scouter.lang.value.ListValue; +import scouter.net.RequestCmd; +import scouter.util.DateUtil; +import scouter.util.FormatUtil; + +public class ErrorSummaryComposite extends Composite { + + public static final String[] HOURLY_TIMES = {"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24"}; + public static final String[] FIVE_MIN_TIMES = {"00", "05", "10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60"}; + + Composite parent; + int serverId; + MapPack param; + + Label dateLbl; + Combo startHHCmb; + Combo startMMCmb; + Combo endHHCmb; + Combo endMMCmb; + + private TableViewer viewer; + private TableColumnLayout tableColumnLayout; + private Clipboard clipboard; + + String date = DateUtil.yyyymmdd(); + + public ErrorSummaryComposite(Composite parent, int style) { + super(parent, style); + this.parent = parent; + } + + public void setData(int serverId, MapPack param) { + this.serverId = serverId; + this.param = param; + initLayout(); + } + + private void initLayout() { + this.setLayout(new GridLayout(1, true)); + Composite upperComp = new Composite(this, SWT.NONE); + upperComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + upperComp.setLayout(new GridLayout(6, false)); + + long now = TimeUtil.getCurrentTime(serverId); + + GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); + dateLbl = new Label(upperComp, SWT.CENTER | SWT.BORDER); + dateLbl.setLayoutData(gd); + dateLbl.addMouseListener(new MouseAdapter() { + public void mouseDown(MouseEvent e) { + CalendarDialog dialog = new CalendarDialog(parent.getDisplay(), new ILoadCounterDialog(){ + public void onPressedOk(long startTime, long endTime) {} + public void onPressedCancel() {} + public void onPressedOk(String date) { + ErrorSummaryComposite.this.date = date; + dateLbl.setText(DateUtil.format(DateUtil.yyyymmdd(date), "yyyy-MM-dd")); + + } + }); + dialog.show(-1, -1, DateUtil.yyyymmdd(date)); + } + + }); + dateLbl.setText(DateUtil.format(now, "yyyy-MM-dd")); + + Composite startCmbComp = new Composite(upperComp, SWT.NONE); + startCmbComp.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + startCmbComp.setLayout(new RowLayout()); + + + long start = now - DateUtil.MILLIS_PER_FIVE_MINUTE; + + startHHCmb = new Combo(startCmbComp, SWT.VERTICAL | SWT.BORDER | SWT.READ_ONLY); + startHHCmb.setLayoutData(new RowData(50, SWT.DEFAULT)); + startHHCmb.setItems(HOURLY_TIMES); + startHHCmb.setText(DateUtil.format(start, "HH")); + + startMMCmb = new Combo(startCmbComp, SWT.VERTICAL | SWT.BORDER | SWT.READ_ONLY); + startMMCmb.setLayoutData(new RowData(50, SWT.DEFAULT)); + startMMCmb.setItems(FIVE_MIN_TIMES); + startMMCmb.setText(DateUtil.format(start / DateUtil.MILLIS_PER_FIVE_MINUTE * DateUtil.MILLIS_PER_FIVE_MINUTE, "mm")); + + Label label = new Label(upperComp, SWT.NONE); + label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); + label.setAlignment(SWT.CENTER); + label.setText("to"); + + Composite endCmbComp = new Composite(upperComp, SWT.NONE); + endCmbComp.setLayoutData(new GridData(SWT.CENTER, SWT.FILL, true, false)); + endCmbComp.setLayout(new RowLayout()); + + endHHCmb = new Combo(endCmbComp, SWT.VERTICAL | SWT.BORDER | SWT.READ_ONLY); + endHHCmb.setLayoutData(new RowData(50, SWT.DEFAULT)); + endHHCmb.setItems(HOURLY_TIMES); + endHHCmb.setText(DateUtil.format(now, "HH")); + + endMMCmb = new Combo(endCmbComp, SWT.VERTICAL | SWT.BORDER | SWT.READ_ONLY); + endMMCmb.setLayoutData(new RowData(50, SWT.DEFAULT)); + endMMCmb.setItems(FIVE_MIN_TIMES); + endMMCmb.setText(DateUtil.format(now / DateUtil.MILLIS_PER_FIVE_MINUTE * DateUtil.MILLIS_PER_FIVE_MINUTE, "mm")); + + final Button getBtn = new Button(upperComp, SWT.PUSH); + gd = new GridData(SWT.FILL, SWT.CENTER, true, false); + getBtn.setLayoutData(gd); + getBtn.setText("&GET"); + getBtn.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + long stime = DateUtil.getTime(date + startHHCmb.getText() + startMMCmb.getText(), "yyyyMMddHHmm"); + long etime = DateUtil.getTime(date + endHHCmb.getText() + endMMCmb.getText(), "yyyyMMddHHmm") - 1; + if (stime >= etime) { + MessageDialog.openWarning(parent.getShell(), "Warning", "Wrong range"); + return; + } + param.put("date", date); + param.put("stime", stime); + param.put("etime", etime); + new LoadErrorSummaryJob(param).schedule(); + } + }); + + final Button clearBtn = new Button(upperComp, SWT.PUSH); + gd = new GridData(SWT.FILL, SWT.CENTER, true, false); + clearBtn.setLayoutData(gd); + clearBtn.setText("&CLEAR"); + clearBtn.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + viewer.getTable().removeAll(); + } + }); + + Composite tableComp = new Composite(this, SWT.NONE); + gd = new GridData(SWT.FILL, SWT.FILL, true, true); + gd.widthHint = 800; + gd.heightHint = 400; + tableComp.setLayoutData(gd); + createTableViewer(tableComp); + } + + private void createTableViewer(Composite composite) { + viewer = new TableViewer(composite, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.H_SCROLL); + tableColumnLayout = new TableColumnLayout(); + composite.setLayout(tableColumnLayout); + createColumns(); + final Table table = viewer.getTable(); + table.setHeaderVisible(true); + table.setLinesVisible(true); + createTableContextMenu(); + viewer.setContentProvider(new ArrayContentProvider()); + viewer.setComparator(new ColumnLabelSorter(viewer)); + GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true); + viewer.getControl().setLayoutData(gridData); + } + + private void createTableContextMenu() { + MenuManager manager = new MenuManager(); + viewer.getControl().setMenu(manager.createContextMenu(viewer.getControl())); + manager.add(new Action("&Copy", ImageDescriptor.createFromImage(Images.copy)) { + public void run() { + copyToClipboard(viewer.getTable().getSelection()); + } + }); + viewer.getTable().addListener(SWT.KeyDown, new Listener() { + public void handleEvent(Event e) { + if(e.stateMask == SWT.CTRL || e.stateMask == SWT.COMMAND){ + switch(e.keyCode) { + case 'c': + case 'C': + TableItem[] items = viewer.getTable().getSelection(); + if (items == null || items.length < 1) { + return; + } + copyToClipboard(items); + break; + case 'a': + case 'A': + viewer.getTable().selectAll(); + break; + } + } + } + }); + } + + private void copyToClipboard(TableItem[] items) { + if (viewer != null) { + int colCnt = viewer.getTable().getColumnCount(); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < colCnt; i++) { + TableColumn column = viewer.getTable().getColumn(i); + sb.append(column.getText()); + if (i == colCnt - 1) { + sb.append("\n"); + } else { + sb.append("\t"); + } + } + if (items != null && items.length > 0) { + for (TableItem item : items) { + for (int i = 0; i < colCnt; i++) { + sb.append(item.getText(i)); + if (i == colCnt - 1) { + sb.append("\n"); + } else { + sb.append("\t"); + } + } + } + clipboard.setContents(new Object[] {sb.toString()}, new Transfer[] {TextTransfer.getInstance()}); + } + } + } + + private void createColumns() { + for (ServiceColumnEnum column : ServiceColumnEnum.values()) { + TableViewerColumn c = createTableViewerColumn(column.getTitle(), column.getWidth(), column.getAlignment(), column.isResizable(), column.isMoveable(), column.isNumber()); + ColumnLabelProvider labelProvider = null; + switch (column) { + case SERVICE: + labelProvider = new ColumnLabelProvider() { + @Override + public String getText(Object element) { + if (element instanceof SummaryData) { + return TextProxy.service.getText(((SummaryData) element).hash); + } + return null; + } + }; + break; + case COUNT: + labelProvider = new ColumnLabelProvider() { + @Override + public String getText(Object element) { + if (element instanceof SummaryData) { + return FormatUtil.print(((SummaryData) element).count, "#,##0"); + } + return null; + } + }; + break; + case ERROR_COUNT: + labelProvider = new ColumnLabelProvider() { + @Override + public String getText(Object element) { + if (element instanceof SummaryData) { + return FormatUtil.print(((SummaryData) element).errorCount, "#,##0"); + } + return null; + } + }; + break; + case ELAPSED_SUM: + labelProvider = new ColumnLabelProvider() { + @Override + public String getText(Object element) { + if (element instanceof SummaryData) { + return FormatUtil.print(((SummaryData) element).elapsedSum, "#,##0"); + } + return null; + } + }; + break; + case ELAPSED_AVG: + labelProvider = new ColumnLabelProvider() { + @Override + public String getText(Object element) { + if (element instanceof SummaryData) { + SummaryData data = (SummaryData) element; + return FormatUtil.print(data.elapsedSum / (double) data.count , "#,##0"); + } + return null; + } + }; + break; + case CPU_SUM: + labelProvider = new ColumnLabelProvider() { + @Override + public String getText(Object element) { + if (element instanceof SummaryData) { + return FormatUtil.print(((SummaryData) element).cpu, "#,##0"); + } + return null; + } + }; + break; + case CPU_AVG: + labelProvider = new ColumnLabelProvider() { + @Override + public String getText(Object element) { + if (element instanceof SummaryData) { + SummaryData data = (SummaryData) element; + return FormatUtil.print(data.cpu / (double) data.count , "#,##0"); + } + return null; + } + }; + break; + case MEM_SUM: + labelProvider = new ColumnLabelProvider() { + @Override + public String getText(Object element) { + if (element instanceof SummaryData) { + return FormatUtil.print(((SummaryData) element).mem, "#,##0"); + } + return null; + } + }; + break; + case MEM_AVG: + labelProvider = new ColumnLabelProvider() { + @Override + public String getText(Object element) { + if (element instanceof SummaryData) { + SummaryData data = (SummaryData) element; + return FormatUtil.print(data.mem / (double) data.count , "#,##0"); + } + return null; + } + }; + break; + } + if (labelProvider != null) { + c.setLabelProvider(labelProvider); + } + } + } + + private TableViewerColumn createTableViewerColumn(String title, int width, int alignment, boolean resizable, boolean moveable, final boolean isNumber) { + final TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE); + final TableColumn column = viewerColumn.getColumn(); + column.setText(title); + column.setAlignment(alignment); + column.setMoveable(moveable); + tableColumnLayout.setColumnData(column, new ColumnWeightData(30, width, resizable)); + column.setData("isNumber", isNumber); + column.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + ColumnLabelSorter sorter = (ColumnLabelSorter) viewer.getComparator(); + TableColumn selectedColumn = (TableColumn) e.widget; + sorter.setColumn(selectedColumn); + } + }); + return viewerColumn; + } + + enum ServiceColumnEnum { + + SERVICE("Error", 150, SWT.CENTER, true, true, false), + COUNT("Count", 70, SWT.RIGHT, true, true, true), + ERROR_COUNT("Error", 70, SWT.RIGHT, true, true, true), + ELAPSED_SUM("Total Elapsed(ms)", 150, SWT.RIGHT, true, true, true), + ELAPSED_AVG("Avg Elapsed(ms)", 150, SWT.RIGHT, true, true, true), + CPU_SUM("Total Cpu(ms)", 100, SWT.RIGHT, true, true, true), + CPU_AVG("Avg Cpu(ms)", 100, SWT.RIGHT, true, true, true), + MEM_SUM("Total Mem(bytes)", 150, SWT.RIGHT, true, true, true), + MEM_AVG("Avg Mem(bytes)", 150, SWT.RIGHT, true, true, true); + + private final String title; + private final int width; + private final int alignment; + private final boolean resizable; + private final boolean moveable; + private final boolean isNumber; + + private ServiceColumnEnum(String text, int width, int alignment, boolean resizable, boolean moveable, boolean isNumber) { + this.title = text; + this.width = width; + this.alignment = alignment; + this.resizable = resizable; + this.moveable = moveable; + this.isNumber = isNumber; + } + + public String getTitle(){ + return title; + } + + public int getAlignment(){ + return alignment; + } + + public boolean isResizable(){ + return resizable; + } + + public boolean isMoveable(){ + return moveable; + } + + public int getWidth() { + return width; + } + + public boolean isNumber() { + return this.isNumber; + } + } + + class LoadErrorSummaryJob extends Job { + + MapPack param; + + public LoadErrorSummaryJob(MapPack param) { + super("Loading..."); + this.param = param; + } + + protected IStatus run(IProgressMonitor monitor) { + TcpProxy tcp = TcpProxy.getTcpProxy(serverId); + Pack p = null; + try { + p = tcp.getSingle(RequestCmd.LOAD_SERVICE_ERROR_SUMMARY, param); + } catch (Exception e) { + e.printStackTrace(); + return Status.CANCEL_STATUS; + } finally { + TcpProxy.putTcpProxy(tcp); + } + + if (p != null) { + final List list = new ArrayList(); + MapPack m = (MapPack) p; + ListValue idLv = m.getList("id"); + ListValue errorLv = m.getList("error"); + ListValue serviceLv = m.getList("service"); + ListValue countLv = m.getList("count"); + ListValue txidLv = m.getList("txid"); + ListValue sqlLv = m.getList("sql"); + ListValue apiLv = m.getList("apicall"); + ListValue stackLv = m.getList("fullstack"); + for (int i = 0; i < idLv.size(); i++) { + ErrorData data = new ErrorData(); + data.error = errorLv.getInt(i); + data.service = serviceLv.getInt(i); + data.count = countLv.getInt(i); + data.txid = txidLv.getLong(i); + data.sql = sqlLv.getInt(i); + data.apicall = apiLv.getInt(i); + data.fullstack = stackLv.getInt(i); + list.add(data); + } + + TextProxy.error.load(date, errorLv, serverId); + TextProxy.error.load(date, stackLv, serverId); + TextProxy.sql.load(date, sqlLv, serverId); + TextProxy.apicall.load(date, apiLv, serverId); + + ExUtil.exec(viewer.getTable(), new Runnable() { + public void run() { + viewer.setInput(list); + } + }); + } + + return Status.OK_STATUS; + } + } + + private static class ErrorData { + public int error; + public int service; + public int count; + public long txid; + public int sql; + public int apicall; + public int fullstack; + } +} diff --git a/scouter.common/src/scouter/io/DataInputX.java b/scouter.common/src/scouter/io/DataInputX.java index 451690f49..aee1740da 100644 --- a/scouter.common/src/scouter/io/DataInputX.java +++ b/scouter.common/src/scouter/io/DataInputX.java @@ -137,24 +137,6 @@ public long readDecimal() throws IOException { } } - public static void main(String[] args) throws IOException { - DataOutputX out = new DataOutputX(); - long x = (long) Integer.MIN_VALUE - 10000; - out.writeLong5(x); - out.writeInt(10); - out.writeInt3(-1); - byte[] b = out.toByteArray(); - - DataInputX in = new DataInputX(b); - // int i = in.readInt(); - // String s = in.readUTF(); - long j = in.readLong5(); - int i = in.readInt(); - int k = in.readInt3(); - System.out.println(j + " " + x); - - } - public String readText() throws IOException { byte[] buffer = readBlob(); return new String(buffer, "UTF8"); diff --git a/scouter.common/src/scouter/io/DataOutputX.java b/scouter.common/src/scouter/io/DataOutputX.java index abce55def..a779966e8 100644 --- a/scouter.common/src/scouter/io/DataOutputX.java +++ b/scouter.common/src/scouter/io/DataOutputX.java @@ -71,12 +71,14 @@ public DataOutputX(DataOutputStream out) { public DataOutputX(RandomAccessFile out) { this.inner = out; } + public DataOutputX writeIntBytes(byte[] b) throws IOException { this.writeInt(b.length); this.write(b); return this; } + public DataOutputX writeShortBytes(byte[] b) throws IOException { this.writeShort(b.length); this.write(b); @@ -98,12 +100,14 @@ public DataOutputX writeBlob(byte[] value, int offset, int length) throws IOExce writeByte((byte) len); write(value, offset, len); } else if (len <= 65535) { - writeByte((byte) 255); - writeShort((short) len); + byte[] buff = new byte[3]; + buff[0] = (byte) 255; + write(toBytes(buff, 1, (short) len)); write(value, offset, len); } else { - writeByte((byte) 254); - writeInt(len); + byte[] buff = new byte[5]; + buff[0] = (byte) 254; + write(toBytes(buff, 1, len)); write(value, offset, len); } } @@ -119,12 +123,14 @@ public DataOutputX writeBlob(byte[] value) throws IOException { writeByte((byte) len); write(value); } else if (len <= 65535) { - writeByte((byte) 255); - writeShort((short) len); + byte[] buff = new byte[3]; + buff[0] = (byte) 255; + write(toBytes(buff, 1, (short) len)); write(value); } else { - writeByte((byte) 254); - writeInt(len); + byte[] buff = new byte[5]; + buff[0] = (byte) 254; + write(toBytes(buff, 1, len)); write(value); } } @@ -163,23 +169,31 @@ public DataOutputX writeDecimal(long v) throws IOException { if (v == 0) { writeByte(0); } else if (Byte.MIN_VALUE <= v && v <= Byte.MAX_VALUE) { - writeByte(1); - writeByte((byte) v); + byte[] b = new byte[2]; + b[0] = 1; + b[1] = (byte) v; + write(b); } else if (Short.MIN_VALUE <= v && v <= Short.MAX_VALUE) { - writeByte(2); - writeShort((short) v); + byte[] b = new byte[3]; + b[0] = 2; + toBytes(b, 1, (short) v); + write(b); } else if (INT3_MIN_VALUE <= v && v <= INT3_MAX_VALUE) { - writeByte(3); - writeInt3((int) v); + byte[] b = new byte[4]; + b[0] = 3; + write(toBytes3(b, 1, (int) v), 0, 4); } else if (Integer.MIN_VALUE <= v && v <= Integer.MAX_VALUE) { - writeByte(4); - writeInt((int) v); + byte[] b = new byte[5]; + b[0] = 4; + write(toBytes(b, 1, (int) v), 0, 5); } else if (LONG5_MIN_VALUE <= v && v <= LONG5_MAX_VALUE) { - writeByte(5); - writeLong5(v); + byte[] b = new byte[6]; + b[0] = 5; + write(toBytes5(b, 1, v), 0, 6); } else if (Long.MIN_VALUE <= v && v <= Long.MAX_VALUE) { - writeByte(8); - writeLong(v); + byte[] b = new byte[9]; + b[0] = 8; + write(toBytes(b, 1, v), 0, 9); } return this; } @@ -197,6 +211,12 @@ public static byte[] toBytes(short v) { return buf; } + public static byte[] toBytes(byte[] buf, int off, short v) { + buf[off] = (byte) ((v >>> 8) & 0xFF); + buf[off + 1] = (byte) ((v >>> 0) & 0xFF); + return buf; + } + public static byte[] toBytes(int v) { byte buf[] = new byte[4]; buf[0] = (byte) ((v >>> 24) & 0xFF); @@ -206,6 +226,14 @@ public static byte[] toBytes(int v) { return buf; } + public static byte[] toBytes(byte[] buf, int off, int v) { + buf[off] = (byte) ((v >>> 24) & 0xFF); + buf[off + 1] = (byte) ((v >>> 16) & 0xFF); + buf[off + 2] = (byte) ((v >>> 8) & 0xFF); + buf[off + 3] = (byte) ((v >>> 0) & 0xFF); + return buf; + } + public static byte[] toBytes3(int v) { byte buf[] = new byte[3]; buf[0] = (byte) ((v >>> 16) & 0xFF); @@ -214,6 +242,13 @@ public static byte[] toBytes3(int v) { return buf; } + public static byte[] toBytes3(byte[] buf, int off, int v) { + buf[off] = (byte) ((v >>> 16) & 0xFF); + buf[off + 1] = (byte) ((v >>> 8) & 0xFF); + buf[off + 2] = (byte) ((v >>> 0) & 0xFF); + return buf; + } + public static byte[] toBytes(long v) { byte buf[] = new byte[8]; buf[0] = (byte) (v >>> 56); @@ -227,6 +262,18 @@ public static byte[] toBytes(long v) { return buf; } + public static byte[] toBytes(byte[] buf, int off, long v) { + buf[off] = (byte) (v >>> 56); + buf[off + 1] = (byte) (v >>> 48); + buf[off + 2] = (byte) (v >>> 40); + buf[off + 3] = (byte) (v >>> 32); + buf[off + 4] = (byte) (v >>> 24); + buf[off + 5] = (byte) (v >>> 16); + buf[off + 6] = (byte) (v >>> 8); + buf[off + 7] = (byte) (v >>> 0); + return buf; + } + public static byte[] toBytes5(long v) { byte writeBuffer[] = new byte[5]; writeBuffer[0] = (byte) (v >>> 32); @@ -237,6 +284,15 @@ public static byte[] toBytes5(long v) { return writeBuffer; } + public static byte[] toBytes5(byte[] buf, int off, long v) { + buf[off] = (byte) (v >>> 32); + buf[off + 1] = (byte) (v >>> 24); + buf[off + 2] = (byte) (v >>> 16); + buf[off + 3] = (byte) (v >>> 8); + buf[off + 4] = (byte) (v >>> 0); + return buf; + } + public static byte[] toBytes(boolean b) { if (b) return new byte[] { 1 }; @@ -244,14 +300,30 @@ public static byte[] toBytes(boolean b) { return new byte[] { 0 }; } + public static byte[] toBytes(byte[] buf, int off, boolean b) { + if (b) + buf[off] = 1; + else + buf[off] = 0; + return buf; + } + public static byte[] toBytes(float v) { return toBytes(Float.floatToIntBits(v)); } + public static byte[] toBytes(byte[] buf, int off, float v) { + return toBytes(buf, off, Float.floatToIntBits(v)); + } + public static byte[] toBytes(double v) { return toBytes(Double.doubleToLongBits(v)); } + public static byte[] toBytes(byte[] buf, int off, double v) { + return toBytes(buf, off, Double.doubleToLongBits(v)); + } + public static byte[] set(byte[] dest, int pos, byte[] src) { System.arraycopy(src, 0, dest, pos, src.length); return dest; @@ -317,8 +389,6 @@ public DataOutputX writeArray(float[] v) throws IOException { return this; } - - public DataOutputX writeValue(Value value) throws IOException { if (value == null) value = NullValue.value; @@ -327,15 +397,12 @@ public DataOutputX writeValue(Value value) throws IOException { return this; } - - public DataOutputX writeStep(Step step) throws IOException { this.writeByte(step.getStepType()); step.write(this); return this; } - public DataOutputX writePack(Pack packet) throws IOException { this.writeByte(packet.getPackType()); packet.write(this); @@ -362,13 +429,13 @@ public DataOutputX writeBoolean(boolean v) throws IOException { public DataOutputX writeByte(int v) throws IOException { this.written++; - this.inner.writeByte(v); + this.inner.writeByte((byte) v); return this; } public DataOutputX writeShort(int v) throws IOException { this.written += 2; - this.inner.writeShort(v); + this.inner.write(toBytes((short) v)); return this; } @@ -380,25 +447,25 @@ public DataOutputX writeChar(int v) throws IOException { public DataOutputX writeInt(int v) throws IOException { this.written += 4; - this.inner.writeInt(v); + this.inner.write(toBytes(v)); return this; } public DataOutputX writeLong(long v) throws IOException { this.written += 8; - this.inner.writeLong(v); + this.inner.write(toBytes(v)); return this; } public DataOutputX writeFloat(float v) throws IOException { this.written += 4; - this.inner.writeFloat(v); + this.inner.write(toBytes(v)); return this; } public DataOutputX writeDouble(double v) throws IOException { this.written += 8; - this.inner.writeDouble(v); + this.inner.write(toBytes(v)); return this; } @@ -424,13 +491,4 @@ public void flush() throws IOException { } } - public static void main(String[] args) throws IOException { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - DataOutputX dout = new DataOutputX(out); - dout.writeInt(100); - // dout.flush(); - byte[] b = ((ByteArrayOutputStream) out).toByteArray(); - DataInputX din = new DataInputX(b); - System.out.println(din.readInt()); - } } \ No newline at end of file diff --git a/scouter.common/src/scouter/lang/pack/PerfCounterPack.java b/scouter.common/src/scouter/lang/pack/PerfCounterPack.java index 00a4f1a1d..0f657593d 100644 --- a/scouter.common/src/scouter/lang/pack/PerfCounterPack.java +++ b/scouter.common/src/scouter/lang/pack/PerfCounterPack.java @@ -23,6 +23,7 @@ import scouter.io.DataOutputX; import scouter.lang.TimeTypeEnum; import scouter.lang.value.MapValue; +import scouter.lang.value.NumberValue; import scouter.lang.value.Value; import scouter.util.DateUtil; @@ -65,4 +66,12 @@ public void put(String key, Value value) { this.data.put(key, value); } + public void add(String key, NumberValue value) { + Value old = this.data.get(key); + if (old == null) { + this.data.put(key, value); + } else if (old instanceof NumberValue) { + ((NumberValue) old).add(value); + } + } } \ No newline at end of file diff --git a/scouter.deploy/build.xml b/scouter.deploy/build.xml index f23266f19..56366e296 100644 --- a/scouter.deploy/build.xml +++ b/scouter.deploy/build.xml @@ -4,7 +4,7 @@ - + diff --git a/scouter.server/src/scouter/server/Configure.java b/scouter.server/src/scouter/server/Configure.java index 9c408b63b..b9a948183 100644 --- a/scouter.server/src/scouter/server/Configure.java +++ b/scouter.server/src/scouter/server/Configure.java @@ -141,8 +141,8 @@ public synchronized boolean reload(boolean force) { public int agent_deadtime = 8000; - public boolean gzip_xlog = true; - public boolean gzip_profile = true; + public boolean gzip_xlog = false; + public boolean gzip_profile = false; public int gzip_writing_block = 3; public int gzip_read_cache_block = 3; public long gzip_read_cache_time = DateUtil.MILLIS_PER_MINUTE; diff --git a/scouter.server/src/scouter/server/db/SummaryWR.scala b/scouter.server/src/scouter/server/db/SummaryWR.scala index 725754219..554893239 100644 --- a/scouter.server/src/scouter/server/db/SummaryWR.scala +++ b/scouter.server/src/scouter/server/db/SummaryWR.scala @@ -104,7 +104,7 @@ object SummaryWR { def getDBPath(date: String): String = { val sb = new StringBuffer(); sb.append(DBCtr.getRootPath()); - sb.append("/").append(date).append("/").append(); + sb.append("/").append(date).append("/").append(root); return sb.toString(); } }