@Produces(TEXT_PLAIN)
public String threaddump() {
checkPermission(RestPermissions.THREADS_DUMP, serverStatus.getNodeId().toString());
// The ThreadDump is built by internal codahale.metrics servlet library we are abusing.
ThreadDump threadDump = new ThreadDump(ManagementFactory.getThreadMXBean());
ByteArrayOutputStream output = new ByteArrayOutputStream();
threadDump.dump(output);
return new String(output.toByteArray(), StandardCharsets.UTF_8);
}