diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 59b6233..a8e9432 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,8 +6,15 @@ + - + + + + + + + @@ -29,31 +36,64 @@ - - + + - - - + + + + + + + + + + + + + + + + + - - + + - - - + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + @@ -62,69 +102,126 @@ - - - + + + + + + + + + + + + + + + + + + + + + - - + + - - + + - - + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - + + + + + + + - - + + - - + + - - + + - - + + - - + + - - - + + + + + + + + + + + @@ -191,18 +288,12 @@ @@ -313,6 +410,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - @@ -434,16 +531,16 @@ - - - + + + - - - + + + @@ -458,7 +555,7 @@ - + @@ -664,18 +761,6 @@ - - - + + + @@ -724,8 +821,9 @@ - + + @@ -743,35 +841,35 @@ - + - + - + - + - + - + - + - + - + - - + + @@ -794,18 +892,18 @@ - + - + - + @@ -854,7 +952,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -986,20 +1033,6 @@ - - - - - - - - - - - - - - @@ -1028,22 +1061,6 @@ - - - - - - - - - - - - - - - - @@ -1069,14 +1086,6 @@ - - - - - - - - @@ -1091,7 +1100,6 @@ - @@ -1102,14 +1110,6 @@ - - - - - - - - @@ -1129,7 +1129,6 @@ - @@ -1137,7 +1136,6 @@ - @@ -1165,6 +1163,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1173,14 +1240,23 @@ - + - - + + + - + + + + + + + + + @@ -1188,46 +1264,184 @@ - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/releases/v8LogScanner.jar b/releases/v8LogScanner.jar index 887e612..0204dbc 100644 Binary files a/releases/v8LogScanner.jar and b/releases/v8LogScanner.jar differ diff --git a/src/main/java/org/v8LogScanner/cmdScanner/CmdChangeOrder.java b/src/main/java/org/v8LogScanner/cmdScanner/CmdChangeOrder.java index edb1ae4..6da9f84 100644 --- a/src/main/java/org/v8LogScanner/cmdScanner/CmdChangeOrder.java +++ b/src/main/java/org/v8LogScanner/cmdScanner/CmdChangeOrder.java @@ -19,9 +19,10 @@ public String getTip() { public void execute() { V8LogScannerAppl appl = V8LogScannerAppl.instance(); - String[] sortingProps = new String[2]; + String[] sortingProps = new String[3]; sortingProps[0] = "Events_amount"; sortingProps[1] = PropTypes.Duration.toString(); + sortingProps[2] = PropTypes.Time.toString(); String userInput = appl.getConsole().askInputFromList("input prop which will be used to sort result:", sortingProps); if (userInput == null) { diff --git a/src/main/java/org/v8LogScanner/cmdScanner/CmdGetTopThisHourEvents.java b/src/main/java/org/v8LogScanner/cmdScanner/CmdGetTopThisHourEvents.java new file mode 100644 index 0000000..636411d --- /dev/null +++ b/src/main/java/org/v8LogScanner/cmdScanner/CmdGetTopThisHourEvents.java @@ -0,0 +1,17 @@ +package org.v8LogScanner.cmdScanner; + +import org.v8LogScanner.cmdAppl.CmdCommand; +import org.v8LogScanner.rgx.ScanProfile; + +public class CmdGetTopThisHourEvents implements CmdCommand { + @Override + public String getTip() { + return ""; + } + + @Override + public void execute() { + V8LogScannerAppl appl = V8LogScannerAppl.instance(); + ScanProfile.buildTopThisHourEvents(appl.profile); + } +} diff --git a/src/main/java/org/v8LogScanner/cmdScanner/V8LogScannerAppl.java b/src/main/java/org/v8LogScanner/cmdScanner/V8LogScannerAppl.java index 3a1b8b9..6338d35 100644 --- a/src/main/java/org/v8LogScanner/cmdScanner/V8LogScannerAppl.java +++ b/src/main/java/org/v8LogScanner/cmdScanner/V8LogScannerAppl.java @@ -138,6 +138,7 @@ public void runAppl() { // Item 4. main.add(new MenuItemCmd("Auto profiles", null, m_autoModes)); + m_autoModes.add(new MenuItemCmd("Find latest in this hour events", new CmdGetTopThisHourEvents(), cursorLogScan)); m_autoModes.add(new MenuItemCmd("Find all users events", new CmdGetAllUserEvents(), heapLogScan)); m_autoModes.add(new MenuItemCmd("Find EXCP from rphost logs grouped by 'descr'", new CmdGetRphostExcp(), heapLogScan)); m_autoModes.add(new MenuItemCmd("Find EXCP caused by user", new CmdGetUserExcp(), heapLogScan)); @@ -184,7 +185,7 @@ public void runAppl() { m_runServer.add(new MenuItemCmd("Run as a fullREST server (not work yet!)", null)); cmdAppl.setTitle( - "V8 Log Scanner v.1.0_beta" + "V8 Log Scanner v.1.1_beta" + "\nRuns on " + Constants.osType + "\n********************" ); diff --git a/src/main/java/org/v8LogScanner/rgx/CursorOp.java b/src/main/java/org/v8LogScanner/rgx/CursorOp.java index fa467fd..73bf69e 100644 --- a/src/main/java/org/v8LogScanner/rgx/CursorOp.java +++ b/src/main/java/org/v8LogScanner/rgx/CursorOp.java @@ -9,6 +9,7 @@ import java.io.IOException; import java.math.BigInteger; import java.util.*; +import java.util.concurrent.ConcurrentMap; import java.util.stream.Collectors; public class CursorOp extends AbstractOp { @@ -65,7 +66,11 @@ public void execute(List logFiles) { } afterSlize = syncReduced.size(); TreeMap> rgxResult = finalReduction(syncReduced); + totalKeys = rgxResult.keySet().size(); + + sortLogs(rgxResult); + selector.setResult(rgxResult); calc.end(); } @@ -170,6 +175,18 @@ private TreeMap> finalReduction(Collection sour return rgxResult; } + private void sortLogs(TreeMap> rgxResult) { + + saveProcessingInfo("\n*SORTING..."); + + rgxResult.entrySet(). + parallelStream(). + forEach(n -> n.getValue(). + sort(RgxOpManager::compare)); + + saveProcessingInfo("Sorting completed."); + } + private SortingKey createSortingKey(String input) { String eventKey = RgxOpManager.getEventProperty( @@ -179,6 +196,8 @@ private SortingKey createSortingKey(String input) { if (sortingProp == PropTypes.Duration) return new DurationKey(eventKey, sortingKey); + else if (sortingProp == PropTypes.Time) + return new TimeKey(eventKey, sortingKey, RgxOpManager.getTimeText(input)); else return new SizeKey(eventKey, sortingKey); } @@ -319,4 +338,54 @@ public String toString() { } } + public class TimeKey implements SortingKey { + + final String key; + private BigInteger sortingKey; + private String time; + + public TimeKey(String key, BigInteger sortingKey, String time) { + this.key = key; + this.sortingKey = sortingKey; + this.time = time; + } + + public String getKey() { + return key; + } + + public BigInteger getSortingKey() { + return sortingKey; + } + + public void setSortingKey(BigInteger sortingKey) { + this.sortingKey = sortingKey; + } + + @Override + public int compareTo(SortingKey o) { + int comparedVal = sortingKey.compareTo(o.getSortingKey()); + return -comparedVal; + } + + public int hashCode() { + return sortingKey.hashCode(); + } + + public boolean equals(Object x) { + if (x == this) + return true; + if (x == null || (!(x instanceof DurationKey))) + return false; + + DurationKey other = (DurationKey) x; + return sortingKey.equals(other.getSortingKey()); + } + + @Override + public String toString() { + return String.format("TIME: %s \nGROUP: %s", time, key); + } + } + } diff --git a/src/main/java/org/v8LogScanner/rgx/RgxOpManager.java b/src/main/java/org/v8LogScanner/rgx/RgxOpManager.java index f080abe..833da14 100644 --- a/src/main/java/org/v8LogScanner/rgx/RgxOpManager.java +++ b/src/main/java/org/v8LogScanner/rgx/RgxOpManager.java @@ -257,4 +257,12 @@ public static BigInteger getTime(String input) { return time; } + public static String getTimeText(String input) { + String time = "00:00"; + Matcher timeMatcher = timePattern.matcher(input); + if (timeMatcher.find()) + time = timeMatcher.group(); + return time; + } + } diff --git a/src/main/java/org/v8LogScanner/rgx/ScanProfile.java b/src/main/java/org/v8LogScanner/rgx/ScanProfile.java index cc808d9..fbaf884 100644 --- a/src/main/java/org/v8LogScanner/rgx/ScanProfile.java +++ b/src/main/java/org/v8LogScanner/rgx/ScanProfile.java @@ -294,4 +294,12 @@ static void BuildFindSlowSQlEventsWithPlan(ScanProfile profile, String queryPlan profile.setSortingProp(PropTypes.Duration); } + static void buildTopThisHourEvents(ScanProfile profile) { + profile.clear(); + profile.setRgxOp(RgxOpTypes.CURSOR_OP); + profile.setSortingProp(PropTypes.Time); + profile.addRegExp(new RegExp(RegExp.EventTypes.ANY)); + profile.setDateRange(DateRanges.THIS_HOUR); + } + } diff --git a/src/test/java/org/v8LogScanner/testV8LogScanner/TestRgxOp.java b/src/test/java/org/v8LogScanner/testV8LogScanner/TestRgxOp.java index 3deae01..e8f0d78 100644 --- a/src/test/java/org/v8LogScanner/testV8LogScanner/TestRgxOp.java +++ b/src/test/java/org/v8LogScanner/testV8LogScanner/TestRgxOp.java @@ -44,6 +44,7 @@ public void testStartRgxOp() throws Exception { ScanProfile profile = localClient.getProfile(); profile.addLogPath(logFileName); profile.addRegExp(new RegExp(EventTypes.EXCP)); + profile.setSortingProp(PropTypes.ANY); manager.startRgxOp(); List logs = localClient.select(100, SelectDirections.FORWARD); @@ -130,6 +131,7 @@ public void testGroupBySeveralProps() { event.getGroupingProps().add(PropTypes.ClientID); event.getGroupingProps().add(PropTypes.ComputerName); profile.addRegExp(event); + profile.setSortingProp(PropTypes.ANY); client.startRgxOp(); List logs = client.select(100, SelectDirections.FORWARD); @@ -394,7 +396,7 @@ public void testVSRQuieries() { rgx.getFilter(PropTypes.Method).add("GET"); profile.addRegExp(rgx); profile.addRegExp(new RegExp(EventTypes.VRSRESPONSE)); - + profile.setSortingProp(PropTypes.ANY); localClient.startRgxOp(); List entries = localClient.select(100, SelectDirections.FORWARD); assertEquals(2, entries.size()); @@ -443,4 +445,27 @@ public void testUserScanOp() { List entries = localClient.select(100, SelectDirections.FORWARD); assertEquals(1, entries.size()); } + + @Test + public void testTopThisHourEvents() { + String logFileName = constructor + .addEXCP() + .addVRSREQUEST() + .build(LogFileTypes.FILE); + + ClientsManager manager = new ClientsManager(); + V8LogScannerClient localClient = manager.localClient(); + + ScanProfile profile = localClient.getProfile(); + ScanProfile.buildTopThisHourEvents(profile); + profile.setDateRange(ScanProfile.DateRanges.ANY); // reset due limits in the test data + profile.addLogPath(logFileName); + manager.startRgxOp(); + List logs = localClient.select(100, SelectDirections.FORWARD); + + assertEquals(3, logs.size()); + + V8LogFileConstructor.deleteLogFile(logFileName); + } + } diff --git a/src/test/java/org/v8LogScanner/testV8LogScanner/TestV8ScannerClient.java b/src/test/java/org/v8LogScanner/testV8LogScanner/TestV8ScannerClient.java index 3a853df..4f767ef 100644 --- a/src/test/java/org/v8LogScanner/testV8LogScanner/TestV8ScannerClient.java +++ b/src/test/java/org/v8LogScanner/testV8LogScanner/TestV8ScannerClient.java @@ -118,6 +118,7 @@ public void testSelect() { client.getProfile().addLogPath(file); client.getProfile().addRegExp(new RegExp()); + client.getProfile().setSortingProp(RegExp.PropTypes.ANY); client.startRgxOp(); List entries = client.select(100, IRgxSelector.SelectDirections.FORWARD); assertEquals(3, entries.size());