Skip to content

Commit b101cec

Browse files
zengqiaoZQKC
authored andcommitted
健康分调整为健康状态
1 parent e98ec56 commit b101cec

File tree

30 files changed

+1091
-171
lines changed

30 files changed

+1091
-171
lines changed

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import com.xiaojukeji.know.streaming.km.biz.cluster.ClusterZookeepersManager;
66
import com.xiaojukeji.know.streaming.km.common.bean.dto.cluster.ClusterZookeepersOverviewDTO;
77
import com.xiaojukeji.know.streaming.km.common.bean.entity.cluster.ClusterPhy;
8-
import com.xiaojukeji.know.streaming.km.common.bean.entity.config.ZKConfig;
98
import com.xiaojukeji.know.streaming.km.common.bean.entity.metrics.ZookeeperMetrics;
10-
import com.xiaojukeji.know.streaming.km.common.bean.entity.param.metric.ZookeeperMetricParam;
119
import com.xiaojukeji.know.streaming.km.common.bean.entity.result.PaginationResult;
1210
import com.xiaojukeji.know.streaming.km.common.bean.entity.result.Result;
1311
import com.xiaojukeji.know.streaming.km.common.bean.entity.result.ResultStatus;
@@ -20,7 +18,6 @@
2018
import com.xiaojukeji.know.streaming.km.common.enums.zookeeper.ZKRoleEnum;
2119
import com.xiaojukeji.know.streaming.km.common.utils.ConvertUtil;
2220
import com.xiaojukeji.know.streaming.km.common.utils.PaginationUtil;
23-
import com.xiaojukeji.know.streaming.km.common.utils.Tuple;
2421
import com.xiaojukeji.know.streaming.km.core.service.cluster.ClusterPhyService;
2522
import com.xiaojukeji.know.streaming.km.core.service.version.metrics.ZookeeperMetricVersionItems;
2623
import com.xiaojukeji.know.streaming.km.core.service.zookeeper.ZnodeService;
@@ -30,7 +27,6 @@
3027
import org.springframework.stereotype.Service;
3128
import java.util.Arrays;
3229
import java.util.List;
33-
import java.util.stream.Collectors;
3430

3531

3632
@Service
@@ -56,11 +52,6 @@ public Result<ClusterZookeepersStateVO> getClusterPhyZookeepersState(Long cluste
5652
return Result.buildFromRSAndMsg(ResultStatus.CLUSTER_NOT_EXIST, MsgConstant.getClusterPhyNotExist(clusterPhyId));
5753
}
5854

59-
// // TODO
60-
// private Integer healthState;
61-
// private Integer healthCheckPassed;
62-
// private Integer healthCheckTotal;
63-
6455
List<ZookeeperInfo> infoList = zookeeperService.listFromDBByCluster(clusterPhyId);
6556

6657
ClusterZookeepersStateVO vo = new ClusterZookeepersStateVO();
@@ -90,21 +81,30 @@ public Result<ClusterZookeepersStateVO> getClusterPhyZookeepersState(Long cluste
9081
}
9182
}
9283

