AE86 11 달 전
부모
커밋
bae89c2491

+ 6 - 5
dbsyncer-biz/src/main/java/org/dbsyncer/biz/MonitorService.java

@@ -3,11 +3,11 @@
  */
 package org.dbsyncer.biz;
 
-import org.dbsyncer.biz.vo.AppReportMetricVo;
-import org.dbsyncer.biz.vo.MetaVo;
-import org.dbsyncer.common.model.Paging;
 import org.dbsyncer.biz.enums.MetricEnum;
+import org.dbsyncer.biz.model.AppReportMetric;
 import org.dbsyncer.biz.model.MetricResponse;
+import org.dbsyncer.biz.vo.MetaVo;
+import org.dbsyncer.common.model.Paging;
 import org.dbsyncer.storage.enums.StorageDataStatusEnum;
 
 import java.util.List;
@@ -37,6 +37,7 @@ public interface MonitorService {
 
     /**
      * 获取驱动默认元信息id
+     *
      * @param params
      * @return
      */
@@ -45,8 +46,8 @@ public interface MonitorService {
     /**
      * 查询驱动同步数据
      *
-     * @return
      * @param params
+     * @return
      */
     Paging queryData(Map<String, String> params);
 
@@ -97,6 +98,6 @@ public interface MonitorService {
      *
      * @return
      */
-    AppReportMetricVo queryAppReportMetric(List<MetricResponse> metrics);
+    AppReportMetric queryAppReportMetric(List<MetricResponse> metrics);
 
 }

+ 2 - 1
dbsyncer-biz/src/main/java/org/dbsyncer/biz/impl/MetricReporter.java

@@ -93,6 +93,8 @@ public class MetricReporter implements ScheduledTaskJob {
 
     private final MappingReportMetric mappingReportMetric = new MappingReportMetric();
 
+    private AppReportMetric report = new AppReportMetric();
+
     private final int SHOW_BUFFER_ACTUATOR_SIZE = 6;
 
     @PostConstruct
@@ -134,7 +136,6 @@ public class MetricReporter implements ScheduledTaskJob {
 
     public AppReportMetric getAppReportMetric() {
         queryTime = LocalDateTime.now();
-        AppReportMetric report = new AppReportMetric();
         report.setSuccess(mappingReportMetric.getSuccess());
         report.setFail(mappingReportMetric.getFail());
         report.setInsert(mappingReportMetric.getInsert());

+ 8 - 9
dbsyncer-biz/src/main/java/org/dbsyncer/biz/impl/MonitorServiceImpl.java

@@ -19,7 +19,6 @@ import org.dbsyncer.biz.metric.impl.MemoryMetricDetailFormatter;
 import org.dbsyncer.biz.metric.impl.ValueMetricDetailFormatter;
 import org.dbsyncer.biz.model.AppReportMetric;
 import org.dbsyncer.biz.model.MetricResponse;
-import org.dbsyncer.biz.vo.AppReportMetricVo;
 import org.dbsyncer.biz.vo.DataVo;
 import org.dbsyncer.biz.vo.LogVo;
 import org.dbsyncer.biz.vo.MetaVo;
@@ -220,12 +219,10 @@ public class MonitorServiceImpl extends BaseServiceImpl implements MonitorServic
     }
 
     @Override
-    public AppReportMetricVo queryAppReportMetric(List<MetricResponse> metrics) {
-        AppReportMetric appReportMetric = metricReporter.getAppReportMetric();
-        AppReportMetricVo vo = new AppReportMetricVo();
-        BeanUtils.copyProperties(appReportMetric, vo);
-        vo.setMetrics(getMetrics(metrics));
-        return vo;
+    public AppReportMetric queryAppReportMetric(List<MetricResponse> metrics) {
+        AppReportMetric app = metricReporter.getAppReportMetric();
+        app.setMetrics(getMetrics(metrics));
+        return app;
     }
 
     @Override
@@ -311,7 +308,6 @@ public class MonitorServiceImpl extends BaseServiceImpl implements MonitorServic
         Assert.notNull(mapping, "驱动不存在.");
         ModelEnum modelEnum = ModelEnum.getModelEnum(mapping.getModel());
         MetaVo metaVo = new MetaVo(modelEnum.getName(), mapping.getName());
-        metaVo.setMappingName(mapping.getName());
         BeanUtils.copyProperties(meta, metaVo);
         return metaVo;
     }
@@ -339,7 +335,10 @@ public class MonitorServiceImpl extends BaseServiceImpl implements MonitorServic
         // 转换显示
         return metrics.stream().map(metric -> {
             MetricResponseVo vo = new MetricResponseVo();
-            BeanUtils.copyProperties(metric, vo);
+            vo.setCode(metric.getCode());
+            vo.setGroup(metric.getGroup());
+            vo.setMetricName(metric.getMetricName());
+            vo.setMeasurements(metric.getMeasurements());
             MetricDetailFormatter detailFormatter = metricDetailFormatterMap.get(vo.getCode());
             if (null != detailFormatter) {
                 detailFormatter.format(vo);

+ 33 - 0
dbsyncer-biz/src/main/java/org/dbsyncer/biz/model/AppReportMetric.java

@@ -4,6 +4,9 @@
 package org.dbsyncer.biz.model;
 
 import org.dbsyncer.biz.vo.HistoryStackVo;
+import org.dbsyncer.biz.vo.MetricResponseVo;
+
+import java.util.List;
 
 public class AppReportMetric extends MappingReportMetric {
 
@@ -32,6 +35,12 @@ public class AppReportMetric extends MappingReportMetric {
      */
     private HistoryStackVo tps;
 
+    private HistoryStackVo cpu;
+
+    private HistoryStackVo memory;
+
+    private List<MetricResponseVo> metrics;
+
     public long getQueueUp() {
         return queueUp;
     }
@@ -71,4 +80,28 @@ public class AppReportMetric extends MappingReportMetric {
     public void setTps(HistoryStackVo tps) {
         this.tps = tps;
     }
+
+    public HistoryStackVo getCpu() {
+        return cpu;
+    }
+
+    public void setCpu(HistoryStackVo cpu) {
+        this.cpu = cpu;
+    }
+
+    public HistoryStackVo getMemory() {
+        return memory;
+    }
+
+    public void setMemory(HistoryStackVo memory) {
+        this.memory = memory;
+    }
+
+    public List<MetricResponseVo> getMetrics() {
+        return metrics;
+    }
+
+    public void setMetrics(List<MetricResponseVo> metrics) {
+        this.metrics = metrics;
+    }
 }

+ 0 - 39
dbsyncer-biz/src/main/java/org/dbsyncer/biz/vo/AppReportMetricVo.java

@@ -1,39 +0,0 @@
-package org.dbsyncer.biz.vo;
-
-import org.dbsyncer.biz.model.AppReportMetric;
-
-import java.util.List;
-
-public class AppReportMetricVo extends AppReportMetric {
-
-    private List<MetricResponseVo> metrics;
-
-    private HistoryStackVo cpu;
-
-    private HistoryStackVo memory;
-
-    public List<MetricResponseVo> getMetrics() {
-        return metrics;
-    }
-
-    public void setMetrics(List<MetricResponseVo> metrics) {
-        this.metrics = metrics;
-    }
-
-    public HistoryStackVo getCpu() {
-        return cpu;
-    }
-
-    public void setCpu(HistoryStackVo cpu) {
-        this.cpu = cpu;
-    }
-
-    public HistoryStackVo getMemory() {
-        return memory;
-    }
-
-    public void setMemory(HistoryStackVo memory) {
-        this.memory = memory;
-    }
-
-}

+ 3 - 22
dbsyncer-parser/src/main/java/org/dbsyncer/parser/impl/OperationTemplate.java

@@ -19,7 +19,6 @@ import org.dbsyncer.sdk.enums.StorageEnum;
 import org.dbsyncer.sdk.storage.StorageService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Component;
 import org.springframework.util.Assert;
 
@@ -58,18 +57,16 @@ public final class OperationTemplate {
     }
 
     public <T> List<T> queryAll(QueryConfig<T> query) {
-        ConfigModel model = query.getConfigModel();
-        String groupId = getGroupId(model, query.getGroupStrategyEnum());
+        String groupId = getGroupId(query.getConfigModel(), query.getGroupStrategyEnum());
         Group group = cacheService.get(groupId, Group.class);
         if (null != group) {
             List<String> index = group.getIndex();
             if (!CollectionUtils.isEmpty(index)) {
                 List<T> list = new ArrayList<>();
-                Class<? extends ConfigModel> clazz = model.getClass();
                 index.forEach(e -> {
                     Object v = cacheService.get(e);
                     if (null != v) {
-                        list.add((T) beanCopy(clazz, v));
+                        list.add((T) v);
                     }
                 });
                 return list;
@@ -89,8 +86,7 @@ public final class OperationTemplate {
         if (StringUtil.isBlank(id)) {
             return null;
         }
-        Object o = cacheService.get(id, clazz);
-        return beanCopy(clazz, o);
+        return (T) cacheService.get(id, clazz);
     }
 
     public String execute(OperationConfig config) {
@@ -152,21 +148,6 @@ public final class OperationTemplate {
         return groupId;
     }
 
-    private <T> T beanCopy(Class<T> clazz, Object o) {
-        if (null == o || null == clazz) {
-            return null;
-        }
-        try {
-            T t = clazz.newInstance();
-            BeanUtils.copyProperties(o, t);
-            return t;
-        } catch (InstantiationException e) {
-            throw new ParserException(e);
-        } catch (IllegalAccessException e) {
-            throw new ParserException(e);
-        }
-    }
-
     public class Group {
 
         private List<String> index;

+ 2 - 2
dbsyncer-web/src/main/java/org/dbsyncer/web/controller/monitor/MonitorController.java

@@ -10,9 +10,9 @@ import org.dbsyncer.biz.SystemConfigService;
 import org.dbsyncer.biz.enums.DiskMetricEnum;
 import org.dbsyncer.biz.enums.MetricEnum;
 import org.dbsyncer.biz.enums.StatisticEnum;
+import org.dbsyncer.biz.model.AppReportMetric;
 import org.dbsyncer.biz.model.MetricResponse;
 import org.dbsyncer.biz.model.Sample;
-import org.dbsyncer.biz.vo.AppReportMetricVo;
 import org.dbsyncer.biz.vo.HistoryStackVo;
 import org.dbsyncer.biz.vo.RestResult;
 import org.dbsyncer.common.util.CollectionUtils;
@@ -184,7 +184,7 @@ public class MonitorController extends BaseController {
                 metricEnumList.forEach(m -> list.add(getMetricResponse(m.getCode())));
             }
             list.addAll(getDiskHealth());
-            AppReportMetricVo reportMetric = monitorService.queryAppReportMetric(list);
+            AppReportMetric reportMetric = monitorService.queryAppReportMetric(list);
             reportMetric.setCpu(cpu);
             reportMetric.setMemory(memory);
             return RestResult.restSuccess(reportMetric);