Map<String, String> metricCriteria = (Map<String, String>) item.get("metricCriteria");
String metricName = (String) item.get("name");
float origValue = ((Number) item.get("value")).floatValue();
float origDiff = ((Number) item.get("diff")).floatValue();
Pair pair = getUnitsLabel(metricName, metricCriteria, ((Number) item.get("value")).doubleValue(), true);
item.put("value", ((Number)pair.first).floatValue());
Pair pairDiff = getUnitsLabel(metricName, metricCriteria, ((Number) item.get("diff")).doubleValue(), true);
item.put("diff", ((Number)pairDiff.first).floatValue());
/*
* Just render an explanation subheader for the first item since it
* has the highest stddev and will be selected by the client
*/
if (first) {
first = false;
String explanation = getMetricConfigValueNotNull(metricName, metricCriteria, "explanation");
double previous = origValue - origDiff;
if (metricName.equals("CONNECTION_RESOURCE_USAGE") && metricCriteria.containsKey("RESOURCE_ID")) { // TODO hack for IMG
explanation = metricCriteria.get("RESOURCE_ID") + " was previously at %.2f and is now at %.2f";
}
if (explanation.length() > 0) {
explanation = MessageFormat.format(explanation, String.valueOf(previous), String.valueOf(pair.first) );
}
item.put("subheader", explanation);
}
item.put("name", metricTypeNameReadable(metricName, metricCriteria));
item.put("metricname", metricName); // needed for debugging
item.put("unit", pair.second);
}
HashMap<String, Object> structure = new HashMap<>();
structure.put("accountId", meta.get("account"));
structure.put("total", meta.get("total"));
structure.put("diff", meta.get("diff"));
structure.put("type", providerId);
structure.put("items", items); // add the updated items
structure.put("granularity", meta.get("granularity"));
// set rich formatting properties
// the client will render the table in "structure" how it wants to
messageDetails = new NodebellySummaryMessageDetails.Builder()
.title(title)
.structure(structure)
.build();
// just print the key/value pairs for the plain text version
details = ((NodebellySummaryMessageDetails) messageDetails).toPlainText();
}
break;
case NODEBELLY_ANOMALY:
String connectionName = "";
if (meta.containsKey("targetConnectionAlias")) {
connectionName = ((String) meta.get("targetConnectionAlias"));
}
String inventoryName = "";
if (meta.containsKey("targetAlias")) {
inventoryName = " for " + ((String) meta.get("targetAlias"));
}
providerId = (String) meta.get("targetProviderId");
String metricName = (String) meta.get("name");
float fValue = ((Number) meta.get("value")).floatValue();
float fMean = ((Number) meta.get("mean")).floatValue();
float fStddev = ((Number) meta.get("stddev")).floatValue();
int nStdDev = Double.valueOf(Math.floor(Math.abs(fValue - fMean) / fStddev)).intValue();
Pair pair1 = getUnitsLabel(metricName, topMetricCriteria, fValue, true);
//Pair pair2 = getUnitsLabel(metricName, topMetricCriteria, fStddev, true);
Pair pair3 = getUnitsLabel(metricName, topMetricCriteria, fMean, true);
int severity = getSeverityLevel(fValue, fMean, fStddev);
title = MessageFormat.format((String) messageProperties.get("message.nodebelly.anomalyseverity" + severity),
metricTypeNameReadable(metricName, topMetricCriteria),
connectionName);