Java 类org.apache.hadoop.hbase.util.JSONBean 实例源码

项目:hbase    文件:DumpRegionServerMetrics.java   
/**
 * Dump out a subset of regionserver mbeans only, not all of them, as json on System.out.
 */
public static String dumpMetrics() 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("java.lang:type=Memory"), null, false);
      jsonBeanWriter.write(mbeanServer,
        new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=IPC"), null, false);
      jsonBeanWriter.write(mbeanServer,
        new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=Replication"), null, false);
      jsonBeanWriter.write(mbeanServer,
        new ObjectName("Hadoop:service=HBase,name=RegionServer,sub=Server"), null, false);
    }
  }
  sw.close();
  return sw.toString();
}
项目:ditb    文件:JMXJsonServlet.java   
/**
 * Initialize this servlet.
 */
@Override
public void init() throws ServletException {
  // Retrieve the MBean server
  mBeanServer = ManagementFactory.getPlatformMBeanServer();
  this.jsonBeanWriter = new JSONBean();
}
项目:ditb    文件:HRegionServer.java   
/**
 * Cause the server to exit without closing the regions it is serving, the log
 * it is using and without notifying the master. Used unit testing and on
 * catastrophic events such as HDFS is yanked out from under hbase or we OOME.
 *
 * @param reason the reason we are aborting
 * @param cause  the exception that caused the abort, or null
 */
@Override public void abort(String reason, Throwable cause) {
  String msg = "ABORTING region server " + this + ": " + reason;
  if (cause != null) {
    LOG.fatal(msg, cause);
  } else {
    LOG.fatal(msg);
  }
  this.abortRequested = true;
  // HBASE-4014: show list of coprocessors that were loaded to help debug
  // regionserver crashes.Note that we're implicitly using
  // java.util.HashSet's toString() method to print the coprocessor names.
  LOG.fatal(
      "RegionServer abort: loaded coprocessors are: " + CoprocessorHost.getLoadedCoprocessors());
  // Try and dump metrics if abort -- might give clue as to how fatal came about....
  try {
    LOG.info("Dump of metrics as JSON on abort: " + JSONBean.dumpRegionServerMetrics());
  } catch (MalformedObjectNameException | IOException e) {
    LOG.warn("Failed dumping metrics", e);
  }

  // Do our best to report our abort to the master, but this may not work
  try {
    if (cause != null) {
      msg += "\nCause:\n" + StringUtils.stringifyException(cause);
    }
    // Report to the master but only if we have already registered with the master.
    if (rssStub != null && this.serverName != null) {
      ReportRSFatalErrorRequest.Builder builder = ReportRSFatalErrorRequest.newBuilder();
      ServerName sn = ServerName.parseVersionedServerName(this.serverName.getVersionedBytes());
      builder.setServer(ProtobufUtil.toServerName(sn));
      builder.setErrorMessage(msg);
      rssStub.reportRSFatalError(null, builder.build());
    }
  } catch (Throwable t) {
    LOG.warn("Unable to report fatal error to master", t);
  }
  stop(reason);
}
项目:pbase    文件:JMXJsonServlet.java   
/**
 * Initialize this servlet.
 */
@Override
public void init() throws ServletException {
  // Retrieve the MBean server
  mBeanServer = ManagementFactory.getPlatformMBeanServer();
  this.jsonBeanWriter = new JSONBean();
}
项目:hbase    文件:JMXJsonServlet.java   
/**
 * Initialize this servlet.
 */
@Override
public void init() throws ServletException {
  // Retrieve the MBean server
  mBeanServer = ManagementFactory.getPlatformMBeanServer();
  this.jsonBeanWriter = new JSONBean();
}
项目:pbase    文件:HRegionServer.java   
/**
 * Cause the server to exit without closing the regions it is serving, the log
 * it is using and without notifying the master. Used unit testing and on
 * catastrophic events such as HDFS is yanked out from under hbase or we OOME.
 *
 * @param reason the reason we are aborting
 * @param cause  the exception that caused the abort, or null
 */
@Override
public void abort(String reason, Throwable cause) {
    String msg = "ABORTING region server " + this + ": " + reason;
    if (cause != null) {
        LOG.fatal(msg, cause);
    } else {
        LOG.fatal(msg);
    }
    this.abortRequested = true;
    // HBASE-4014: show list of coprocessors that were loaded to help debug
    // regionserver crashes.Note that we're implicitly using
    // java.util.HashSet's toString() method to print the coprocessor names.
    LOG.fatal("RegionServer abort: loaded coprocessors are: " +
            CoprocessorHost.getLoadedCoprocessors());
    // Try and dump metrics if abort -- might give clue as to how fatal came about....
    try {
        LOG.info("Dump of metrics as JSON on abort: " + JSONBean.dumpRegionServerMetrics());
    } catch (MalformedObjectNameException | IOException e) {
        LOG.warn("Failed dumping metrics", e);
    }

    // Do our best to report our abort to the master, but this may not work
    try {
        if (cause != null) {
            msg += "\nCause:\n" + StringUtils.stringifyException(cause);
        }
        // Report to the master but only if we have already registered with the master.
        if (rssStub != null && this.serverName != null) {
            ReportRSFatalErrorRequest.Builder builder =
                    ReportRSFatalErrorRequest.newBuilder();
            ServerName sn =
                    ServerName.parseVersionedServerName(this.serverName.getVersionedBytes());
            builder.setServer(ProtobufUtil.toServerName(sn));
            builder.setErrorMessage(msg);
            rssStub.reportRSFatalError(null, builder.build());
        }
    } catch (Throwable t) {
        LOG.warn("Unable to report fatal error to master", t);
    }
    stop(reason);
}