93-
Result<ZookeeperMetrics> metricsResult = zookeeperMetricService.collectMetricsFromZookeeper(new ZookeeperMetricParam(
84+
// 指标获取
85+
Result<ZookeeperMetrics> metricsResult = zookeeperMetricService.batchCollectMetricsFromZookeeper(
9486
clusterPhyId,
95-
infoList.stream().filter(elem -> elem.alive()).map(item -> new Tuple<String, Integer>(item.getHost(), item.getPort())).collect(Collectors.toList()),
96-
ConvertUtil.str2ObjByJson(clusterPhy.getZkProperties(), ZKConfig.class),
97-
ZookeeperMetricVersionItems.ZOOKEEPER_METRIC_WATCH_COUNT
98-
));
87+
Arrays.asList(
88+
ZookeeperMetricVersionItems.ZOOKEEPER_METRIC_WATCH_COUNT,
89+
ZookeeperMetricVersionItems.ZOOKEEPER_METRIC_HEALTH_STATE,
90+
ZookeeperMetricVersionItems.ZOOKEEPER_METRIC_HEALTH_CHECK_PASSED,
91+
ZookeeperMetricVersionItems.ZOOKEEPER_METRIC_HEALTH_CHECK_TOTAL
92+
)
93+
94+
);
9995
if (metricsResult.failed()) {
10096
LOGGER.error(
10197
"class=ClusterZookeepersManagerImpl||method=getClusterPhyZookeepersState||clusterPhyId={}||errMsg={}",
10298
clusterPhyId, metricsResult.getMessage()
10399
);
104100
return Result.buildSuc(vo);
105101
}
106-
Float watchCount = metricsResult.getData().getMetric(ZookeeperMetricVersionItems.ZOOKEEPER_METRIC_WATCH_COUNT);
107-
vo.setWatchCount(watchCount != null? watchCount.intValue(): null);
102+
103+
ZookeeperMetrics metrics = metricsResult.getData();
104+
vo.setWatchCount(ConvertUtil.float2Integer(metrics.getMetrics().get(ZookeeperMetricVersionItems.ZOOKEEPER_METRIC_WATCH_COUNT)));
105+
vo.setHealthState(ConvertUtil.float2Integer(metrics.getMetrics().get(ZookeeperMetricVersionItems.ZOOKEEPER_METRIC_HEALTH_STATE)));
106+
vo.setHealthCheckPassed(ConvertUtil.float2Integer(metrics.getMetrics().get(ZookeeperMetricVersionItems.ZOOKEEPER_METRIC_HEALTH_CHECK_PASSED)));
107+
vo.setHealthCheckTotal(ConvertUtil.float2Integer(metrics.getMetrics().get(ZookeeperMetricVersionItems.ZOOKEEPER_METRIC_HEALTH_CHECK_TOTAL)));
108108

109109
return Result.buildSuc(vo);
110110
}

