public static String dumpBeanToString(String qry)
    throws MalformedObjectNameException, IOException {
    StringWriter sw = new StringWriter(1024 * 100); // Guess this size
    try (PrintWriter writer = new PrintWriter(sw)) {
      JSONBean dumper = new JSONBean();
      try (JSONBean.Writer jsonBeanWriter = dumper.open(writer)) {
        MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
        jsonBeanWriter.write(mbeanServer, new ObjectName(qry), null, false);
      }
    }
    sw.close();
    return sw.toString();
  }
Returns a subset of mbeans defined by qry. Modeled after DumpRegionServerMetrics#dumpMetrics.
Example: String qry= "java.lang:type=Memory"
@throws MalformedObjectNameException if json have bad format
@throws IOException                  /
@return String representation of json array.
hbase-http/src/main/java/org/apache/hadoop/hbase/util/JSONMetricUtil.java