@GET
@Path("/netstats")
public Response netstats(@QueryParam("host") String hostname) throws IOException, ExecutionException, InterruptedException, JSONException
{
JMXNodeTool nodetool = null;
try {
nodetool = JMXNodeTool.instance(config);
} catch (JMXConnectionException e) {
return Response.status(503).entity("JMXConnectionException")
.build();
}
JSONObject rootObj = new JSONObject();
rootObj.put("mode", nodetool.getOperationMode());
final InetAddress addr = (hostname == null) ? null : InetAddress.getByName(hostname);
Set<InetAddress> hosts = addr == null ? nodetool.getStreamDestinations() : new HashSet<InetAddress>()
{
{
add(addr);
}
};
if (hosts.size() == 0)
rootObj.put("sending", "Not sending any streams.");
JSONObject hostSendStats = new JSONObject();
for (InetAddress host : hosts)
{
try
{
List<String> files = nodetool.getFilesDestinedFor(host);
if (files.size() > 0)
{
JSONArray fObj = new JSONArray();
for (String file : files)
fObj.put(file);
hostSendStats.put(host.getHostAddress(), fObj);
}
}
catch (IOException ex)
{
hostSendStats.put(host.getHostAddress(), "Error retrieving file data");
}
}
rootObj.put("hosts sending", hostSendStats);
hosts = addr == null ? nodetool.getStreamSources() : new HashSet<InetAddress>()
{
{
add(addr);
}
};
if (hosts.size() == 0)
rootObj.put("receiving", "Not receiving any streams.");
JSONObject hostRecvStats = new JSONObject();
for (InetAddress host : hosts)
{
try
{
List<String> files = nodetool.getIncomingFiles(host);
if (files.size() > 0)
{
JSONArray fObj = new JSONArray();
for (String file : files)
fObj.put(file);