Commit 573fcd8e authored by Node- 门 忠鑫's avatar Node- 门 忠鑫

# 修改上报时间间隔

parent a1196840
......@@ -26,9 +26,9 @@ public class AgentReportTask {
}
/**
* 30毫秒上报一次数据
* 1毫秒上报一次数据
*/
@Scheduled(fixedRate = 30000)
@Scheduled(fixedRate = 1000)
public void report() {
reportService.report();
}
......
......@@ -2,6 +2,7 @@ package cn.quantgroup.tech.enoch.agent.configuration;
import cn.quantgroup.tech.enoch.agent.AgentReportTask;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.common.serialization.StringSerializer;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -33,7 +34,6 @@ public class EnochAgentAutoConfiguration {
private EnochAgentProperties enochAgentProperties;
@Bean
@ConditionalOnBean(EnochAgentProperties.class)
public ProducerFactory<String, String> producerFactory() {
HashMap<String, Object> config = new HashMap<>(16);
config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, enochAgentProperties.getKafkaHost());
......@@ -45,7 +45,6 @@ public class EnochAgentAutoConfiguration {
@Bean
@ConditionalOnBean(ProducerFactory.class)
public KafkaTemplate<String, String> kafkaTemplate(ProducerFactory<String, String> producerFactory) {
return new KafkaTemplate<>(producerFactory);
}
......@@ -58,4 +57,5 @@ public class EnochAgentAutoConfiguration {
taskRegistrar.setScheduler(executor);
}
}
}
\ No newline at end of file
......@@ -3,20 +3,21 @@ package cn.quantgroup.tech.enoch.agent.report.impl;
import cn.quantgroup.tech.enoch.agent.configuration.EnochAgentProperties;
import cn.quantgroup.tech.enoch.agent.report.IReportService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.endpoint.HealthEndpoint;
import org.springframework.boot.actuate.endpoint.MetricsEndpoint;
import org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint;
import org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint;
import org.springframework.boot.actuate.health.Health;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
/**
......@@ -30,6 +31,9 @@ public class ReportServiceImpl implements IReportService {
@Autowired
private HealthEndpoint healthEndpoint;
@Autowired
private HealthMvcEndpoint healthMvcEndpoint;
@Autowired
private MetricsEndpoint metricsEndpoint;
......@@ -49,7 +53,9 @@ public class ReportServiceImpl implements IReportService {
@Override
public void report() {
int size = arrayBlockingQueue.size();
log.info("enoch.agent report data, size: {}", size);
if (size <= 0) {
return;
}
List<Map<String, Object>> slice = new ArrayList<>(size);
arrayBlockingQueue.drainTo(slice, size);
Map<String, Object> pushPackage = new HashMap<>(6);
......@@ -60,14 +66,15 @@ public class ReportServiceImpl implements IReportService {
pushPackage.put("appName", applicationInfo.getAppName());
pushPackage.put("endPoints", slice);
//todo 若发kafka失败,添加本地持久化操作,待下次提交时,一同push
kafkaTemplate.send(enochAgentProperties.getKafkaTopic(), JSON.toJSONString(pushPackage));
kafkaTemplate.send(enochAgentProperties.getKafkaTopic(), JSON.toJSONString(pushPackage, SerializerFeature.DisableCircularReferenceDetect));
}
@Override
public void collect() {
log.info("enoch.agent collect data");
HashMap<String, Object> endPoints = new HashMap<>(16);
endPoints.put("health", healthEndpoint.invoke());
Health health = healthMvcEndpoint.getDelegate().invoke();
Health.status(health.getStatus()).build();
endPoints.put("health", health);
endPoints.put("metrics", metricsEndpoint.invoke());
endPoints.put("timestamp", System.nanoTime());
try {
......@@ -78,8 +85,10 @@ public class ReportServiceImpl implements IReportService {
}
private ApplicationInfo initApplicationInfo() {
applicationInfo.setAppName(environmentMvcEndpoint.value("spring.application.name").toString());
applicationInfo.setIp(environmentMvcEndpoint.value("spring.cloud.client.ipAddress").toString());
Map<String, String> appName = (HashMap) environmentMvcEndpoint.value("spring.application.name");
Map<String, String> ip = (HashMap) environmentMvcEndpoint.value("spring.cloud.client.ipAddress");
applicationInfo.setAppName(appName.get("spring.application.name"));
applicationInfo.setIp(ip.get("spring.cloud.client.ipAddress"));
return applicationInfo;
}
......
{
"lockfileVersion": 1
}
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