diff --git a/README.md b/README.md index 916bbea..9e4b682 100644 --- a/README.md +++ b/README.md @@ -56,10 +56,20 @@ Count (default : mysql root@localhost:3388) java -jar metrics-VERSION-all.jar -password=*** metrics-stats Timestamp;AccountName;ApplicationName;TierName;NodeName;AgentType;MetricsCount - Thu Aug 24 00:00:00 CEST 2017;customer1;MyApp1;MyTier1;MyNode1;MACHINE_AGENT;43 + Thu Aug 24 00:00:00 CEST 2017;customer1;MyApp1;MyTier1;MyNode1;MACHINE_AGENT_LEGACY;43 Thu Aug 24 00:00:00 CEST 2017;customer1;MyApp2;MyTier2;Mu=yNode2;APP_AGENT;66 ... +Summary (default : mysql root@localhost:3388) + + java -jar metrics-VERSION-all.jar -password=*** metrics-stats-summary + + Timestamp;AgentType;Min;Avg;Max;Sum;Count; + "Mon Feb 12 00:00:00 CET 2018";"APP_AGENT";103;227;2196;205434;902; + "Mon Feb 12 00:00:00 CET 2018";"MACHINE_AGENT_LEGACY";64;84;92;4876;58; + "Mon Feb 12 00:00:00 CET 2018";"EUM";890;2372;9641;21356;9; + ... + Storage (default : mysql root@localhost:3388) java -jar metrics-VERSION-all.jar -password=*** metrics-stats-storage diff --git a/build.gradle b/build.gradle index a07ba25..1f702ed 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'org.appdynamics' -version = '1.0.2' +version = '1.0.3' description = """""" diff --git a/src/main/java/org/appdynamics/metrics/MetricStat.java b/src/main/java/org/appdynamics/metrics/MetricStat.java index 8932816..4b3d959 100644 --- a/src/main/java/org/appdynamics/metrics/MetricStat.java +++ b/src/main/java/org/appdynamics/metrics/MetricStat.java @@ -46,6 +46,25 @@ public String getAgentType() { return agentType; } + public String getModifiedAgentType() { + String result = agentType; + + if(tierName == null || "null".equalsIgnoreCase(tierName)) + result = "EUM"; + else if("Server & Infrastructure Monitoring".equals(applicationName)) { + result = "MACHINE_AGENT_SERVER_VISIBILITY"; + } + else if("Database Monitoring".equals(applicationName)) { + if("MACHINE_AGENT".equals(agentType)) + result = "MACHINE_AGENT_DB_COLLECTOR"; + } + else if("MACHINE_AGENT".equals(agentType)) { + result = "MACHINE_AGENT_LEGACY"; + } + + return result; + } + public int getMetricsCount() { return metricsCount; } diff --git a/src/main/java/org/appdynamics/metrics/Metrics.java b/src/main/java/org/appdynamics/metrics/Metrics.java index 29391ca..7501b63 100644 --- a/src/main/java/org/appdynamics/metrics/Metrics.java +++ b/src/main/java/org/appdynamics/metrics/Metrics.java @@ -55,6 +55,10 @@ public static void main(String[] args) throws Exception { conn = DriverManager.getConnection(jdbcUrl); int beforeMin = pgArgs.getArgument(1) !=null ? Integer.parseInt(pgArgs.getArgument(1)): 10; statsMetrics(conn, beforeMin, out, db); + } else if (pgArgs.getArgument(0).equals("metrics-stats-summary")) { + conn = DriverManager.getConnection(jdbcUrl); + int beforeMin = pgArgs.getArgument(1) !=null ? Integer.parseInt(pgArgs.getArgument(1)): 10; + statsMetricsSummary(conn, beforeMin, out, db); } else if (pgArgs.getArgument(0).equals("metrics-stats-storage")) { conn = DriverManager.getConnection(jdbcUrl); statsMetricsStorage(conn, pgArgs.getArgument(2), out, db); @@ -77,7 +81,7 @@ public static void main(String[] args) throws Exception { } private static void displayUsage() { - System.out.println("Usage : [-hostname=] [-port=] [-username=] [-password=] [-filename=] applications|tiers|metrics-list [filter]|metrics-stats-storage|metrics-stats [beforeMin]|metrics-delete filter"); + System.out.println("Usage : [-hostname=] [-port=] [-username=] [-password=] [-filename=] applications|tiers|metrics-list [filter]|metrics-stats-storage|metrics-stats|metrics-stats-summary [beforeMin]|metrics-delete filter"); System.exit(0); } @@ -135,12 +139,54 @@ private static void statsMetrics(Connection conn, int beforeMin, PrinterAdapter Collection stats = findMetricStats(conn, beforeMin, out, db); String header = "Timestamp;AccountName;ApplicationName;TierName;NodeName;AgentType;MetricsCount;"; - String row = "\"%tc\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";\"%d\";"; + String row = "\"%tc\";\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";%d;"; out.println(header); for (MetricStat m : stats) - out.println(String.format(row, m.getTimestamp(), m.getAccountName(), m.getApplicationName(), m.getTierName(), m.getNodeName(), m.getAgentType(), m.getMetricsCount())); + out.println(String.format(row, m.getTimestamp(), m.getAccountName(), m.getApplicationName(), m.getTierName(), m.getNodeName(), m.getModifiedAgentType(), m.getMetricsCount())); + } + + private static void statsMetricsSummary(Connection conn, int beforeMin, PrinterAdapter out, String db) throws SQLException, FileNotFoundException { + + Collection stats = findMetricStats(conn, beforeMin, out, db); + + // Group by AgentType + Map> agentTypes = new HashMap>(); + for(MetricStat ms : stats) { + List s = agentTypes.get(ms.getModifiedAgentType()); + + if(s==null) { + s = new LinkedList(); + agentTypes.put(ms.getModifiedAgentType(), s); + } + + s.add(ms); + } + + // Compute Sum, Avg, Count, Min and Max + Map operators = new HashMap(); + + for(String agentType : agentTypes.keySet()) { + GroupOperator go = null; + + for(MetricStat ms : agentTypes.get(agentType)) { + if(go==null) { + go = new GroupOperator(agentType, ms.getTimestamp()); + operators.put(agentType, go); + } + go.update(ms.getMetricsCount()); + } + } + + // Display + String header = "Timestamp;AgentType;Min;Avg;Max;Sum;Count;"; + String row = "\"%tc\";\"%s\";%d;%d;%d;%d;%d;"; + + out.println(header); + + for (GroupOperator go : operators.values()) + out.println(String.format(row, go.timestamp, go.agentType, go.min, go.getAvg(), go.max, go.sum, go.count)); } private static void statsMetricsStorage(Connection conn, String filter, PrinterAdapter out, String db) throws SQLException, FileNotFoundException { @@ -217,7 +263,6 @@ private static Collection findMetricStats(Connection conn, int befor private static Collection findMetricStatsStorage(Connection conn, String filter, PrinterAdapter out, String db) throws SQLException { Collection metricStorageStats = new ArrayList(); - List tables = new ArrayList(); Statement stmt = conn.createStatement(); @@ -324,8 +369,10 @@ static class ProgramArguments { if (arg == null) continue; if (arg.startsWith("-") && arg.contains("=")) { - String[] splits = arg.substring(1).split("="); - parameters.put(splits[0], splits[1]); + int index = arg.indexOf("="); + String action = arg.substring(1,index); + String value = arg.substring(index+1); + parameters.put(action, value); } else arguments.add(arg); } @@ -347,6 +394,33 @@ String getParameter(String key) { String getParameter(String key, String defaultValue) { return parameters.containsKey(key) ? parameters.get(key) : defaultValue; } + } + + static class GroupOperator { + public String agentType; + public Date timestamp; + public long count; + public long sum; + public long min=-1; + public long max; + + public GroupOperator(String agentType, Date timestamp) { + super(); + this.agentType = agentType; + this.timestamp = timestamp; + } + void update(long value) { + if(value>max) + max=value; + if(min<0 || value