Commit a1196840 authored by Node- 门 忠鑫's avatar Node- 门 忠鑫

# enoch agent

parent 41be1f07
package cn.quantgroup.tech.enoch.agent; package cn.quantgroup.tech.enoch.agent;
import cn.quantgroup.tech.enoch.agent.report.IReportService; import cn.quantgroup.tech.enoch.agent.report.IReportService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
...@@ -11,7 +12,7 @@ import org.springframework.stereotype.Component; ...@@ -11,7 +12,7 @@ import org.springframework.stereotype.Component;
*/ */
@Component @Component
@EnableScheduling @EnableScheduling
public class TimerTask { public class AgentReportTask {
@Autowired @Autowired
private IReportService reportService; private IReportService reportService;
......
package cn.quantgroup.tech.enoch.agent.configuration; package cn.quantgroup.tech.enoch.agent.configuration;
import cn.quantgroup.tech.enoch.agent.AgentReportTask;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.producer.ProducerConfig; import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.serialization.StringSerializer; import org.apache.kafka.common.serialization.StringSerializer;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.kafka.core.DefaultKafkaProducerFactory; import org.springframework.kafka.core.DefaultKafkaProducerFactory;
import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.ProducerFactory; import org.springframework.kafka.core.ProducerFactory;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import java.util.HashMap; import java.util.HashMap;
import java.util.concurrent.ScheduledThreadPoolExecutor;
/** /**
* @author: amen * @author: amen
...@@ -21,16 +25,15 @@ import java.util.HashMap; ...@@ -21,16 +25,15 @@ import java.util.HashMap;
*/ */
@Slf4j @Slf4j
@Configuration @Configuration
@EnableConfigurationProperties({EnochAgentProperties.class}) @ComponentScan(basePackageClasses = {AgentReportTask.class})
@EnableConfigurationProperties(EnochAgentProperties.class)
public class EnochAgentAutoConfiguration { public class EnochAgentAutoConfiguration {
@Autowired @Autowired
private EnochAgentProperties enochAgentProperties; private EnochAgentProperties enochAgentProperties;
@Bean @Bean
@ConditionalOnBean(EnochAgentProperties.class) @ConditionalOnBean(EnochAgentProperties.class)
@ConditionalOnMissingBean
public ProducerFactory<String, String> producerFactory() { public ProducerFactory<String, String> producerFactory() {
HashMap<String, Object> config = new HashMap<>(16); HashMap<String, Object> config = new HashMap<>(16);
config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, enochAgentProperties.getKafkaHost()); config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, enochAgentProperties.getKafkaHost());
...@@ -47,4 +50,12 @@ public class EnochAgentAutoConfiguration { ...@@ -47,4 +50,12 @@ public class EnochAgentAutoConfiguration {
} }
@Configuration
public static class ScheduleConfig implements SchedulingConfigurer {
@Override
public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(2);
taskRegistrar.setScheduler(executor);
}
}
} }
\ No newline at end of file
...@@ -12,6 +12,5 @@ import org.springframework.boot.context.properties.ConfigurationProperties; ...@@ -12,6 +12,5 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public class EnochAgentProperties { public class EnochAgentProperties {
private String kafkaHost; private String kafkaHost;
private String kafkaTopic; private String kafkaTopic;
private Long reportRate = 30000L;
} }
...@@ -48,8 +48,8 @@ public class ReportServiceImpl implements IReportService { ...@@ -48,8 +48,8 @@ public class ReportServiceImpl implements IReportService {
@Override @Override
public void report() { public void report() {
log.info("enoch.agent report");
int size = arrayBlockingQueue.size(); int size = arrayBlockingQueue.size();
log.info("enoch.agent report data, size: {}", size);
List<Map<String, Object>> slice = new ArrayList<>(size); List<Map<String, Object>> slice = new ArrayList<>(size);
arrayBlockingQueue.drainTo(slice, size); arrayBlockingQueue.drainTo(slice, size);
Map<String, Object> pushPackage = new HashMap<>(6); Map<String, Object> pushPackage = new HashMap<>(6);
...@@ -65,8 +65,7 @@ public class ReportServiceImpl implements IReportService { ...@@ -65,8 +65,7 @@ public class ReportServiceImpl implements IReportService {
@Override @Override
public void collect() { public void collect() {
log.info("enoch.agent collect"); log.info("enoch.agent collect data");
//todo 添加timestamp
HashMap<String, Object> endPoints = new HashMap<>(16); HashMap<String, Object> endPoints = new HashMap<>(16);
endPoints.put("health", healthEndpoint.invoke()); endPoints.put("health", healthEndpoint.invoke());
endPoints.put("metrics", metricsEndpoint.invoke()); endPoints.put("metrics", metricsEndpoint.invoke());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment