metricsData.put("name", metricName);
List<Object> values = Lists.newArrayList();
metricsData.put("values", values);
while (cursor.hasNext()) {
final DBObject value = cursor.next();
metricsData.put("node", value.get("node"));
final MetricType metricType = MetricType.valueOf(((String) value.get("type")).toUpperCase());
Map<String, Object> dataPoint = Maps.newHashMap();
values.add(dataPoint);
dataPoint.put("timestamp", value.get("timestamp"));
metricsData.put("type", metricType.toString().toLowerCase());
switch (metricType) {
case GAUGE:
final Object gaugeValue = value.get("value");
dataPoint.put("value", gaugeValue);
break;
case COUNTER:
dataPoint.put("count", value.get("count"));
break;
case HISTOGRAM:
dataPoint.put("75-percentile", value.get("75-percentile"));
dataPoint.put("95-percentile", value.get("95-percentile"));
dataPoint.put("98-percentile", value.get("98-percentile"));
dataPoint.put("99-percentile", value.get("99-percentile"));
dataPoint.put("999-percentile", value.get("999-percentile"));
dataPoint.put("max", value.get("max"));
dataPoint.put("min", value.get("min"));
dataPoint.put("mean", value.get("mean"));
dataPoint.put("median", value.get("median"));
dataPoint.put("std_dev", value.get("std_dev"));
break;
case METER:
dataPoint.put("count", value.get("count"));
dataPoint.put("1-minute-rate", value.get("1-minute-rate"));
dataPoint.put("5-minute-rate", value.get("5-minute-rate"));
dataPoint.put("15-minute-rate", value.get("15-minute-rate"));
dataPoint.put("mean-rate", value.get("mean-rate"));
break;
case TIMER:
dataPoint.put("count", value.get("count"));
dataPoint.put("rate-unit", value.get("rate-unit"));
dataPoint.put("1-minute-rate", value.get("1-minute-rate"));
dataPoint.put("5-minute-rate", value.get("5-minute-rate"));
dataPoint.put("15-minute-rate", value.get("15-minute-rate"));
dataPoint.put("mean-rate", value.get("mean-rate"));
dataPoint.put("duration-unit", value.get("duration-unit"));
dataPoint.put("75-percentile", value.get("75-percentile"));
dataPoint.put("95-percentile", value.get("95-percentile"));
dataPoint.put("98-percentile", value.get("98-percentile"));
dataPoint.put("99-percentile", value.get("99-percentile"));
dataPoint.put("999-percentile", value.get("999-percentile"));
dataPoint.put("max", value.get("max"));
dataPoint.put("min", value.get("min"));
dataPoint.put("mean", value.get("mean"));
dataPoint.put("median", value.get("median"));
dataPoint.put("stddev", value.get("stddev"));
break;
}
}