增强客户端数据采集定制化.

pull/39/head
chen.ma 3 years ago
parent 2bd4da24db
commit 60a0a34896

@ -37,7 +37,22 @@ public class BootstrapProperties {
/** /**
* Print dynamic thread pool banner * Print dynamic thread pool banner
*/ */
private boolean banner = true; private Boolean banner = true;
/**
* Enable client data collect
*/
private Boolean enableCollect = true;
/**
* Task buffer container capacity
*/
private Integer taskBufferSize = 4096;
/**
* Delay starting data acquisition task. unit: ms
*/
private Long initialDelay = 10000L;
/** /**
* Time interval for client to collect monitoring data. unit: ms * Time interval for client to collect monitoring data. unit: ms

@ -42,7 +42,7 @@ public class DynamicThreadPoolBannerHandler implements InitializingBean {
"|___/ \\_, |_||_\\__,_|_|_|_|_\\__| |_| |_| \n" + "|___/ \\_, |_||_\\__,_|_|_|_|_\\__| |_| |_| \n" +
" |__/ \n"; " |__/ \n";
if (properties.isBanner()) { if (properties.getBanner()) {
String version = getVersion(); String version = getVersion();
version = (version != null) ? " (v" + version + ")" : "no version."; version = (version != null) ? " (v" + version + ")" : "no version.";

@ -47,22 +47,19 @@ public class ReportingEventExecutor implements Runnable, CommandLineRunner, Disp
private final ServerHealthCheck serverHealthCheck; private final ServerHealthCheck serverHealthCheck;
/** /**
* *
*/ */
private Map<String, Collector> collectors; private Map<String, Collector> collectors;
/** /**
* , ReportingEventExecutor * , ReportingEventExecutor
*/ */
private final BlockingQueue<Message> messageCollectVessel = new ArrayBlockingQueue(4096); private BlockingQueue<Message> messageCollectVessel;
/** /**
* , Spring 线 * , Spring 线
*/ */
private final ScheduledThreadPoolExecutor collectVesselExecutor = new ScheduledThreadPoolExecutor( private ScheduledThreadPoolExecutor collectVesselExecutor;
new Integer(1),
ThreadFactoryBuilder.builder().daemon(true).prefix("collect-data-scheduled").build()
);
@SneakyThrows @SneakyThrows
@Override @Override
@ -79,13 +76,32 @@ public class ReportingEventExecutor implements Runnable, CommandLineRunner, Disp
@Override @Override
public void run(String... args) { public void run(String... args) {
long initialDelay = 100000; if (properties.getEnableCollect()) {
String reportingTaskName = "reporting-task"; Integer bufferSize = properties.getTaskBufferSize();
// 延迟 initialDelay 后循环调用. scheduleWithFixedDelay 每次执行时间为上一次任务结束时, 向后推一个时间间隔 messageCollectVessel = new ArrayBlockingQueue(bufferSize);
collectVesselExecutor.scheduleWithFixedDelay(() -> runTimeGatherTask(), initialDelay, properties.getCollectInterval(), TimeUnit.MILLISECONDS);
ThreadUtil.newThread(this, reportingTaskName, Boolean.TRUE).start(); String collectVesselTaskName = "collect-data-scheduled";
collectVesselExecutor = new ScheduledThreadPoolExecutor(
new Integer(1),
ThreadFactoryBuilder.builder().daemon(true).prefix(collectVesselTaskName).build()
);
// 延迟 initialDelay 后循环调用. scheduleWithFixedDelay 每次执行时间为上一次任务结束时, 向后推一个时间间隔
collectVesselExecutor.scheduleWithFixedDelay(
() -> runTimeGatherTask(),
properties.getInitialDelay(),
properties.getCollectInterval(),
TimeUnit.MILLISECONDS
);
// 启动上报监控数据线程
String reportingTaskName = "reporting-task";
ThreadUtil.newThread(this, reportingTaskName, Boolean.TRUE).start();
// 获取所有数据采集组件, 目前仅有历史运行数据采集
collectors = ApplicationContextHolder.getBeansOfType(Collector.class);
}
collectors = ApplicationContextHolder.getBeansOfType(Collector.class);
log.info("Dynamic thread pool :: [{}]. The dynamic thread pool starts data collection and reporting. ", getThreadPoolNum()); log.info("Dynamic thread pool :: [{}]. The dynamic thread pool starts data collection and reporting. ", getThreadPoolNum());
} }

Loading…
Cancel
Save