scylla-jmx: Add "PendingTasksByTableName" gauge to CompactionMetrics

Required by origin 3.11 nodetool.

Message-Id: <20180801084545.23239-1-calle@scylladb.com>
This commit is contained in:
Calle Wilund 2018-08-01 08:45:45 +00:00 committed by Avi Kivity
parent 9c3ac3e547
commit c6aee9f63e

View File

@ -23,6 +23,11 @@
*/
package org.apache.cassandra.metrics;
import java.util.HashMap;
import java.util.Map;
import javax.json.JsonArray;
import javax.json.JsonObject;
import javax.management.MalformedObjectNameException;
/**
@ -47,6 +52,25 @@ public class CompactionMetrics implements Metrics {
/** Total number of bytes compacted since server [re]start */
registry.register(() -> registry.meter("/compaction_manager/metrics/bytes_compacted"),
factory.createMetricName("BytesCompacted"));
}
registry.register(() -> registry.gauge((client) -> {
Map<String, Map<String, Integer>> result = new HashMap<>();
JsonArray compactions = client.getJsonArray("compaction_manager/compactions");
for (int i = 0; i < compactions.size(); i++) {
JsonObject c = compactions.getJsonObject(i);
String ks = c.getString("ks");
String cf = c.getString("cf");
if (!result.containsKey(ks)) {
result.put(ks, new HashMap<>());
}
Map<String, Integer> map = result.get(ks);
map.put(cf, (int)(c.getJsonNumber("total").longValue() - c.getJsonNumber("completed").longValue()));
}
return result;
}), factory.createMetricName("PendingTasksByTableName"));
}
}