Skip to content

Commit

Permalink
Add a new command : metrics-stats-summary
Browse files Browse the repository at this point in the history
Refine the agentType for metrics-stats and metrics-stats-summary
commands
  • Loading branch information
rhallier committed Feb 15, 2018
1 parent 384219c commit 53aef96
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 8 deletions.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = 'org.appdynamics'
version = '1.0.2'
version = '1.0.3'

description = """"""

Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/appdynamics/metrics/MetricStat.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
86 changes: 80 additions & 6 deletions src/main/java/org/appdynamics/metrics/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -135,12 +139,54 @@ private static void statsMetrics(Connection conn, int beforeMin, PrinterAdapter
Collection<MetricStat> 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<MetricStat> stats = findMetricStats(conn, beforeMin, out, db);

// Group by AgentType
Map<String, List<MetricStat>> agentTypes = new HashMap<String, List<MetricStat>>();
for(MetricStat ms : stats) {
List<MetricStat> s = agentTypes.get(ms.getModifiedAgentType());

if(s==null) {
s = new LinkedList<MetricStat>();
agentTypes.put(ms.getModifiedAgentType(), s);
}

s.add(ms);
}

// Compute Sum, Avg, Count, Min and Max
Map<String, GroupOperator> operators = new HashMap<String, GroupOperator>();

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 {
Expand Down Expand Up @@ -217,7 +263,6 @@ private static Collection<MetricStat> findMetricStats(Connection conn, int befor

private static Collection<MetricStorageStat> findMetricStatsStorage(Connection conn, String filter, PrinterAdapter out, String db) throws SQLException {
Collection<MetricStorageStat> metricStorageStats = new ArrayList<MetricStorageStat>();
List<String> tables = new ArrayList<String>();

Statement stmt = conn.createStatement();

Expand Down Expand Up @@ -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);
}
Expand All @@ -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<min)
min=value;
sum+=value;
count++;
}

long getAvg() {
return (long)sum/count;
}
}
}

0 comments on commit 53aef96

Please sign in to comment.