Skip to content

Commit bbe967c

Browse files
zengqiaoZQKC
authored andcommitted
补充多集群健康状态概览信息
1 parent b101cec commit bbe967c

File tree

5 files changed

+109
-10
lines changed

5 files changed

+109
-10
lines changed

km-biz/src/main/java/com/xiaojukeji/know/streaming/km/biz/cluster/MultiClusterPhyManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.xiaojukeji.know.streaming.km.biz.cluster;
22

3+
import com.xiaojukeji.know.streaming.km.common.bean.entity.cluster.ClusterPhysHealthState;
34
import com.xiaojukeji.know.streaming.km.common.bean.entity.cluster.ClusterPhysState;
45
import com.xiaojukeji.know.streaming.km.common.bean.dto.cluster.MultiClusterDashboardDTO;
56
import com.xiaojukeji.know.streaming.km.common.bean.entity.result.PaginationResult;
@@ -15,6 +16,8 @@ public interface MultiClusterPhyManager {
1516
*/
1617
ClusterPhysState getClusterPhysState();
1718

19+
ClusterPhysHealthState getClusterPhysHealthState();
20+
1821
/**
1922
* 查询多集群大盘
2023
* @param dto 分页信息

km-biz/src/main/java/com/xiaojukeji/know/streaming/km/biz/cluster/impl/MultiClusterPhyManagerImpl.java

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.xiaojukeji.know.streaming.km.biz.cluster.MultiClusterPhyManager;
66
import com.xiaojukeji.know.streaming.km.common.bean.dto.metrices.MetricDTO;
77
import com.xiaojukeji.know.streaming.km.common.bean.dto.metrices.MetricsClusterPhyDTO;
8+
import com.xiaojukeji.know.streaming.km.common.bean.entity.cluster.ClusterPhysHealthState;
89
import com.xiaojukeji.know.streaming.km.common.bean.entity.cluster.ClusterPhysState;
910
import com.xiaojukeji.know.streaming.km.common.bean.entity.cluster.ClusterPhy;
1011
import com.xiaojukeji.know.streaming.km.common.bean.dto.cluster.MultiClusterDashboardDTO;
@@ -16,6 +17,7 @@
1617
import com.xiaojukeji.know.streaming.km.common.bean.vo.metrics.line.MetricMultiLinesVO;
1718
import com.xiaojukeji.know.streaming.km.common.constant.Constant;
1819
import com.xiaojukeji.know.streaming.km.common.converter.ClusterVOConverter;
20+
import com.xiaojukeji.know.streaming.km.common.enums.health.HealthStateEnum;
1921
import com.xiaojukeji.know.streaming.km.common.utils.ConvertUtil;
2022
import com.xiaojukeji.know.streaming.km.common.utils.PaginationUtil;
2123
import com.xiaojukeji.know.streaming.km.common.utils.PaginationMetricsUtil;
@@ -75,6 +77,32 @@ public ClusterPhysState getClusterPhysState() {
7577
return physState;
7678
}
7779

80+
@Override
81+
public ClusterPhysHealthState getClusterPhysHealthState() {
82+
List<ClusterPhy> clusterPhyList = clusterPhyService.listAllClusters();
83+
84+
ClusterPhysHealthState physState = new ClusterPhysHealthState(clusterPhyList.size());
85+
for (ClusterPhy clusterPhy: clusterPhyList) {
86+
ClusterMetrics metrics = clusterMetricService.getLatestMetricsFromCache(clusterPhy.getId());
87+
Integer state = metrics.getMetric(ClusterMetricVersionItems.CLUSTER_METRIC_HEALTH_STATE).intValue();
88+
if (state == null) {
89+
physState.setUnknownCount(physState.getUnknownCount() + 1);
90+
} else if (state.equals(HealthStateEnum.GOOD.getDimension())) {
91+
physState.setGoodCount(physState.getGoodCount() + 1);
92+
} else if (state.equals(HealthStateEnum.MEDIUM.getDimension())) {
93+
physState.setMediumCount(physState.getMediumCount() + 1);
94+
} else if (state.equals(HealthStateEnum.POOR.getDimension())) {
95+
physState.setPoorCount(physState.getPoorCount() + 1);
96+
} else if (state.equals(HealthStateEnum.DEAD.getDimension())) {
97+
physState.setDeadCount(physState.getDeadCount() + 1);
98+
} else {
99+
physState.setUnknownCount(physState.getUnknownCount() + 1);
100+
}
101+
}
102+
103+
return physState;
104+
}
105+
78106
@Override
79107
public PaginationResult<ClusterPhyDashboardVO> getClusterPhysDashboard(MultiClusterDashboardDTO dto) {
80108
// 获取集群
@@ -148,16 +176,7 @@ private PaginationResult<ClusterMetrics> getAndPagingClusterWithLatestMetricsFro
148176
// 获取所有的metrics
149177
List<ClusterMetrics> metricsList = new ArrayList<>();
150178
for (ClusterPhyDashboardVO vo: voList) {
151-
ClusterMetrics clusterMetrics = clusterMetricService.getLatestMetricsFromCache(vo.getId());
152-
if (!clusterMetrics.getMetrics().containsKey(ClusterMetricVersionItems.CLUSTER_METRIC_HEALTH_SCORE)) {
153-
Float alive = clusterMetrics.getMetrics().get(ClusterMetricVersionItems.CLUSTER_METRIC_ALIVE);
154-
// 如果集群没有健康分,则设置一个默认的健康分数值
155-
clusterMetrics.putMetric(ClusterMetricVersionItems.CLUSTER_METRIC_HEALTH_SCORE,
156-
(alive != null && alive <= 0)? 0.0f: Constant.DEFAULT_CLUSTER_HEALTH_SCORE.floatValue()
157-
);
158-
}
159-
160-
metricsList.add(clusterMetrics);
179+
metricsList.add(clusterMetricService.getLatestMetricsFromCache(vo.getId()));
161180
}
162181

163182
// 范围搜索
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.xiaojukeji.know.streaming.km.common.bean.entity.cluster;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Data;
5+
import lombok.NoArgsConstructor;
6+
7+
8+
/**
9+
* 集群状态信息
10+
* @author zengqiao
11+
* @date 22/02/24
12+
*/
13+
@Data
14+
@NoArgsConstructor
15+
@AllArgsConstructor
16+
public class ClusterPhysHealthState {
17+
private Integer unknownCount;
18+
19+
private Integer goodCount;
20+
21+
private Integer mediumCount;
22+
23+
private Integer poorCount;
24+
25+
private Integer deadCount;
26+
27+
private Integer total;
28+
29+
public ClusterPhysHealthState(Integer total) {
30+
this.unknownCount = 0;
31+
this.goodCount = 0;
32+
this.mediumCount = 0;
33+
this.poorCount = 0;
34+
this.deadCount = 0;
35+
this.total = total;
36+
}
37+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.xiaojukeji.know.streaming.km.common.bean.vo.cluster;
2+
3+
import io.swagger.annotations.ApiModel;
4+
import io.swagger.annotations.ApiModelProperty;
5+
import lombok.Data;
6+
7+
8+
/**
9+
* @author zengqiao
10+
* @date 22/02/24
11+
*/
12+
@Data
13+
@ApiModel(description = "集群健康状态信息")
14+
public class ClusterPhysHealthStateVO {
15+
@ApiModelProperty(value = "未知", example = "30")
16+
private Integer unknownCount;
17+
18+
@ApiModelProperty(value = "好", example = "30")
19+
private Integer goodCount;
20+
21+
@ApiModelProperty(value = "中", example = "30")
22+
private Integer mediumCount;
23+
24+
@ApiModelProperty(value = "差", example = "30")
25+
private Integer poorCount;
26+
27+
@ApiModelProperty(value = "down", example = "30")
28+
private Integer deadCount;
29+
30+
@ApiModelProperty(value = "总数", example = "150")
31+
private Integer total;
32+
}

km-rest/src/main/java/com/xiaojukeji/know/streaming/km/rest/api/v3/cluster/MultiClusterPhyController.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.xiaojukeji.know.streaming.km.common.bean.dto.cluster.MultiClusterDashboardDTO;
55
import com.xiaojukeji.know.streaming.km.common.bean.entity.result.PaginationResult;
66
import com.xiaojukeji.know.streaming.km.common.bean.entity.result.Result;
7+
import com.xiaojukeji.know.streaming.km.common.bean.vo.cluster.ClusterPhysHealthStateVO;
78
import com.xiaojukeji.know.streaming.km.common.bean.vo.cluster.ClusterPhysStateVO;
89
import com.xiaojukeji.know.streaming.km.common.bean.vo.cluster.ClusterPhyDashboardVO;
910
import com.xiaojukeji.know.streaming.km.common.constant.ApiPrefix;
@@ -47,6 +48,13 @@ public Result<ClusterPhysStateVO> getClusterPhysState() {
4748
return Result.buildSuc(ConvertUtil.obj2Obj(multiClusterPhyManager.getClusterPhysState(), ClusterPhysStateVO.class));
4849
}
4950

51+
@ApiOperation(value = "多物理集群-健康状态", notes = "")
52+
@GetMapping(value = "physical-clusters/health-state")
53+
@ResponseBody
54+
public Result<ClusterPhysHealthStateVO> getClusterPhysHealthState() {
55+
return Result.buildSuc(ConvertUtil.obj2Obj(multiClusterPhyManager.getClusterPhysHealthState(), ClusterPhysHealthStateVO.class));
56+
}
57+
5058
@ApiOperation(value = "多物理集群-已存在kafka版本", notes = "")
5159
@GetMapping(value = "physical-clusters/exist-version")
5260
public Result<List<String>> getClusterPhysVersion() {

0 commit comments

Comments
 (0)