Example #1
0
 public static boolean isUsingSsl() {
   return server.isUsingSsl();
 }
Example #2
0
  public void run(String hostname) {
    try {
      getMonitorLock();
    } catch (Exception e) {
      log.error("Failed to get Monitor ZooKeeper lock");
      throw new RuntimeException(e);
    }

    Monitor.START_TIME = System.currentTimeMillis();
    int port = config.getConfiguration().getPort(Property.MONITOR_PORT);
    try {
      log.debug("Creating monitor on port " + port);
      server = new EmbeddedWebServer(hostname, port);
    } catch (Throwable ex) {
      log.error("Unable to start embedded web server", ex);
      throw new RuntimeException(ex);
    }

    server.addServlet(DefaultServlet.class, "/");
    server.addServlet(OperationServlet.class, "/op");
    server.addServlet(MasterServlet.class, "/master");
    server.addServlet(TablesServlet.class, "/tables");
    server.addServlet(TServersServlet.class, "/tservers");
    server.addServlet(ProblemServlet.class, "/problems");
    server.addServlet(GcStatusServlet.class, "/gc");
    server.addServlet(LogServlet.class, "/log");
    server.addServlet(XMLServlet.class, "/xml");
    server.addServlet(JSONServlet.class, "/json");
    server.addServlet(VisServlet.class, "/vis");
    server.addServlet(Summary.class, "/trace/summary");
    server.addServlet(ListType.class, "/trace/listType");
    server.addServlet(ShowTrace.class, "/trace/show");
    if (server.isUsingSsl()) server.addServlet(ShellServlet.class, "/shell");
    server.start();

    try {
      hostname = InetAddress.getLocalHost().getHostName();

      log.debug("Using " + hostname + " to advertise monitor location in ZooKeeper");

      String monitorAddress = HostAndPort.fromParts(hostname, server.getPort()).toString();

      ZooReaderWriter.getInstance()
          .putPersistentData(
              ZooUtil.getRoot(instance) + Constants.ZMONITOR_HTTP_ADDR,
              monitorAddress.getBytes(StandardCharsets.UTF_8),
              NodeExistsPolicy.OVERWRITE);
      log.info("Set monitor address in zookeeper to " + monitorAddress);
    } catch (Exception ex) {
      log.error("Unable to set monitor HTTP address in zookeeper", ex);
    }

    if (null != hostname) {
      LogService.startLogListener(
          Monitor.getSystemConfiguration(), instance.getInstanceID(), hostname);
    } else {
      log.warn("Not starting log4j listener as we could not determine address to use");
    }

    new Daemon(new LoggingRunnable(log, new ZooKeeperStatus()), "ZooKeeperStatus").start();

    // need to regularly fetch data so plot data is updated
    new Daemon(
            new LoggingRunnable(
                log,
                new Runnable() {

                  @Override
                  public void run() {
                    while (true) {
                      try {
                        Monitor.fetchData();
                      } catch (Exception e) {
                        log.warn(e.getMessage(), e);
                      }

                      UtilWaitThread.sleep(333);
                    }
                  }
                }),
            "Data fetcher")
        .start();
  }