|
@@ -3,11 +3,13 @@ package com.github.ltsopensource.core.monitor;
|
|
|
import com.github.ltsopensource.core.AppContext;
|
|
|
import com.github.ltsopensource.core.cluster.Config;
|
|
|
import com.github.ltsopensource.core.cluster.NodeType;
|
|
|
+import com.github.ltsopensource.core.commons.utils.Callable;
|
|
|
import com.github.ltsopensource.core.constant.ExtConfig;
|
|
|
import com.github.ltsopensource.core.domain.monitor.MData;
|
|
|
import com.github.ltsopensource.core.factory.NamedThreadFactory;
|
|
|
import com.github.ltsopensource.core.logger.Logger;
|
|
|
import com.github.ltsopensource.core.logger.LoggerFactory;
|
|
|
+import com.github.ltsopensource.core.support.NodeShutdownHook;
|
|
|
import com.github.ltsopensource.jvmmonitor.JVMMonitor;
|
|
|
|
|
|
import java.util.concurrent.Executors;
|
|
@@ -41,17 +43,25 @@ public abstract class AbstractMStatReporter implements MStatReporter {
|
|
|
// 启动JVM监控
|
|
|
JVMMonitor.start();
|
|
|
|
|
|
+ final MStatReportWorker worker = new MStatReportWorker(appContext, this);
|
|
|
+
|
|
|
try {
|
|
|
if (!config.getParameter(ExtConfig.M_STAT_REPORTER_CLOSED, false)) {
|
|
|
if (start.compareAndSet(false, true)) {
|
|
|
- scheduledFuture = executor.scheduleWithFixedDelay(
|
|
|
- new MStatReportWorker(appContext, this), 1, 1, TimeUnit.SECONDS);
|
|
|
+ scheduledFuture = executor.scheduleWithFixedDelay(worker, 1, 1, TimeUnit.SECONDS);
|
|
|
LOGGER.info("MStatReporter start succeed.");
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
LOGGER.error("MStatReporter start failed.", e);
|
|
|
}
|
|
|
+
|
|
|
+ NodeShutdownHook.registerHook(appContext, this.getClass().getName(), new Callable() {
|
|
|
+ @Override
|
|
|
+ public void call() throws Exception {
|
|
|
+ worker.run();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
/**
|