From 57da8633dde56cad9bd8e917ccc24ec064e3d194 Mon Sep 17 00:00:00 2001 From: ScouterProject Date: Tue, 14 Jul 2015 20:33:58 +0900 Subject: [PATCH] refactoring tagcnt --- .../src/scouter/client/tags/TagCount.java | 7 +- .../src/scouter/client/tags/TagCountUtil.java | 62 +++---- .../src/scouter/client/tags/TagCountView.java | 171 +++++++++--------- .../StatusConstants.java | 2 +- .../scouter/lang/constants/TagConstants.java | 27 +++ .../netio/service/handle/MariaService.scala | 2 +- .../service/handle/TagCountService.scala | 77 ++++---- .../server/tagcnt/TagCountConfig.scala | 59 +++--- .../tagcnt/core/MoveToNextCollector.scala | 2 +- 9 files changed, 220 insertions(+), 189 deletions(-) rename scouter.common/src/scouter/lang/{counters => constants}/StatusConstants.java (96%) create mode 100644 scouter.common/src/scouter/lang/constants/TagConstants.java diff --git a/scouter.client/src/scouter/client/tags/TagCount.java b/scouter.client/src/scouter/client/tags/TagCount.java index 427f00d60..44c18c534 100644 --- a/scouter.client/src/scouter/client/tags/TagCount.java +++ b/scouter.client/src/scouter/client/tags/TagCount.java @@ -42,5 +42,10 @@ protected int getChildSize() { if (childs == null) return 0; return childs.size(); } - + + @Override + public String toString() { + return "TagCount [tagName=" + tagName + ", value=" + value + ", count=" + + count + ", childs size = " + (childs == null ? "null" : childs.size()) + "]"; + } } diff --git a/scouter.client/src/scouter/client/tags/TagCountUtil.java b/scouter.client/src/scouter/client/tags/TagCountUtil.java index 8b0eabbe1..2f9020f79 100644 --- a/scouter.client/src/scouter/client/tags/TagCountUtil.java +++ b/scouter.client/src/scouter/client/tags/TagCountUtil.java @@ -20,6 +20,7 @@ import scouter.client.model.TextProxy; import scouter.lang.AlertLevel; +import scouter.lang.constants.TagConstants; import scouter.lang.value.DecimalValue; import scouter.lang.value.IP4Value; import scouter.lang.value.ListValue; @@ -42,55 +43,48 @@ public static List loadTagString(int serverId, String date, List for (Value v : vList) { lv.add(CastUtil.cint(v.toJavaObject())); } - if (tagName.equals("object")){ + if (tagName.equals(TagConstants.NAME_OBJECT)){ TextProxy.object.load(date, lv, serverId); for (int i = 0; i < lv.size(); i++) { resultList.add(TextProxy.object.getText(lv.getInt(i))); } - } else if (tagName.equals("service") || tagName.startsWith("service-")) { + } else if (tagName.equals(TagConstants.NAME_SERVICE) + || tagName.equals(TagConstants.NAME_SERVICE_ELAPSED) + || tagName.equals(TagConstants.NAME_SERVICE_BYTES) + || tagName.equals(TagConstants.NAME_SERVICE_ERRORS)) { TextProxy.service.load(date, lv, serverId); for (int i = 0; i < lv.size(); i++) { resultList.add(TextProxy.service.getText(lv.getInt(i))); } - } else if (tagName.equals("user-agent")) { + } else if (tagName.equals(TagConstants.NAME_USER_AGENT)) { TextProxy.userAgent.load(date, lv, serverId); for (int i = 0; i < lv.size(); i++) { resultList.add(TextProxy.userAgent.getText(lv.getInt(i))); } - } else if (tagName.equals("group")) { + } else if (tagName.equals(TagConstants.NAME_GROUP)) { TextProxy.group.load(date, lv, serverId); for (int i = 0; i < lv.size(); i++) { resultList.add(TextProxy.group.getText(lv.getInt(i))); } - } else if (tagName.equals("city")) { + } else if (tagName.equals(TagConstants.NAME_CITY)) { TextProxy.city.load(date, lv, serverId); for (int i = 0; i < lv.size(); i++) { resultList.add(TextProxy.city.getText(lv.getInt(i))); } - } else if (tagName.equals("referer")) { + } else if (tagName.equals(TagConstants.NAME_REFERER)) { TextProxy.referer.load(date, lv, serverId); for (int i = 0; i < lv.size(); i++) { resultList.add(TextProxy.referer.getText(lv.getInt(i))); } - } else if (tagName.equals("error")) { + } else if (tagName.equals(TagConstants.NAME_ERROR)) { TextProxy.error.load(date, lv, serverId); for (int i = 0; i < lv.size(); i++) { resultList.add(TextProxy.error.getText(lv.getInt(i))); } - } else if (tagName.equals("sql")) { - TextProxy.sql.load(date, lv, serverId); - for (int i = 0; i < lv.size(); i++) { - resultList.add(TextProxy.sql.getText(lv.getInt(i))); - } - } else if (tagName.equals("apicall")) { - TextProxy.apicall.load(date, lv, serverId); - for (int i = 0; i < lv.size(); i++) { - resultList.add(TextProxy.apicall.getText(lv.getInt(i))); - } } break; case ValueEnum.DECIMAL: - if (tagName.equals("level")) { + if (tagName.equals(TagConstants.NAME_LEVEL)) { for (Value v : vList) { resultList.add(AlertLevel.getName((byte)((DecimalValue)v).value)); } @@ -120,25 +114,25 @@ public static List loadTagString(int serverId, String date, List } public static Value convertTagToValue(String tagName, String tagValue) { - if (tagName.equals("object") - || tagName.equals("service") - || tagName.startsWith("service-") - || tagName.equals("group") - || tagName.equals("user-agent") - || tagName.equals("referer") - || tagName.equals("city") - || tagName.equals("error") - || tagName.equals("object") - || tagName.equals("object")) { + if (tagName.equals(TagConstants.NAME_OBJECT) + || tagName.equals(TagConstants.NAME_SERVICE) + || tagName.equals(TagConstants.NAME_SERVICE_ELAPSED) + || tagName.equals(TagConstants.NAME_SERVICE_BYTES) + || tagName.equals(TagConstants.NAME_SERVICE_ERRORS) + || tagName.equals(TagConstants.NAME_GROUP) + || tagName.equals(TagConstants.NAME_USER_AGENT) + || tagName.equals(TagConstants.NAME_REFERER) + || tagName.equals(TagConstants.NAME_CITY) + || tagName.equals(TagConstants.NAME_ERROR)) { return new TextHashValue(tagValue); - } else if (tagName.equals("visitor") - || tagName.equals("elapsed") - || tagName.equals("sqltime") - || tagName.equals("apitime")){ + } else if (tagName.equals(TagConstants.NAME_VISITOR) + || tagName.equals(TagConstants.NAME_ELAPSED) + || tagName.equals(TagConstants.NAME_SQLTIME) + || tagName.equals(TagConstants.NAME_APITIME)){ return new DecimalValue(Long.valueOf(tagValue)); - } else if(tagName.equals("level")) { + } else if(tagName.equals(TagConstants.NAME_LEVEL)) { return new DecimalValue(AlertLevel.getValue(tagValue)); - } else if (tagName.equals("ip")) { + } else if (tagName.equals(TagConstants.NAME_IP)) { return new IP4Value(tagValue); } return new TextValue(tagValue); diff --git a/scouter.client/src/scouter/client/tags/TagCountView.java b/scouter.client/src/scouter/client/tags/TagCountView.java index e4f0a160d..f274f41bd 100644 --- a/scouter.client/src/scouter/client/tags/TagCountView.java +++ b/scouter.client/src/scouter/client/tags/TagCountView.java @@ -97,12 +97,12 @@ import scouter.client.util.ImageUtil; import scouter.client.util.ScouterUtil; import scouter.io.DataInputX; +import scouter.lang.constants.TagConstants; import scouter.lang.pack.AlertPack; import scouter.lang.pack.MapPack; import scouter.lang.pack.Pack; import scouter.lang.pack.XLogPack; import scouter.lang.value.BooleanValue; -import scouter.lang.value.DecimalValue; import scouter.lang.value.ListValue; import scouter.lang.value.MapValue; import scouter.lang.value.NullValue; @@ -119,8 +119,7 @@ public class TagCountView extends ViewPart { public static final String ID = TagCountView.class.getName(); - private static final String DEFAULT_TAG_GROUP = "service"; - private static final String TOTAL_NAME = "@total"; + private static final String DEFAULT_TAG_GROUP = TagConstants.GROUP_SERVICE; private static final int LIMIT_PER_PAGE = 100; int serverId; @@ -459,30 +458,25 @@ public void propertyChange(PropertyChangeEvent evt) { tagNameTree = treeViewer.getTree(); tagNameTree.setHeaderVisible(true); tagNameTree.setLinesVisible(true); - treeViewer.addDoubleClickListener(new IDoubleClickListener() { - public void doubleClick(DoubleClickEvent event) { - IStructuredSelection sel = (IStructuredSelection) event.getSelection(); - Object o = sel.getFirstElement(); - if (o instanceof TagCount) { - TagCount tc = (TagCount) o; - if (tc.tagName == null && tc.count == 0) { - loadTagValues(tagGroupCombo.getText(), tc.value); - } else { - TreeItem[] items = tagNameTree.getSelection(); - if (items != null && items.length >0) { - TreeItem item = items[0]; - if (item != null) { - if(item.getExpanded()){ - item.setExpanded(false); - }else{ - item.setExpanded(true); - } - } - } - } - } - } - }); +// treeViewer.addDoubleClickListener(new IDoubleClickListener() { +// public void doubleClick(DoubleClickEvent event) { +// IStructuredSelection sel = (IStructuredSelection) event.getSelection(); +// Object o = sel.getFirstElement(); +// if (o instanceof TagCount) { +// TreeItem[] items = tagNameTree.getSelection(); +// if (items != null && items.length >0) { +// TreeItem item = items[0]; +// if (item != null) { +// if(item.getExpanded()){ +// item.setExpanded(false); +// }else{ +// item.setExpanded(true); +// } +// } +// } +// } +// } +// }); treeViewer.setContentProvider(new ViewContentProvider()); treeViewer.setLabelProvider(new TableLabelProvider()); treeViewer.addCheckStateListener(new ICheckStateListener() { @@ -687,9 +681,9 @@ private void openCountGraph() { private void openDataTable() { String tagGroup = tagGroupCombo.getText(); - if ("service".equals(tagGroup)) { + if (TagConstants.GROUP_SERVICE.equals(tagGroup)) { dataTableSash.setMaximizedControl(serviceTable); - } else if ("alert".equals(tagGroup)) { + } else if (TagConstants.GROUP_ALERT.equals(tagGroup)) { dataTableSash.setMaximizedControl(alertTable); } } @@ -778,6 +772,8 @@ public void run() { } private void loadTagNames(final String tagGroup) { + tagNameTree.removeAll(); + nameTree.clear(); ExUtil.asyncRun(new Runnable() { public void run() { TcpProxy tcp = TcpProxy.getTcpProxy(serverId); @@ -788,95 +784,100 @@ public void run() { param.put("tagGroup", tagGroup); names = tcp.processValues(RequestCmd.TAGCNT_TAG_NAMES, param); } catch (Exception e) { - + e.printStackTrace(); } finally { TcpProxy.putTcpProxy(tcp); } if (names != null) { final List list = new ArrayList(); for (Value v : names) { - if (TOTAL_NAME.equals(v.toString())) continue; + if (TagConstants.NAME_TOTAL.equals(v.toString())) continue; list.add(v.toString()); } + for (int i = 0; i < list.size(); i++) { + TagCount tag = new TagCount(); + tag.tagName = ""; + tag.value = list.get(i); + nameTree.put(list.get(i), tag); + } + loadTagValues(tagGroup, list); ExUtil.exec(tagNameTree, new Runnable() { public void run() { - tagNameTree.removeAll(); - nameTree.clear(); - for (int i = 0; i < list.size(); i++) { - TagCount tag = new TagCount(); - tag.value = list.get(i); - nameTree.put(list.get(i), tag); - } treeViewer.refresh(); treeViewer.setGrayedElements(nameTree.values().toArray()); } }); } } - }); - } - - - private void loadTagValues(final String tagGroup, final String tagName) { - ExUtil.asyncRun(new Runnable() { - public void run() { - final DecimalValue valueSize = new DecimalValue(); - final DecimalValue totalCount = new DecimalValue(); - final List valueList = new ArrayList(); - final List cntList = new ArrayList(); + + private void loadTagValues(final String tagGroup, final List tagNameList) { + final List dataList = new ArrayList(); TcpProxy tcp = TcpProxy.getTcpProxy(serverId); try { MapPack param = new MapPack(); param.put("objType", objType); param.put("tagGroup", tagGroup); - param.put("tagName", tagName); + ListValue tagNameLv = param.newList("tagName"); + for (String tagName : tagNameList) { + tagNameLv.add(tagName); + } param.put("date", date); tcp.process(RequestCmd.TAGCNT_TAG_VALUES, param, new INetReader() { public void process(DataInputX in) throws IOException { - valueSize.value = in.readInt(); - totalCount.value = in.readLong(); + TagData data = new TagData(); + dataList.add(data); + data.tagName = in.readText(); + data.totalSize = in.readInt(); + data.totalCnt = in.readLong(); int size = in.readInt(); for (int i = 0; i < size; i++) { Value v = in.readValue(); long cnt = in.readLong(); - valueList.add(v); - cntList.add(cnt); + data.addValue(v, cnt); } } }); - } catch (Exception e) { - + e.printStackTrace(); } finally { TcpProxy.putTcpProxy(tcp); } - final List nameList = TagCountUtil.loadTagString(serverId, date, valueList, tagName); - - ExUtil.exec(tagNameTree, new Runnable() { - public void run() { - //removeTagCountAll(); - TagCount parentTag = nameTree.get(tagName); - if (parentTag == null) return; - for (int i = 0; i < nameList.size(); i++) { - TagCount child = new TagCount(); - child.tagName = parentTag.value; - child.value = nameList.get(i); - child.count = cntList.get(i); - parentTag.addChild(child); - } - parentTag.count = totalCount.value; - parentTag.value += " (" + valueSize.value + ")"; - treeViewer.refresh(); - treeViewer.setExpandedElements(new TagCount[] {parentTag}); + for (TagData data : dataList) { + data.strValueList = TagCountUtil.loadTagString(serverId, date, data.valueList, data.tagName); + String tagName = data.tagName; + TagCount parentTag = nameTree.get(tagName); + if (parentTag == null) return; + for (int i = 0; i < data.strValueList.size(); i++) { + TagCount child = new TagCount(); + child.tagName = parentTag.value; + child.value = data.strValueList.get(i); + child.count = data.cntList.get(i); + parentTag.addChild(child); } - }); + parentTag.count = data.totalCnt; + parentTag.value += " (" + data.totalSize + ")"; + } } }); + } + + static class TagData { + String tagName; + List valueList = new ArrayList(); + List cntList = new ArrayList(); + List strValueList; + int totalSize; + long totalCnt; + void addValue(Value v, long cnt) { + valueList.add(v); + cntList.add(cnt); + } } + private void removeTagCountAll() { for (Trace t : cntTraceMap.values()) { cntGraph.removeTrace(t); @@ -944,7 +945,7 @@ public void run() { MapPack param = new MapPack(); param.put("tagGroup", tagGroup); param.put("objType", objType); - param.put("tagName", TOTAL_NAME); + param.put("tagName", TagConstants.NAME_TOTAL); param.put("tagValue", NullValue.value); param.put("date", date); tcp.process(RequestCmd.TAGCNT_TAG_VALUE_DATA, param, new INetReader() { @@ -1004,7 +1005,7 @@ private MapValue makeFilterMv() { for (Object o : objects) { if (o instanceof TagCount) { TagCount tc = (TagCount) o; - if (tc.tagName == null) continue; + if (StringUtil.isEmpty(tc.tagName)) continue; String tagName = tc.tagName; ListValue lv = filterMv.getList(tagName); if (lv == null) { @@ -1044,7 +1045,7 @@ public void run() { if (lastIndex == LIMIT_PER_PAGE) { rightBtn.setEnabled(true); } - if ("service".equals(tagGroup)) { + if (TagConstants.GROUP_SERVICE.equals(tagGroup)) { if (lastSize > 0) { Pack p = result.get(0); XLogPack xp = (XLogPack) p; @@ -1056,7 +1057,7 @@ public void run() { lastTxid = xp.txid; } serviceTable.setInput(result, serverId, tagGroup); - } else if ("alert".equals(tagGroup)) { + } else if (TagConstants.GROUP_ALERT.equals(tagGroup)) { if (lastSize > 0) { Pack p = result.get(0); AlertPack xp = (AlertPack) p; @@ -1079,7 +1080,7 @@ public void run() { long stime = lastTime; long etime = (stime + DateUtil.MILLIS_PER_MINUTE) / DateUtil.MILLIS_PER_MINUTE * DateUtil.MILLIS_PER_MINUTE - 1; MapPack extra = new MapPack(); - if ("service".equals(tagGroup)) { + if (TagConstants.GROUP_SERVICE.equals(tagGroup)) { extra.put("txid", lastTxid); } List list = loadData(tagGroup, stime, etime, false, extra, filterMv); @@ -1093,7 +1094,7 @@ public void run() { rightBtn.setEnabled(false); } leftBtn.setEnabled(true); - if ("service".equals(tagGroup)) { + if (TagConstants.GROUP_SERVICE.equals(tagGroup)) { if (lastSize > 0) { Pack p = result.get(0); XLogPack xp = (XLogPack) p; @@ -1108,7 +1109,7 @@ public void run() { firstTxid = lastTxid = 0; } serviceTable.setInput(result, serverId, tagGroup); - } else if ("alert".equals(tagGroup)) { + } else if (TagConstants.GROUP_ALERT.equals(tagGroup)) { if (lastSize > 0) { Pack p = result.get(0); AlertPack xp = (AlertPack) p; @@ -1134,7 +1135,7 @@ public void run() { long etime = firstTime; long stime = etime / DateUtil.MILLIS_PER_MINUTE * DateUtil.MILLIS_PER_MINUTE; MapPack extra = new MapPack(); - if ("service".equals(tagGroup)) { + if (TagConstants.GROUP_SERVICE.equals(tagGroup)) { extra.put("txid", firstTxid); } List list = loadData(tagGroup, stime, etime, true, extra, filterMv); @@ -1151,7 +1152,7 @@ public void run() { leftBtn.setEnabled(false); } rightBtn.setEnabled(true); - if ("service".equals(tagGroup)) { + if (TagConstants.GROUP_SERVICE.equals(tagGroup)) { Pack p = revList.get(0); XLogPack xp = (XLogPack) p; firstTime = xp.endTime; @@ -1161,7 +1162,7 @@ public void run() { lastTime = xp.endTime; lastTxid = xp.txid; serviceTable.setInput(revList, serverId, tagGroup); - } else if ("service".equals(tagGroup)) { + } else if (TagConstants.GROUP_ALERT.equals(tagGroup)) { Pack p = revList.get(0); AlertPack xp = (AlertPack) p; firstTime = xp.time; diff --git a/scouter.common/src/scouter/lang/counters/StatusConstants.java b/scouter.common/src/scouter/lang/constants/StatusConstants.java similarity index 96% rename from scouter.common/src/scouter/lang/counters/StatusConstants.java rename to scouter.common/src/scouter/lang/constants/StatusConstants.java index b6b0f304b..57726c9f1 100644 --- a/scouter.common/src/scouter/lang/counters/StatusConstants.java +++ b/scouter.common/src/scouter/lang/constants/StatusConstants.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package scouter.lang.counters; +package scouter.lang.constants; public class StatusConstants { public final static String PERF_KEY_ACTIVE_QUERY_LIST = "active_query_list"; diff --git a/scouter.common/src/scouter/lang/constants/TagConstants.java b/scouter.common/src/scouter/lang/constants/TagConstants.java new file mode 100644 index 000000000..8f52c3e9b --- /dev/null +++ b/scouter.common/src/scouter/lang/constants/TagConstants.java @@ -0,0 +1,27 @@ +package scouter.lang.constants; + +public class TagConstants { + public static final String GROUP_SERVICE = "service"; + public static final String GROUP_ALERT = "alert"; + + public static final String NAME_TOTAL = "@total"; + public static final String NAME_OBJECT = "object"; + public static final String NAME_IP = "ip"; + public static final String NAME_SERVICE = "service"; + public static final String NAME_SERVICE_ELAPSED = "service-elapsed"; + public static final String NAME_SERVICE_BYTES = "service-bytes"; + public static final String NAME_SERVICE_ERRORS = "service-errors"; + public static final String NAME_USER_AGENT = "user-agent"; + public static final String NAME_ERROR = "error"; + public static final String NAME_REFERER = "referer"; + public static final String NAME_GROUP = "group"; + public static final String NAME_ELAPSED = "elapsed"; + public static final String NAME_SQLTIME = "sqltime"; + public static final String NAME_APITIME = "apitime"; + public static final String NAME_CITY = "city"; + public static final String NAME_NATION = "nation"; + public static final String NAME_VISITOR = "visitor"; + public static final String NAME_LEVEL = "level"; + public static final String NAME_TITLE = "title"; + +} diff --git a/scouter.server/src/scouter/server/netio/service/handle/MariaService.scala b/scouter.server/src/scouter/server/netio/service/handle/MariaService.scala index 8059b951c..39ca95333 100644 --- a/scouter.server/src/scouter/server/netio/service/handle/MariaService.scala +++ b/scouter.server/src/scouter/server/netio/service/handle/MariaService.scala @@ -21,7 +21,7 @@ import java.util.HashSet import scouter.lang.CounterKey import scouter.lang.DigestKey import scouter.lang.TimeTypeEnum -import scouter.lang.counters.StatusConstants +import scouter.lang.constants.StatusConstants import scouter.lang.pack.MapPack import scouter.lang.pack.StatusPack import scouter.lang.value.DoubleValue diff --git a/scouter.server/src/scouter/server/netio/service/handle/TagCountService.scala b/scouter.server/src/scouter/server/netio/service/handle/TagCountService.scala index 5a4c02254..fbc135457 100644 --- a/scouter.server/src/scouter/server/netio/service/handle/TagCountService.scala +++ b/scouter.server/src/scouter/server/netio/service/handle/TagCountService.scala @@ -15,10 +15,9 @@ */ package scouter.server.netio.service.handle; -import scala.collection.JavaConversions.asScalaBuffer -import scala.collection.JavaConversions.asScalaSet import scouter.io.DataInputX import scouter.io.DataOutputX +import scouter.lang.constants.TagConstants import scouter.lang.pack.AlertPack import scouter.lang.pack.MapPack import scouter.lang.pack.XLogPack @@ -32,15 +31,12 @@ import scouter.server.netio.service.anotation.ServiceHandler import scouter.server.tagcnt.TagCountConfig import scouter.server.tagcnt.TagCountProxy import scouter.server.tagcnt.core.ValueCount -import scouter.server.tagcnt.core.ValueCountTotal import scouter.server.util.EnumerScala -import scouter.server.util.TimedSeries import scouter.util.DateUtil +import scouter.util.IPUtil import scouter.util.IntSet import scouter.util.StringUtil import scouter.net.RequestCmd -import java.util.Enumeration -import scouter.util.IPUtil class TagCountService { @@ -74,24 +70,28 @@ class TagCountService { val param = din.readPack().asInstanceOf[MapPack]; val objType = param.getText("objType"); val tagGroup = param.getText("tagGroup"); - val tagName = param.getText("tagName"); + val tagNameLv = param.getList("tagName"); var date = param.getText("date"); if (StringUtil.isEmpty(date)) { date = DateUtil.yyyymmdd(); } - val valueCountTotal = TagCountProxy.getTagValueCountWithCache(date, objType, tagGroup, tagName, 100); - if (valueCountTotal != null) { - dout.writeByte(TcpFlag.HasNEXT); - dout.writeInt(valueCountTotal.howManyValues) - // TODO: temp - dout.writeLong(valueCountTotal.totalCount.toLong) - dout.writeInt(valueCountTotal.values.size()) - EnumerScala.forward(valueCountTotal.values, (vc: ValueCount) => { - dout.writeValue(vc.tagValue) - // TODO: temp - dout.writeLong(vc.valueCount.toLong) - }) + for (i <- 0 to tagNameLv.size() - 1) { + val tagName = tagNameLv.getString(i); + val valueCountTotal = TagCountProxy.getTagValueCountWithCache(date, objType, tagGroup, tagName, 100); + if (valueCountTotal != null) { + dout.writeByte(TcpFlag.HasNEXT); + dout.writeText(tagName); + dout.writeInt(valueCountTotal.howManyValues) + // TODO: temp + dout.writeLong(valueCountTotal.totalCount.toLong) + dout.writeInt(valueCountTotal.values.size()) + EnumerScala.forward(valueCountTotal.values, (vc: ValueCount) => { + dout.writeValue(vc.tagValue) + // TODO: temp + dout.writeLong(vc.valueCount.toLong) + }) + } } } @@ -143,7 +143,7 @@ class TagCountService { } } - if (tagGroup == "service" ) { + if (tagGroup == TagConstants.GROUP_SERVICE) { var txid = param.getLong("txid"); var ok = if (txid == 0) true else false; var cnt = 0; @@ -171,7 +171,7 @@ class TagCountService { } else { XLogRD.readByTime(date, stime, etime, handler); } - } else if (tagGroup == "alert") { + } else if (tagGroup == TagConstants.GROUP_ALERT) { var cnt = 0; val handler = (time: Long, data: Array[Byte]) => { val x = new DataInputX(data).readPack().asInstanceOf[AlertPack]; @@ -200,7 +200,7 @@ class TagCountService { val itr = mv.keys(); while (itr.hasMoreElements()) { val key = itr.nextElement(); - if (key == "error") { + if (key == TagConstants.NAME_ERROR) { val errorLv = mv.getList(key); for (i <- 0 to errorLv.size() - 1) { var error = errorLv.get(i).toJavaObject(); @@ -208,7 +208,7 @@ class TagCountService { return true; } } - } else if (key == "user-agent") { + } else if (key == TagConstants.NAME_USER_AGENT) { val userAgentLv = mv.getList(key); for (i <- 0 to userAgentLv.size() - 1) { var userAgent = userAgentLv.get(i).toJavaObject(); @@ -216,7 +216,7 @@ class TagCountService { return true; } } - } else if (key == "object") { + } else if (key == TagConstants.NAME_OBJECT) { val objHashLv = mv.getList(key); for (i <- 0 to objHashLv.size() - 1) { var objHash = objHashLv.get(i).toJavaObject(); @@ -224,7 +224,7 @@ class TagCountService { return true; } } - } else if (key == "nation") { + } else if (key == TagConstants.NAME_NATION) { val nationLv = mv.getList(key); for (i <- 0 to nationLv.size() - 1) { var nation = nationLv.getString(i); @@ -232,7 +232,7 @@ class TagCountService { return true; } } - } else if (key == "visitor") { + } else if (key == TagConstants.NAME_VISITOR) { val visitorLv = mv.getList(key); for (i <- 0 to visitorLv.size() - 1) { var visitor = visitorLv.getLong(i); @@ -240,7 +240,7 @@ class TagCountService { return true; } } - } else if (key == "city") { + } else if (key == TagConstants.NAME_CITY) { val cityLv = mv.getList(key); for (i <- 0 to cityLv.size() - 1) { var city = cityLv.get(i).toJavaObject(); @@ -248,7 +248,7 @@ class TagCountService { return true; } } - } else if (key == "ip") { + } else if (key == TagConstants.NAME_IP) { val ipLv = mv.getList(key); for (i <- 0 to ipLv.size() - 1) { var ip = ipLv.get(i); @@ -256,7 +256,10 @@ class TagCountService { return true; } } - } else if (key == "service" || key.startsWith("service-")) { + } else if (key == TagConstants.NAME_SERVICE + || key == TagConstants.NAME_SERVICE_ELAPSED + || key == TagConstants.NAME_SERVICE_BYTES + || key == TagConstants.NAME_SERVICE_ERRORS) { val serviceLv = mv.getList(key); for (i <- 0 to serviceLv.size() - 1) { var service = serviceLv.get(i).toJavaObject(); @@ -264,7 +267,7 @@ class TagCountService { return true; } } - } else if (key == "referer") { + } else if (key == TagConstants.NAME_REFERER) { val refererLv = mv.getList(key); for (i <- 0 to refererLv.size() - 1) { var referer = refererLv.get(i).toJavaObject(); @@ -272,7 +275,7 @@ class TagCountService { return true; } } - } else if (key == "group") { + } else if (key == TagConstants.NAME_GROUP) { val groupLv = mv.getList(key); for (i <- 0 to groupLv.size() - 1) { var group = groupLv.get(i).toJavaObject(); @@ -280,7 +283,7 @@ class TagCountService { return true; } } - } else if (key == "apitime") { + } else if (key == TagConstants.NAME_APITIME) { if (x.apicallTime >= 1000) { val apitimeLv = mv.getList(key); for (i <- 0 to apitimeLv.size() - 1) { @@ -292,7 +295,7 @@ class TagCountService { } } } - } else if (key == "sqltime") { + } else if (key == TagConstants.NAME_SQLTIME) { if (x.sqlTime >= 1000) { val sqltimeLv = mv.getList(key); for (i <- 0 to sqltimeLv.size() - 1) { @@ -304,7 +307,7 @@ class TagCountService { } } } - } else if (key == "elapsed") { + } else if (key == TagConstants.NAME_ELAPSED) { if (x.elapsed >= 1000) { val elapsedLv = mv.getList(key); for (i <- 0 to elapsedLv.size() - 1) { @@ -325,7 +328,7 @@ class TagCountService { val itr = mv.keys(); while (itr.hasMoreElements()) { val key = itr.nextElement(); - if (key == "object") { + if (key == TagConstants.NAME_OBJECT) { val objHashLv = mv.getList(key); for (i <- 0 to objHashLv.size() - 1) { var objHash = objHashLv.get(i).toJavaObject(); @@ -333,7 +336,7 @@ class TagCountService { return true; } } - } else if (key == "level") { + } else if (key == TagConstants.NAME_LEVEL) { val levelLv = mv.getList(key); for (i <- 0 to levelLv.size() - 1) { var level = levelLv.getInt(i); @@ -341,7 +344,7 @@ class TagCountService { return true; } } - } else if (key == "title") { + } else if (key == TagConstants.NAME_TITLE) { val titleLv = mv.getList(key); for (i <- 0 to titleLv.size() - 1) { var title = titleLv.getString(i); diff --git a/scouter.server/src/scouter/server/tagcnt/TagCountConfig.scala b/scouter.server/src/scouter/server/tagcnt/TagCountConfig.scala index 2b5bbb441..932d4b301 100644 --- a/scouter.server/src/scouter/server/tagcnt/TagCountConfig.scala +++ b/scouter.server/src/scouter/server/tagcnt/TagCountConfig.scala @@ -16,14 +16,15 @@ */ package scouter.server.tagcnt; -import scouter.util.BitUtil; -import scouter.util.HashUtil; -import scouter.util.LongKeyMap; -import scouter.util.LongSet; -import scouter.util.StringEnumer; -import scouter.util.StringKeyLinkedMap; -import scouter.util.StringSet; +import scouter.util.BitUtil +import scouter.util.HashUtil +import scouter.util.LongKeyMap +import scouter.util.LongSet +import scouter.util.StringEnumer +import scouter.util.StringKeyLinkedMap +import scouter.util.StringSet import scouter.util.StringUtil; +import scouter.lang.constants.TagConstants object TagCountConfig { @@ -60,40 +61,40 @@ object TagCountConfig { } class Service { - val total = new Tag("service", "@total"); - val objectName = new Tag("service", "object"); - val ip = new Tag("service", "ip"); - val service = new Tag("service", "service"); + val total = new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_TOTAL); + val objectName = new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_OBJECT); + val ip = new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_IP); + val service = new Tag(TagConstants.GROUP_SERVICE, TagConstants.GROUP_SERVICE); - val service_elapsed= new Tag("service", "service-elapsed"); - val service_bytes = new Tag("service", "service-bytes"); - val service_errors = new Tag("service", "service-errors"); + val service_elapsed= new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_SERVICE_ELAPSED); + val service_bytes = new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_SERVICE_BYTES); + val service_errors = new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_SERVICE_ERRORS); - val userAgent = new Tag("service", "user-agent"); - val error = new Tag("service", "error"); - val referer = new Tag("service", "referer"); - val group = new Tag("service", "group"); + val userAgent = new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_USER_AGENT); + val error = new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_ERROR); + val referer = new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_REFERER); + val group = new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_GROUP); - val elapsed = new Tag("service", "elapsed"); - val sqltime = new Tag("service", "sqltime"); - val apitime = new Tag("service", "apitime"); + val elapsed = new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_ELAPSED); + val sqltime = new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_SQLTIME); + val apitime = new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_APITIME); - val city = new Tag("service", "city"); - val nation = new Tag("service", "nation"); - val visitor = new Tag("service", "visitor"); + val city = new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_CITY); + val nation = new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_NATION); + val visitor = new Tag(TagConstants.GROUP_SERVICE, TagConstants.NAME_VISITOR); } val service = new Service() class Alert { - val total = new Tag("alert", "@total"); - val objectName = new Tag("alert", "object"); - val level = new Tag("alert", "level"); - val title = new Tag("alert", "title"); + val total = new Tag(TagConstants.GROUP_ALERT, TagConstants.NAME_TOTAL); + val objectName = new Tag(TagConstants.GROUP_ALERT, TagConstants.NAME_OBJECT); + val level = new Tag(TagConstants.GROUP_ALERT, TagConstants.NAME_LEVEL); + val title = new Tag(TagConstants.GROUP_ALERT, TagConstants.NAME_TITLE); } val alert = new Alert() def main(args: Array[String]) { System.out.println(StringUtil.toString(getTagGroups())); - System.out.println(StringUtil.toString(getTagNames("service"))); + System.out.println(StringUtil.toString(getTagNames(TagConstants.GROUP_SERVICE))); } } diff --git a/scouter.server/src/scouter/server/tagcnt/core/MoveToNextCollector.scala b/scouter.server/src/scouter/server/tagcnt/core/MoveToNextCollector.scala index f99f57eb2..104aef532 100644 --- a/scouter.server/src/scouter/server/tagcnt/core/MoveToNextCollector.scala +++ b/scouter.server/src/scouter/server/tagcnt/core/MoveToNextCollector.scala @@ -28,7 +28,7 @@ import scouter.server.util.ThreadScala object MoveToNextCollector { private val MAX_MASTER = 1000; - private val MAX_QUE_SIZE = 10000; + private val MAX_QUE_SIZE = 30000; private val queue = new RequestQueue[CountItem](MAX_QUE_SIZE + 1);