List of usage examples for org.apache.cassandra.db.compaction CompactionManagerMBean getCompactions
public List<Map<String, String>> getCompactions();
From source file:c3.ops.priam.resources.CassandraAdmin.java
License:Apache License
@GET @Path("/compactionstats") public Response compactionStats() throws IOException, ExecutionException, InterruptedException, JSONException { JMXNodeTool nodetool = null;//from w ww . j a v a 2 s.c o m try { nodetool = JMXNodeTool.instance(config); } catch (JMXConnectionException 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(); }
From source file:com.netflix.priam.resources.CassandraAdminResource.java
License:Apache License
@GET @Path("/compactionstats") public Response compactionStats() throws Exception { JMXNodeTool nodetool = getNodeTool(); Map<String, Object> rootObj = Maps.newLinkedHashMap(); CompactionManagerMBean cm = nodetool.getCompactionManagerProxy(); rootObj.put("pending tasks", cm.getCompactions()); List<Map<String, Object>> compStats = Lists.newArrayList(); for (Map<String, String> c : cm.getCompactions()) { Map<String, Object> cObj = Maps.newLinkedHashMap(); 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.add(cObj);/* w w w.j a v a 2s. com*/ } rootObj.put("compaction stats", compStats); return Response.ok(rootObj, MediaType.APPLICATION_JSON).build(); }
From source file:com.perpetumobile.bit.orm.cassandra.CliMain.java
License:Apache License
private void describeKeySpace(String keySpaceName, KsDef metadata) throws TException { NodeProbe probe = sessionState.getNodeProbe(); // getting compaction manager MBean to displaying index building information CompactionManagerMBean compactionManagerMBean = (probe == null) ? null : probe.getCompactionManagerProxy(); // Describe and display sessionState.out.println("Keyspace: " + keySpaceName + ":"); try {//from w ww . j a v a 2s .c o m KsDef ks_def; ks_def = metadata == null ? thriftClient.describe_keyspace(keySpaceName) : metadata; sessionState.out.println(" Replication Strategy: " + ks_def.strategy_class); sessionState.out.println(" Durable Writes: " + ks_def.durable_writes); Map<String, String> options = ks_def.strategy_options; sessionState.out .println(" Options: [" + ((options == null) ? "" : FBUtilities.toString(options)) + "]"); sessionState.out.println(" Column Families:"); Collections.sort(ks_def.cf_defs, new CfDefNamesComparator()); for (CfDef cf_def : ks_def.cf_defs) describeColumnFamily(ks_def, cf_def, probe); // compaction manager information if (compactionManagerMBean != null) { for (Map<String, String> info : compactionManagerMBean.getCompactions()) { // if ongoing compaction type is index build if (info.get("taskType").equals(OperationType.INDEX_BUILD.toString())) continue; sessionState.out.printf("%nCurrently building index %s, completed %d of %d bytes.%n", info.get("columnfamily"), info.get("bytesComplete"), info.get("totalBytes")); } } // closing JMX connection if (probe != null) probe.close(); } catch (InvalidRequestException e) { sessionState.out.println("Invalid request: " + e); } catch (NotFoundException e) { sessionState.out.println("Keyspace " + keySpaceName + " could not be found."); } catch (IOException e) { sessionState.out.println("Error while closing JMX connection: " + e.getMessage()); } }