LeftSider.tsx 9.4 KB
Newer Older
Z
zengqiao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
import { AppContainer, Divider, IconFont, Progress, Tooltip, Utils } from 'knowdesign';
import React, { useEffect, useState } from 'react';
import AccessClusters from '../MutliClusterPage/AccessCluster';
import './index.less';
import API from '../../api';
import HealthySetting from './HealthySetting';
import CheckDetail from './CheckDetail';
import { Link, useHistory, useParams } from 'react-router-dom';
import { getHealthClassName, getHealthProcessColor, getHealthState, getHealthText, renderToolTipValue } from './config';
import { ClustersPermissionMap } from '../CommonConfig';

const LeftSider = () => {
  const [global] = AppContainer.useGlobalValue();
  const history = useHistory();
  const [kafkaVersion, setKafkaVersion] = useState({});
  const [clusterInfo, setClusterInfo] = useState({} as any);
  const [loading, setLoading] = React.useState(false);
  const [clusterMetrics, setClusterMetrics] = useState({} as any);
  const [brokerState, setBrokerState] = useState({} as any);

  const detailDrawerRef: any = React.createRef();
  const healthyDrawerRef: any = React.createRef();
  const { clusterId } = useParams<{ clusterId: string }>();
  const [visible, setVisible] = React.useState(false);

  const getSupportKafkaVersion = () => {
    Utils.request(API.supportKafkaVersion).then((res) => {
      setKafkaVersion(res || {});
    });
  };

  const getBrokerState = () => {
    return Utils.request(API.getBrokersState(clusterId)).then((res) => {
      setBrokerState(res);
    });
  };

  const getPhyClusterMetrics = () => {
    return Utils.post(
      API.getPhyClusterMetrics(+clusterId),
      [
        'HealthScore',
        'HealthCheckPassed',
        'HealthCheckTotal',
        'Topics',
        'PartitionURP',
        'PartitionNoLeader', // > 0 error
        'PartitionMinISR_S', // > 0 error
        'Groups',
        'GroupDeads',
        'Alive',
      ].concat(process.env.BUSINESS_VERSION ? ['LoadReBalanceEnable', 'LoadReBalanceNwIn', 'LoadReBalanceNwOut', 'LoadReBalanceDisk'] : [])
    ).then((res: any) => {
      setClusterMetrics(res?.metrics || {});
    });
  };

  const getPhyClusterInfo = () => {
    setLoading(true);
    Utils.request(API.getPhyClusterBasic(+clusterId))
      .then((res: any) => {
        let jmxProperties = null;
        try {
          jmxProperties = JSON.parse(res?.jmxProperties);
        } catch (err) {
          console.error(err);
        }

        // 转化值对应成表单值
        if (jmxProperties?.openSSL) {
          jmxProperties.security = 'Password';
        }

        if (jmxProperties) {
          res = Object.assign({}, res || {}, jmxProperties);
        }
        setClusterInfo(res);
        setLoading(false);
      })
      .catch((err) => {
        setLoading(false);
      });
  };

  useEffect(() => {
    getBrokerState();
    getPhyClusterMetrics();
    getSupportKafkaVersion();
    getPhyClusterInfo();
  }, []);

  const renderIcon = (type: string) => {
    return (
      <span className={`icon`}>
        <IconFont type={type === 'green' ? 'icon-zhengchang' : type === 'warning' ? 'icon-yichang' : 'icon-warning'} />
      </span>
    );
  };

  return (
    <>
      <div className="left-sider">
        <div className="state-card">
          <Progress
            type="circle"
            status="active"
            strokeWidth={4}
            strokeColor={getHealthProcessColor(clusterMetrics?.HealthScore, clusterMetrics?.Alive)}
            percent={clusterMetrics?.HealthScore ?? '-'}
Z
zengqiao 已提交
110
            className={+clusterMetrics.Alive <= 0 ? 'red-circle' : +clusterMetrics?.HealthScore < 90 ? 'blue-circle' : 'green-circle'}
Z
zengqiao 已提交
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155
            format={() => (
              <div className={`healthy-percent ${getHealthClassName(clusterMetrics?.HealthScore, clusterMetrics?.Alive)}`}>
                {getHealthText(clusterMetrics?.HealthScore, clusterMetrics?.Alive)}
              </div>
            )}
            width={75}
          />
          <div className="healthy-state">
            <div className="healthy-state-status">
              <span>{getHealthState(clusterMetrics?.HealthScore, clusterMetrics?.Alive)}</span>
              {/* 健康分设置 */}
              {global.hasPermission && global.hasPermission(ClustersPermissionMap.CLUSTER_CHANGE_HEALTHY) ? (
                <span
                  className="icon"
                  onClick={() => {
                    healthyDrawerRef.current.getHealthconfig().then(() => {
                      healthyDrawerRef.current.setVisible(true);
                    });
                  }}
                >
                  <IconFont type="icon-shezhi" size={13} />
                </span>
              ) : (
                <></>
              )}
            </div>
            <div>
              <span className="healthy-state-num">
                {clusterMetrics?.HealthCheckPassed}/{clusterMetrics?.HealthCheckTotal}
              </span>
              {/* 健康度详情 */}
              <span
                className="healthy-state-btn"
                onClick={() => {
                  detailDrawerRef.current.setVisible(true);
                }}
              >
                查看详情
              </span>
            </div>
          </div>
        </div>
        <Divider />
        <div className="title">
          <div className="name">{renderToolTipValue(clusterInfo?.name, 35)}</div>
G
GraceWalk 已提交
156
          {!loading && global.hasPermission && global.hasPermission(ClustersPermissionMap.CLUSTER_CHANGE_INFO) ? (
Z
zengqiao 已提交
157 158 159 160 161 162 163 164 165 166 167
            <div className="edit-icon-box" onClick={() => setVisible(true)}>
              <IconFont className="edit-icon" type="icon-bianji2" />
            </div>
          ) : (
            <></>
          )}
        </div>
        <div className="tag-panel">
          <div className="tag default">{clusterInfo?.kafkaVersion ?? '-'}</div>
          {clusterMetrics?.LoadReBalanceEnable !== undefined &&
            [
G
GraceWalk 已提交
168 169 170
              ['BytesIn', clusterMetrics?.LoadReBalanceNwIn === 1],
              ['BytesOut', clusterMetrics?.LoadReBalanceNwOut === 1],
              ['Disk', clusterMetrics?.LoadReBalanceDisk === 1],
Z
zengqiao 已提交
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241
            ].map(([name, isBalanced]) => {
              return isBalanced ? (
                <div className="tag balanced">{name} 已均衡</div>
              ) : clusterMetrics?.LoadReBalanceEnable ? (
                <div className="tag unbalanced">{name} 未均衡</div>
              ) : (
                <Tooltip
                  title={
                    <span>
                      尚未开启 {name} 均衡策略,
                      <Link to={`/cluster/${clusterId}/cluster/balance`}>前往开启</Link>
                    </span>
                  }
                >
                  <div className="tag unbalanced">{name} 未均衡</div>
                </Tooltip>
              );
            })}
        </div>
        <div className="desc">{renderToolTipValue(clusterInfo?.description, 35)}</div>
        <div className="card-panel">
          <div className="card-item" onClick={() => history.push(`/cluster/${clusterId}/broker`)}>
            <div className="title">Brokers总数</div>
            <div className="count">
              <span className="num">{brokerState?.brokerCount ?? '-'}</span>
              <span className="unit"></span>
            </div>
            <div className="metric">
              <span className="type">Controller</span>
              {renderIcon(brokerState?.kafkaControllerAlive ? 'green' : 'red')}
            </div>
            <div className="metric">
              <span className="type">Similar Config</span>
              {renderIcon(brokerState?.configSimilar ? 'green' : 'warning')}
            </div>
          </div>
          <div className="card-item" onClick={() => history.push(`/cluster/${clusterId}/topic`)}>
            <div className="title">Topics总数</div>
            <div className="count">
              <span className="num">{clusterMetrics?.Topics ?? '-'}</span>
              <span className="unit"></span>
            </div>
            <div className="metric">
              <span className="type">No leader</span>
              {renderIcon(clusterMetrics?.PartitionNoLeader === 0 ? 'green' : 'red')}
            </div>
            <div className="metric">
              <span className="type">{'< Min ISR'}</span>
              {renderIcon(clusterMetrics?.PartitionMinISR_S === 0 ? 'green' : 'red')}
            </div>
            <div className="metric">
              <span className="type">URP</span>
              {renderIcon(clusterMetrics?.PartitionURP === 0 ? 'green' : 'red')}
            </div>
          </div>
          <div className="card-item" onClick={() => history.push(`/cluster/${clusterId}/consumers`)}>
            <div className="title">ConsumerGroup总数</div>
            <div className="count">
              <span className="num">{clusterMetrics?.Groups ?? '-'}</span>
              <span className="unit"></span>
            </div>
            <div className="metric">
              <span className="type">Dead</span>
              {renderIcon(clusterMetrics?.GroupDeads === 0 ? 'green' : 'red')}
            </div>
          </div>
        </div>
      </div>
      <AccessClusters
        visible={visible}
        setVisible={setVisible}
G
GraceWalk 已提交
242
        title="edit.cluster"
Z
zengqiao 已提交
243 244 245 246 247 248 249 250 251 252 253
        afterSubmitSuccess={getPhyClusterInfo}
        clusterInfo={clusterInfo}
        kafkaVersion={Object.keys(kafkaVersion)}
      />
      <HealthySetting ref={healthyDrawerRef} />
      <CheckDetail ref={detailDrawerRef} />
    </>
  );
};

export default LeftSider;