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 ( ); }; return ( <>
(
{getHealthText(clusterMetrics?.HealthScore, clusterMetrics?.Alive)}
)} width={75} />
{getHealthState(clusterMetrics?.HealthScore, clusterMetrics?.Alive)} {/* 健康分设置 */} {global.hasPermission && global.hasPermission(ClustersPermissionMap.CLUSTER_CHANGE_HEALTHY) ? ( { healthyDrawerRef.current.getHealthconfig().then(() => { healthyDrawerRef.current.setVisible(true); }); }} > ) : ( <> )}
{clusterMetrics?.HealthCheckPassed}/{clusterMetrics?.HealthCheckTotal} {/* 健康度详情 */} { detailDrawerRef.current.setVisible(true); }} > 查看详情
{renderToolTipValue(clusterInfo?.name, 35)}
{!loading && global.hasPermission && global.hasPermission(ClustersPermissionMap.CLUSTER_CHANGE_INFO) ? (
setVisible(true)}>
) : ( <> )}
{clusterInfo?.kafkaVersion ?? '-'}
{clusterMetrics?.LoadReBalanceEnable !== undefined && [ ['BytesIn', clusterMetrics?.LoadReBalanceNwIn === 1], ['BytesOut', clusterMetrics?.LoadReBalanceNwOut === 1], ['Disk', clusterMetrics?.LoadReBalanceDisk === 1], ].map(([name, isBalanced]) => { return isBalanced ? (
{name} 已均衡
) : clusterMetrics?.LoadReBalanceEnable ? (
{name} 未均衡
) : ( 尚未开启 {name} 均衡策略, 前往开启 } >
{name} 未均衡
); })}
{renderToolTipValue(clusterInfo?.description, 35)}
history.push(`/cluster/${clusterId}/broker`)}>
Brokers总数
{brokerState?.brokerCount ?? '-'}
Controller {renderIcon(brokerState?.kafkaControllerAlive ? 'green' : 'red')}
Similar Config {renderIcon(brokerState?.configSimilar ? 'green' : 'warning')}
history.push(`/cluster/${clusterId}/topic`)}>
Topics总数
{clusterMetrics?.Topics ?? '-'}
No leader {renderIcon(clusterMetrics?.PartitionNoLeader === 0 ? 'green' : 'red')}
{'< Min ISR'} {renderIcon(clusterMetrics?.PartitionMinISR_S === 0 ? 'green' : 'red')}
URP {renderIcon(clusterMetrics?.PartitionURP === 0 ? 'green' : 'red')}
history.push(`/cluster/${clusterId}/consumers`)}>
ConsumerGroup总数
{clusterMetrics?.Groups ?? '-'}
Dead {renderIcon(clusterMetrics?.GroupDeads === 0 ? 'green' : 'red')}
); }; export default LeftSider;