ref: 重新调整指标监测数据入库格式,一个指标重新作为独立的数据行记录(方便按时间粒度获取监测数据时的计算)

ref: 移动部分数据类
lensfrex 7 months ago
parent 5070304883
commit b217fbb0fa
Signed by: lensfrex
GPG Key ID: B1E395B3C6CA0356
  1. 2
      rition-center/api/src/main/java/rition/backend/api/v1/collector/DataCollectingController.java
  2. 4
      rition-center/api/src/main/java/rition/backend/service/MetricDataCollectingService.java
  3. 2
      rition-center/common/src/main/java/rition/common/data/dto/service/MetricDataDto.java
  4. 10
      rition-center/common/src/main/java/rition/common/data/entity/MetricRecordEntity.java
  5. 2
      rition-center/common/src/main/java/rition/common/data/entity/RuleEntity.java
  6. 34
      rition-center/service/collector/src/main/java/rition/service/collector/MetricCollectingService.java
  7. 2
      rition-center/service/monitor/src/main/java/rition/service/monitor/MonitorService.java
  8. 2
      rition-center/service/monitor/src/main/resources/application-monitor.yml

@ -9,7 +9,7 @@ import rition.backend.annotation.paramter.RequestId;
import rition.backend.api.v1.dto.request.MetricDataUploadRequest;
import rition.backend.api.v1.dto.response.Response;
import rition.backend.service.MetricDataCollectingService;
import rition.common.data.dto.MetricDataDto;
import rition.common.data.dto.service.MetricDataDto;
import java.util.HashMap;
import java.util.List;

@ -4,12 +4,10 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import rition.common.data.dto.MetricDataDto;
import rition.common.data.dto.service.MetricDataDto;
import rition.common.data.dto.log.RequestProcessTraceRecord;
import rition.service.collector.MetricCollectingService;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Map;
/**

@ -1,5 +1,5 @@
package rition.common.data.dto;
package rition.common.data.dto.service;
import lombok.AllArgsConstructor;
import lombok.Builder;

@ -32,10 +32,14 @@ public class MetricRecordEntity {
private String instanceId;
/**
* 监控指标值使用json格式存储
* 指标项
*/
@TableField(typeHandler = JacksonTypeHandler.class)
private Map<String, Double> metricData;
private String metric;
/**
* 指标值
*/
private Double value;
/**
* create_time

@ -40,7 +40,7 @@ public class RuleEntity {
/**
* 阈值
*/
private String threshold;
private Double threshold;
/**
* 触发方法实时计算或定时计算

@ -4,8 +4,9 @@ import com.github.yitter.idgen.YitIdHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;
import rition.common.data.dto.MetricDataDto;
import rition.common.data.dto.service.MetricDataDto;
import rition.common.data.entity.MetricRecordEntity;
import rition.common.data.enums.Constants;
import rition.service.collector.configure.CollectorServiceKafkaConfigure;
import rition.common.data.dao.mapper.MetricRecordMapper;
@ -45,27 +46,31 @@ public class MetricCollectingService {
* @param collectedMetricData 监控指标数据以时间戳为组
*/
public void receiveData(Map<Long, Map<String, MetricDataDto>> collectedMetricData) {
List<MetricRecordEntity> batchSaveEntityList = new ArrayList<>(DEFAULT_DB_BATCH_SIZE);
List<MetricRecordEntity> batchSaveEntityList = new ArrayList<>(DEFAULT_DB_BATCH_SIZE * METRIC_NUMS);
int turn = 0;
for (Long timestamp : collectedMetricData.keySet()) {
Map<String, MetricDataDto> instanceMetricData = collectedMetricData.get(timestamp);
for (String instanceId : instanceMetricData.keySet()) {
MetricDataDto metricDataDto = instanceMetricData.get(instanceId);
MetricRecordEntity entity = new MetricRecordEntity();
entity.setId(YitIdHelper.nextId());
entity.setInstanceId(instanceId);
entity.setMetricData(metricDataDto.getData());
var time = Instant.ofEpochSecond(metricDataDto.getTimestamp());
entity.setTime(time);
entity.setUpdateTime(time);
entity.setStatus(0);
List<MetricRecordEntity> metricRecordEntityList = new ArrayList<>(METRIC_NUMS);
for (String metric : metricDataDto.getData().keySet()) {
MetricRecordEntity entity = new MetricRecordEntity();
entity.setId(YitIdHelper.nextId());
entity.setInstanceId(instanceId);
entity.setMetric(metric);
entity.setValue(metricDataDto.getData().get(metric));
// kafka发布
kafkaTemplate.send(this.collectedDataTopic, metricDataDto);
var time = Instant.ofEpochSecond(metricDataDto.getTimestamp());
entity.setTime(time);
entity.setUpdateTime(time);
entity.setStatus(Constants.EntityCommonStatus.NORMAL);
metricRecordEntityList.add(entity);
}
// 分批入库
batchSaveEntityList.add(entity);
batchSaveEntityList.addAll(metricRecordEntityList);
if (turn >= DEFAULT_DB_BATCH_SIZE) {
metricRecordMapper.insertBatchSomeColumn(batchSaveEntityList);
// 下一轮
@ -74,6 +79,9 @@ public class MetricCollectingService {
} else {
turn++;
}
// kafka发布
kafkaTemplate.send(this.collectedDataTopic, metricDataDto);
}
}

@ -3,7 +3,7 @@ package rition.service.monitor;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Service;
import rition.common.data.dto.MetricDataDto;
import rition.common.data.dto.service.MetricDataDto;
@Service
public class MonitorService {

@ -13,7 +13,7 @@ spring:
spring:
json:
trusted:
packages: "rition.common.data.dto"
packages: "rition.common.data.dto.*"
producer:
retries: 4
compression-type: zstd

Loading…
Cancel
Save