public Response compactionStats()

in priam/src/main/java/com/netflix/priam/resources/CassandraAdmin.java [295:331]


    public Response compactionStats()
            throws IOException, ExecutionException, InterruptedException, JSONException {
        JMXNodeTool nodeTool;
        try {
            nodeTool = JMXNodeTool.instance(config);
        } catch (JMXConnectionException e) {
            logger.error(
                    "Exception in fetching c* jmx tool .  Msgl: {}", e.getLocalizedMessage(), e);
            return Response.status(503).entity("JMXConnectionException").build();
        }
        JSONObject rootObj = new JSONObject();
        CompactionManagerMBean cm = nodeTool.getCompactionManagerProxy();
        rootObj.put("pending tasks", cm.getPendingTasks());
        JSONArray compStats = new JSONArray();
        for (Map<String, String> c : cm.getCompactions()) {
            JSONObject cObj = new JSONObject();
            cObj.put("id", c.get("id"));
            cObj.put("keyspace", c.get("keyspace"));
            cObj.put("columnfamily", c.get("columnfamily"));
            cObj.put("bytesComplete", c.get("bytesComplete"));
            cObj.put("totalBytes", c.get("totalBytes"));
            cObj.put("taskType", c.get("taskType"));
            String percentComplete =
                    new Long(c.get("totalBytes")) == 0
                            ? "n/a"
                            : new DecimalFormat("0.00")
                                            .format(
                                                    (double) new Long(c.get("bytesComplete"))
                                                            / new Long(c.get("totalBytes"))
                                                            * 100)
                                    + "%";
            cObj.put("progress", percentComplete);
            compStats.put(cObj);
        }
        rootObj.put("compaction stats", compStats);
        return Response.ok(rootObj, MediaType.APPLICATION_JSON).build();
    }