use of org.apache.accumulo.fate.util.LoggingRunnable in project accumulo by apache.
the class Monitor method run.
public void run(String hostname) {
Monitor.START_TIME = System.currentTimeMillis();
int[] ports = config.getSystemConfiguration().getPort(Property.MONITOR_PORT);
for (int port : ports) {
try {
log.debug("Creating monitor on port {}", port);
server = new EmbeddedWebServer(hostname, port);
server.addServlet(getDefaultServlet(), "/resources/*");
server.addServlet(getRestServlet(), "/rest/*");
server.addServlet(getViewServlet(), "/*");
server.start();
break;
} catch (Throwable ex) {
log.error("Unable to start embedded web server", ex);
}
}
if (!server.isRunning()) {
throw new RuntimeException("Unable to start embedded web server on ports: " + Arrays.toString(ports));
}
try {
getMonitorLock();
} catch (Exception e) {
log.error("Failed to get Monitor ZooKeeper lock");
throw new RuntimeException(e);
}
String advertiseHost = hostname;
if (advertiseHost.equals("0.0.0.0")) {
try {
advertiseHost = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
log.error("Unable to get hostname", e);
}
}
log.debug("Using {} to advertise monitor location in ZooKeeper", advertiseHost);
try {
String monitorAddress = HostAndPort.fromParts(advertiseHost, server.getPort()).toString();
ZooReaderWriter.getInstance().putPersistentData(ZooUtil.getRoot(instance) + Constants.ZMONITOR_HTTP_ADDR, monitorAddress.getBytes(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 != advertiseHost) {
LogService.startLogListener(Monitor.getContext().getConfiguration(), instance.getInstanceID(), advertiseHost);
} 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);
}
sleepUninterruptibly(333, TimeUnit.MILLISECONDS);
}
}
}), "Data fetcher").start();
new Daemon(new LoggingRunnable(log, new Runnable() {
@Override
public void run() {
while (true) {
try {
Monitor.fetchScans();
} catch (Exception e) {
log.warn("{}", e.getMessage(), e);
}
sleepUninterruptibly(5, TimeUnit.SECONDS);
}
}
}), "Scan scanner").start();
monitorInitialized.set(true);
}
Aggregations