@GET
@Path("/tpstats")
public Response tpstats() throws IOException, ExecutionException, InterruptedException, JSONException
{
JMXNodeTool nodetool = null;
try {
nodetool = JMXNodeTool.instance(config);
} catch (JMXConnectionException e) {
return Response.status(503).entity("JMXConnectionException")
.build();
}
Iterator<Map.Entry<String, JMXEnabledThreadPoolExecutorMBean>> threads = nodetool.getThreadPoolMBeanProxies();
JSONArray threadPoolArray = new JSONArray();
while (threads.hasNext())
{
Entry<String, JMXEnabledThreadPoolExecutorMBean> thread = threads.next();
JMXEnabledThreadPoolExecutorMBean threadPoolProxy = thread.getValue();
JSONObject tpObj = new JSONObject();// "Pool Name", "Active",
// "Pending", "Completed",
// "Blocked", "All time blocked"
tpObj.put("pool name", thread.getKey());
tpObj.put("active", threadPoolProxy.getActiveCount());
tpObj.put("pending", threadPoolProxy.getPendingTasks());
tpObj.put("completed", threadPoolProxy.getCompletedTasks());
tpObj.put("blocked", threadPoolProxy.getCurrentlyBlockedTasks());
tpObj.put("total blocked", threadPoolProxy.getTotalBlockedTasks());
threadPoolArray.put(tpObj);
}
JSONObject droppedMsgs = new JSONObject();
for (Entry<String, Integer> entry : nodetool.getDroppedMessages().entrySet())
droppedMsgs.put(entry.getKey(), entry.getValue());
JSONObject rootObj = new JSONObject();
rootObj.put("thread pool", threadPoolArray);
rootObj.put("dropped messages", droppedMsgs);