km-biz/src/main/java/com/xiaojukeji/know/streaming/km/biz/version/impl/VersionControlManagerImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class VersionControlManagerImpl implements VersionControlManager {
4747

4848
@PostConstruct
4949
public void init(){
50-
defaultMetrics.add(new UserMetricConfig(METRIC_TOPIC.getCode(), TOPIC_METRIC_HEALTH_SCORE, true));
50+
defaultMetrics.add(new UserMetricConfig(METRIC_TOPIC.getCode(), TOPIC_METRIC_HEALTH_STATE, true));
5151
defaultMetrics.add(new UserMetricConfig(METRIC_TOPIC.getCode(), TOPIC_METRIC_FAILED_FETCH_REQ, true));
5252
defaultMetrics.add(new UserMetricConfig(METRIC_TOPIC.getCode(), TOPIC_METRIC_FAILED_PRODUCE_REQ, true));
5353
defaultMetrics.add(new UserMetricConfig(METRIC_TOPIC.getCode(), TOPIC_METRIC_UNDER_REPLICA_PARTITIONS, true));
@@ -57,7 +57,7 @@ public void init(){
5757
defaultMetrics.add(new UserMetricConfig(METRIC_TOPIC.getCode(), TOPIC_METRIC_BYTES_REJECTED, true));
5858
defaultMetrics.add(new UserMetricConfig(METRIC_TOPIC.getCode(), TOPIC_METRIC_MESSAGE_IN, true));
5959

60-
defaultMetrics.add(new UserMetricConfig(METRIC_CLUSTER.getCode(), CLUSTER_METRIC_HEALTH_SCORE, true));
60+
defaultMetrics.add(new UserMetricConfig(METRIC_CLUSTER.getCode(), CLUSTER_METRIC_HEALTH_STATE, true));
6161
defaultMetrics.add(new UserMetricConfig(METRIC_CLUSTER.getCode(), CLUSTER_METRIC_ACTIVE_CONTROLLER_COUNT, true));
6262
defaultMetrics.add(new UserMetricConfig(METRIC_CLUSTER.getCode(), CLUSTER_METRIC_BYTES_IN, true));
6363
defaultMetrics.add(new UserMetricConfig(METRIC_CLUSTER.getCode(), CLUSTER_METRIC_BYTES_OUT, true));
@@ -75,9 +75,9 @@ public void init(){
7575
defaultMetrics.add(new UserMetricConfig(METRIC_GROUP.getCode(), GROUP_METRIC_OFFSET_CONSUMED, true));
7676
defaultMetrics.add(new UserMetricConfig(METRIC_GROUP.getCode(), GROUP_METRIC_LAG, true));
7777
defaultMetrics.add(new UserMetricConfig(METRIC_GROUP.getCode(), GROUP_METRIC_STATE, true));
78-
defaultMetrics.add(new UserMetricConfig(METRIC_GROUP.getCode(), GROUP_METRIC_HEALTH_SCORE, true));
78+
defaultMetrics.add(new UserMetricConfig(METRIC_GROUP.getCode(), GROUP_METRIC_HEALTH_STATE, true));
7979

80-
defaultMetrics.add(new UserMetricConfig(METRIC_BROKER.getCode(), BROKER_METRIC_HEALTH_SCORE, true));
80+
defaultMetrics.add(new UserMetricConfig(METRIC_BROKER.getCode(), BROKER_METRIC_HEALTH_STATE, true));
8181
defaultMetrics.add(new UserMetricConfig(METRIC_BROKER.getCode(), BROKER_METRIC_CONNECTION_COUNT, true));
8282
defaultMetrics.add(new UserMetricConfig(METRIC_BROKER.getCode(), BROKER_METRIC_MESSAGE_IN, true));
8383
defaultMetrics.add(new UserMetricConfig(METRIC_BROKER.getCode(), BROKER_METRIC_NETWORK_RPO_AVG_IDLE, true));

km-common/src/main/java/com/xiaojukeji/know/streaming/km/common/bean/entity/broker/Broker.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import com.alibaba.fastjson.TypeReference;
55
import com.xiaojukeji.know.streaming.km.common.bean.entity.common.IpPortData;
6+
import com.xiaojukeji.know.streaming.km.common.bean.entity.config.JmxConfig;
67
import com.xiaojukeji.know.streaming.km.common.bean.po.broker.BrokerPO;
78
import com.xiaojukeji.know.streaming.km.common.utils.ConvertUtil;
89
import lombok.AllArgsConstructor;
@@ -65,13 +66,13 @@ public class Broker implements Serializable {
6566
*/
6667
private Map<String, IpPortData> endpointMap;
6768

68-
public static Broker buildFrom(Long clusterPhyId, Node node, Long startTimestamp) {
69+
public static Broker buildFrom(Long clusterPhyId, Node node, Long startTimestamp, JmxConfig jmxConfig) {
6970
Broker metadata = new Broker();
7071
metadata.setClusterPhyId(clusterPhyId);
7172
metadata.setBrokerId(node.id());
7273
metadata.setHost(node.host());
7374
metadata.setPort(node.port());
74-
metadata.setJmxPort(-1);
75+
metadata.setJmxPort(jmxConfig != null ? jmxConfig.getJmxPort() : -1);
7576
metadata.setStartTimestamp(startTimestamp);
7677
metadata.setRack(node.rack());
7778
metadata.setStatus(1);

km-common/src/main/java/com/xiaojukeji/know/streaming/km/common/bean/entity/config/healthcheck/BaseClusterHealthConfig.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,4 @@ public class BaseClusterHealthConfig extends BaseClusterConfigValue {
1313
* 健康检查名称
1414
*/
1515
protected HealthCheckNameEnum checkNameEnum;
16-
17-
/**
18-
* 权重
19-
*/
20-
protected Float weight;
2116
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.xiaojukeji.know.streaming.km.common.bean.entity.config.healthcheck;
2+
3+
import lombok.Data;
4+
5+
/**
6+
* @author wyb
7+
* @date 2022/10/26
8+
*/
9+
@Data
10+
public class HealthAmountRatioConfig extends BaseClusterHealthConfig {
11+
/**
12+
* 总数
13+
*/
14+
private Integer amount;
15+
/**
16+
* 比例
17+
*/
18+
private Double ratio;
19+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.xiaojukeji.know.streaming.km.common.bean.entity.health;
2+
3+
import com.xiaojukeji.know.streaming.km.common.bean.po.health.HealthCheckResultPO;
4+
import com.xiaojukeji.know.streaming.km.common.enums.health.HealthCheckNameEnum;
5+
import com.xiaojukeji.know.streaming.km.common.utils.ValidateUtils;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
import java.util.ArrayList;
10+
import java.util.Date;
11+
import java.util.List;
12+
import java.util.stream.Collectors;
13+
14+
@Data
15+
@NoArgsConstructor
16+
public class HealthCheckAggResult {
17+
private HealthCheckNameEnum checkNameEnum;
18+
19+
private List<HealthCheckResultPO> poList;
20+
21+
private Boolean passed;
22+
23+
public HealthCheckAggResult(HealthCheckNameEnum checkNameEnum, List<HealthCheckResultPO> poList) {
24+
this.checkNameEnum = checkNameEnum;
25+
this.poList = poList;
26+
if (!ValidateUtils.isEmptyList(poList) && poList.stream().filter(elem -> elem.getPassed() <= 0).count() <= 0) {
27+
passed = true;
28+
} else {
29+
passed = false;
30+
}
31+
}
32+
33+
public Integer getTotalCount() {
34+
if (poList == null) {
35+
return 0;
36+
}
37+
38+
return poList.size();
39+
}
40+
41+
public Integer getPassedCount() {
42+
if (poList == null) {
43+
return 0;
44+
}
45+
return (int) (poList.stream().filter(elem -> elem.getPassed() > 0).count());
46+
}
47+
48+
/**
49+
* 计算当前检查的健康分
50+
* 比如:计算集群Broker健康检查中的某一项的健康分
51+
*/
52+
public Integer calRawHealthScore() {
53+
if (poList == null || poList.isEmpty()) {
54+
return 100;
55+
}
56+
57+
return 100 * this.getPassedCount() / this.getTotalCount();
58+
}
59+
60+
public List<String> getNotPassedResNameList() {
61+
if (poList == null) {
62+
return new ArrayList<>();
63+
}
64+
65+
return poList.stream().filter(elem -> elem.getPassed() <= 0).map(elem -> elem.getResName()).collect(Collectors.toList());
66+
}
67+
68+
public Date getCreateTime() {
69+
if (ValidateUtils.isEmptyList(poList)) {
70+
return null;
71+
}
72+
73+
return poList.get(0).getCreateTime();
74+
}
75+
76+
public Date getUpdateTime() {
77+
if (ValidateUtils.isEmptyList(poList)) {
78+
return null;
79+
}
80+
81+
return poList.get(0).getUpdateTime();
82+
}
83+
}

km-common/src/main/java/com/xiaojukeji/know/streaming/km/common/bean/entity/health/HealthScoreResult.java

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,18 @@
1717
public class HealthScoreResult {
1818
private HealthCheckNameEnum checkNameEnum;
1919

20-
private Float presentDimensionTotalWeight;
21-
22-
private Float allDimensionTotalWeight;
23-
2420
private BaseClusterHealthConfig baseConfig;
2521

2622
private List<HealthCheckResultPO> poList;
2723

2824
private Boolean passed;
2925

3026
public HealthScoreResult(HealthCheckNameEnum checkNameEnum,
31-
Float presentDimensionTotalWeight,
32-
Float allDimensionTotalWeight,
3327
BaseClusterHealthConfig baseConfig,
3428
List<HealthCheckResultPO> poList) {
3529
this.checkNameEnum = checkNameEnum;
3630
this.baseConfig = baseConfig;
3731
this.poList = poList;
38-
this.presentDimensionTotalWeight = presentDimensionTotalWeight;
39-
this.allDimensionTotalWeight = allDimensionTotalWeight;
4032
if (!ValidateUtils.isEmptyList(poList) && poList.stream().filter(elem -> elem.getPassed() <= 0).count() <= 0) {
4133
passed = true;
4234
} else {
@@ -59,32 +51,6 @@ public Integer getPassedCount() {
5951
return (int) (poList.stream().filter(elem -> elem.getPassed() > 0).count());
6052
}
6153

62-
/**
63-
* 计算所有检查结果的健康分
64-
* 比如:计算集群健康分
65-
*/
66-
public Float calAllWeightHealthScore() {
67-
Float healthScore = 100 * baseConfig.getWeight() / allDimensionTotalWeight;
68-
if (poList == null || poList.isEmpty()) {
69-
return 0.0f;
70-
}
71-
72-
return healthScore * this.getPassedCount() / this.getTotalCount();
73-
}
74-
75-
/**
76-
* 计算当前维度的健康分
77-
* 比如:计算集群Broker健康分
78-
*/
79-
public Float calDimensionWeightHealthScore() {
80-
Float healthScore = 100 * baseConfig.getWeight() / presentDimensionTotalWeight;
81-
if (poList == null || poList.isEmpty()) {
82-
return 0.0f;
83-
}
84-
85-
return healthScore * this.getPassedCount() / this.getTotalCount();
86-
}
87-
8854
/**
8955
* 计算当前检查的健康分
9056
* 比如:计算集群Broker健康检查中的某一项的健康分
@@ -102,7 +68,7 @@ public List<String> getNotPassedResNameList() {
10268
return new ArrayList<>();
10369
}
10470

105-
return poList.stream().filter(elem -> elem.getPassed() <= 0).map(elem -> elem.getResName()).collect(Collectors.toList());
71+
return poList.stream().filter(elem -> elem.getPassed() <= 0 && !ValidateUtils.isBlank(elem.getResName())).map(elem -> elem.getResName()).collect(Collectors.toList());
10672
}
10773

10874
public Date getCreateTime() {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.xiaojukeji.know.streaming.km.common.bean.entity.param.zookeeper;
2+
3+
import com.xiaojukeji.know.streaming.km.common.bean.entity.config.ZKConfig;
4+
import com.xiaojukeji.know.streaming.km.common.bean.entity.param.cluster.ClusterPhyParam;
5+
import com.xiaojukeji.know.streaming.km.common.utils.Tuple;
6+
import lombok.Data;
7+
import lombok.NoArgsConstructor;
8+
9+
import java.util.List;
10+
11+
/**
12+
* @author didi
13+
*/
14+
@Data
15+
@NoArgsConstructor
16+
public class ZookeeperParam extends ClusterPhyParam {
17+
private List<Tuple<String, Integer>> zkAddressList;
18+
19+
private ZKConfig zkConfig;
20+
21+
public ZookeeperParam(Long clusterPhyId, List<Tuple<String, Integer>> zkAddressList, ZKConfig zkConfig) {
22+
super(clusterPhyId);
23+
this.zkAddressList = zkAddressList;
24+
this.zkConfig = zkConfig;
25+
}
26+
}

km-common/src/main/java/com/xiaojukeji/know/streaming/km/common/bean/vo/health/HealthCheckConfigVO.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ public class HealthCheckConfigVO {
3232
@ApiModelProperty(value="检查说明", example = "Group延迟")
3333
private String configDesc;
3434

35-
@ApiModelProperty(value="权重", example = "10")
36-
private Float weight;
37-
3835
@ApiModelProperty(value="检查配置", example = "100")
3936
private String value;
4037
}

km-common/src/main/java/com/xiaojukeji/know/streaming/km/common/bean/vo/health/HealthScoreBaseResultVO.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public class HealthScoreBaseResultVO extends BaseTimeVO {
1818
@ApiModelProperty(value="检查维度", example = "1")
1919
private Integer dimension;
2020

21+
@ApiModelProperty(value="检查维度名称", example = "cluster")
22+
private String dimensionName;
23+
2124
@ApiModelProperty(value="检查名称", example = "Group延迟")
2225
private String configName;
2326

@@ -27,9 +30,6 @@ public class HealthScoreBaseResultVO extends BaseTimeVO {
2730
@ApiModelProperty(value="检查说明", example = "Group延迟")
2831
private String configDesc;
2932

30-
@ApiModelProperty(value="权重百分比[0-100]", example = "10")
31-
private Integer weightPercent;
32-
3333
@ApiModelProperty(value="得分", example = "100")
3434
private Integer score;
3535

0 commit comments

Comments
 (0)