From bbe967c4a812d9bcd5a29abb030131642219912c Mon Sep 17 00:00:00 2001 From: zengqiao Date: Sat, 29 Oct 2022 13:44:42 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=E5=A4=9A=E9=9B=86=E7=BE=A4?= =?UTF-8?q?=E5=81=A5=E5=BA=B7=E7=8A=B6=E6=80=81=E6=A6=82=E8=A7=88=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../biz/cluster/MultiClusterPhyManager.java | 3 ++ .../impl/MultiClusterPhyManagerImpl.java | 39 ++++++++++++++----- .../cluster/ClusterPhysHealthState.java | 37 ++++++++++++++++++ .../vo/cluster/ClusterPhysHealthStateVO.java | 32 +++++++++++++++ .../v3/cluster/MultiClusterPhyController.java | 8 ++++ 5 files changed, 109 insertions(+), 10 deletions(-) create mode 100644 km-common/src/main/java/com/xiaojukeji/know/streaming/km/common/bean/entity/cluster/ClusterPhysHealthState.java create mode 100644 km-common/src/main/java/com/xiaojukeji/know/streaming/km/common/bean/vo/cluster/ClusterPhysHealthStateVO.java diff --git a/km-biz/src/main/java/com/xiaojukeji/know/streaming/km/biz/cluster/MultiClusterPhyManager.java b/km-biz/src/main/java/com/xiaojukeji/know/streaming/km/biz/cluster/MultiClusterPhyManager.java index be365710..0bd2f6e4 100644 --- a/km-biz/src/main/java/com/xiaojukeji/know/streaming/km/biz/cluster/MultiClusterPhyManager.java +++ b/km-biz/src/main/java/com/xiaojukeji/know/streaming/km/biz/cluster/MultiClusterPhyManager.java @@ -1,5 +1,6 @@ package com.xiaojukeji.know.streaming.km.biz.cluster; +import com.xiaojukeji.know.streaming.km.common.bean.entity.cluster.ClusterPhysHealthState; import com.xiaojukeji.know.streaming.km.common.bean.entity.cluster.ClusterPhysState; import com.xiaojukeji.know.streaming.km.common.bean.dto.cluster.MultiClusterDashboardDTO; import com.xiaojukeji.know.streaming.km.common.bean.entity.result.PaginationResult; @@ -15,6 +16,8 @@ public interface MultiClusterPhyManager { */ ClusterPhysState getClusterPhysState(); + ClusterPhysHealthState getClusterPhysHealthState(); + /** * 查询多集群大盘 * @param dto 分页信息 diff --git a/km-biz/src/main/java/com/xiaojukeji/know/streaming/km/biz/cluster/impl/MultiClusterPhyManagerImpl.java b/km-biz/src/main/java/com/xiaojukeji/know/streaming/km/biz/cluster/impl/MultiClusterPhyManagerImpl.java index 05cc95bd..75741d8f 100644 --- a/km-biz/src/main/java/com/xiaojukeji/know/streaming/km/biz/cluster/impl/MultiClusterPhyManagerImpl.java +++ b/km-biz/src/main/java/com/xiaojukeji/know/streaming/km/biz/cluster/impl/MultiClusterPhyManagerImpl.java @@ -5,6 +5,7 @@ import com.didiglobal.logi.log.LogFactory; import com.xiaojukeji.know.streaming.km.biz.cluster.MultiClusterPhyManager; import com.xiaojukeji.know.streaming.km.common.bean.dto.metrices.MetricDTO; import com.xiaojukeji.know.streaming.km.common.bean.dto.metrices.MetricsClusterPhyDTO; +import com.xiaojukeji.know.streaming.km.common.bean.entity.cluster.ClusterPhysHealthState; import com.xiaojukeji.know.streaming.km.common.bean.entity.cluster.ClusterPhysState; import com.xiaojukeji.know.streaming.km.common.bean.entity.cluster.ClusterPhy; import com.xiaojukeji.know.streaming.km.common.bean.dto.cluster.MultiClusterDashboardDTO; @@ -16,6 +17,7 @@ import com.xiaojukeji.know.streaming.km.common.bean.vo.cluster.ClusterPhyDashboa import com.xiaojukeji.know.streaming.km.common.bean.vo.metrics.line.MetricMultiLinesVO; import com.xiaojukeji.know.streaming.km.common.constant.Constant; import com.xiaojukeji.know.streaming.km.common.converter.ClusterVOConverter; +import com.xiaojukeji.know.streaming.km.common.enums.health.HealthStateEnum; import com.xiaojukeji.know.streaming.km.common.utils.ConvertUtil; import com.xiaojukeji.know.streaming.km.common.utils.PaginationUtil; import com.xiaojukeji.know.streaming.km.common.utils.PaginationMetricsUtil; @@ -75,6 +77,32 @@ public class MultiClusterPhyManagerImpl implements MultiClusterPhyManager { return physState; } + @Override + public ClusterPhysHealthState getClusterPhysHealthState() { + List clusterPhyList = clusterPhyService.listAllClusters(); + + ClusterPhysHealthState physState = new ClusterPhysHealthState(clusterPhyList.size()); + for (ClusterPhy clusterPhy: clusterPhyList) { + ClusterMetrics metrics = clusterMetricService.getLatestMetricsFromCache(clusterPhy.getId()); + Integer state = metrics.getMetric(ClusterMetricVersionItems.CLUSTER_METRIC_HEALTH_STATE).intValue(); + if (state == null) { + physState.setUnknownCount(physState.getUnknownCount() + 1); + } else if (state.equals(HealthStateEnum.GOOD.getDimension())) { + physState.setGoodCount(physState.getGoodCount() + 1); + } else if (state.equals(HealthStateEnum.MEDIUM.getDimension())) { + physState.setMediumCount(physState.getMediumCount() + 1); + } else if (state.equals(HealthStateEnum.POOR.getDimension())) { + physState.setPoorCount(physState.getPoorCount() + 1); + } else if (state.equals(HealthStateEnum.DEAD.getDimension())) { + physState.setDeadCount(physState.getDeadCount() + 1); + } else { + physState.setUnknownCount(physState.getUnknownCount() + 1); + } + } + + return physState; + } + @Override public PaginationResult getClusterPhysDashboard(MultiClusterDashboardDTO dto) { // 获取集群 @@ -148,16 +176,7 @@ public class MultiClusterPhyManagerImpl implements MultiClusterPhyManager { // 获取所有的metrics List metricsList = new ArrayList<>(); for (ClusterPhyDashboardVO vo: voList) { - ClusterMetrics clusterMetrics = clusterMetricService.getLatestMetricsFromCache(vo.getId()); - if (!clusterMetrics.getMetrics().containsKey(ClusterMetricVersionItems.CLUSTER_METRIC_HEALTH_SCORE)) { - Float alive = clusterMetrics.getMetrics().get(ClusterMetricVersionItems.CLUSTER_METRIC_ALIVE); - // 如果集群没有健康分,则设置一个默认的健康分数值 - clusterMetrics.putMetric(ClusterMetricVersionItems.CLUSTER_METRIC_HEALTH_SCORE, - (alive != null && alive <= 0)? 0.0f: Constant.DEFAULT_CLUSTER_HEALTH_SCORE.floatValue() - ); - } - - metricsList.add(clusterMetrics); + metricsList.add(clusterMetricService.getLatestMetricsFromCache(vo.getId())); } // 范围搜索 diff --git a/km-common/src/main/java/com/xiaojukeji/know/streaming/km/common/bean/entity/cluster/ClusterPhysHealthState.java b/km-common/src/main/java/com/xiaojukeji/know/streaming/km/common/bean/entity/cluster/ClusterPhysHealthState.java new file mode 100644 index 00000000..fb1a1982 --- /dev/null +++ b/km-common/src/main/java/com/xiaojukeji/know/streaming/km/common/bean/entity/cluster/ClusterPhysHealthState.java @@ -0,0 +1,37 @@ +package com.xiaojukeji.know.streaming.km.common.bean.entity.cluster; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + + +/** + * 集群状态信息 + * @author zengqiao + * @date 22/02/24 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class ClusterPhysHealthState { + private Integer unknownCount; + + private Integer goodCount; + + private Integer mediumCount; + + private Integer poorCount; + + private Integer deadCount; + + private Integer total; + + public ClusterPhysHealthState(Integer total) { + this.unknownCount = 0; + this.goodCount = 0; + this.mediumCount = 0; + this.poorCount = 0; + this.deadCount = 0; + this.total = total; + } +} diff --git a/km-common/src/main/java/com/xiaojukeji/know/streaming/km/common/bean/vo/cluster/ClusterPhysHealthStateVO.java b/km-common/src/main/java/com/xiaojukeji/know/streaming/km/common/bean/vo/cluster/ClusterPhysHealthStateVO.java new file mode 100644 index 00000000..4c81d30c --- /dev/null +++ b/km-common/src/main/java/com/xiaojukeji/know/streaming/km/common/bean/vo/cluster/ClusterPhysHealthStateVO.java @@ -0,0 +1,32 @@ +package com.xiaojukeji.know.streaming.km.common.bean.vo.cluster; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + + +/** + * @author zengqiao + * @date 22/02/24 + */ +@Data +@ApiModel(description = "集群健康状态信息") +public class ClusterPhysHealthStateVO { + @ApiModelProperty(value = "未知", example = "30") + private Integer unknownCount; + + @ApiModelProperty(value = "好", example = "30") + private Integer goodCount; + + @ApiModelProperty(value = "中", example = "30") + private Integer mediumCount; + + @ApiModelProperty(value = "差", example = "30") + private Integer poorCount; + + @ApiModelProperty(value = "down", example = "30") + private Integer deadCount; + + @ApiModelProperty(value = "总数", example = "150") + private Integer total; +} diff --git a/km-rest/src/main/java/com/xiaojukeji/know/streaming/km/rest/api/v3/cluster/MultiClusterPhyController.java b/km-rest/src/main/java/com/xiaojukeji/know/streaming/km/rest/api/v3/cluster/MultiClusterPhyController.java index 34b907a8..aa9bf781 100644 --- a/km-rest/src/main/java/com/xiaojukeji/know/streaming/km/rest/api/v3/cluster/MultiClusterPhyController.java +++ b/km-rest/src/main/java/com/xiaojukeji/know/streaming/km/rest/api/v3/cluster/MultiClusterPhyController.java @@ -4,6 +4,7 @@ import com.xiaojukeji.know.streaming.km.biz.cluster.MultiClusterPhyManager; import com.xiaojukeji.know.streaming.km.common.bean.dto.cluster.MultiClusterDashboardDTO; import com.xiaojukeji.know.streaming.km.common.bean.entity.result.PaginationResult; import com.xiaojukeji.know.streaming.km.common.bean.entity.result.Result; +import com.xiaojukeji.know.streaming.km.common.bean.vo.cluster.ClusterPhysHealthStateVO; import com.xiaojukeji.know.streaming.km.common.bean.vo.cluster.ClusterPhysStateVO; import com.xiaojukeji.know.streaming.km.common.bean.vo.cluster.ClusterPhyDashboardVO; import com.xiaojukeji.know.streaming.km.common.constant.ApiPrefix; @@ -47,6 +48,13 @@ public class MultiClusterPhyController { return Result.buildSuc(ConvertUtil.obj2Obj(multiClusterPhyManager.getClusterPhysState(), ClusterPhysStateVO.class)); } + @ApiOperation(value = "多物理集群-健康状态", notes = "") + @GetMapping(value = "physical-clusters/health-state") + @ResponseBody + public Result getClusterPhysHealthState() { + return Result.buildSuc(ConvertUtil.obj2Obj(multiClusterPhyManager.getClusterPhysHealthState(), ClusterPhysHealthStateVO.class)); + } + @ApiOperation(value = "多物理集群-已存在kafka版本", notes = "") @GetMapping(value = "physical-clusters/exist-version") public Result> getClusterPhysVersion() {