import React, { useState, useEffect } from 'react'; import { useParams } from 'react-router-dom'; import CardBar from './index'; import { Tag, Utils, Tooltip, Popover, AppContainer } from 'knowdesign'; import { IconFont } from '@knowdesign/icons'; import api from '@src/api'; import StateChart from './StateChart'; import ClusterNorms from '@src/pages/LoadRebalance/ClusterNorms'; import { QuestionCircleOutlined } from '@ant-design/icons'; import moment from 'moment'; import { ClustersPermissionMap } from '@src/pages/CommonConfig'; const transUnitTimePro = (ms: number, num = 0) => { if (!ms) return ''; if (ms < 60000) { return { value: 0, unit: `分钟` }; } if (ms >= 60000 && ms < 3600000) { return { value: (ms / 1000 / 60).toFixed(num), unit: `分钟` }; } if (ms >= 3600000 && ms < 86400000) { return { value: (ms / 1000 / 60 / 60).toFixed(num), unit: `小时` }; } return { value: (ms / 1000 / 60 / 60 / 24).toFixed(num), unit: `天` }; }; const LoadRebalanceCardBar = (props: any) => { const [global] = AppContainer.useGlobalValue(); const { clusterId } = useParams<{ clusterId: string; }>(); const [loading, setLoading] = useState(false); const [cardData, setCardData] = useState([]); const [normsVisible, setNormsVisible] = useState(null); const cardItems = ['AclEnable', 'Acls', 'AclUsers', 'AclTopics', 'AclGroups']; const onClose = () => { setNormsVisible(false); }; const getCartInfo = () => { // /api/v3/clusters/${clusterId}/balance-state /ks-km/api/v3/clusters/{clusterPhyId}/balance-state return Utils.request(api.getCartInfo(+clusterId)); }; useEffect(() => { setLoading(true); // 获取右侧状态 getCartInfo() .then((res: any) => { // const { AclEnable, Acls, AclUsers, AclTopics, AclGroups } = res.metrics; const { next, sub, status } = res; const { cpu, disk, bytesIn, bytesOut } = sub; const newNextDate: any = transUnitTimePro(moment(next).valueOf() - moment().valueOf()); // const newNextDate = parseInt(`${transUnitTimePro(moment(next).valueOf() - moment().valueOf())}`); const cardMap = [ { title() { return (
State {global.hasPermission(ClustersPermissionMap.REBALANCE_SETTING) && ( setNormsVisible(true)} type="icon-shezhi" > )}
); }, value() { return (
{!status ? '已均衡' : '未均衡'} {/* 已均衡 */}
周期均衡 {/* 周期均衡 */} 距下次均衡还剩{newNextDate?.value || 0} {newNextDate?.unit || '分钟'} {/* {距下次均衡还剩{1}小时} */}
); }, className: '', valueClassName: 'custom-card-bar-value', // cardbar value类名 customStyle: { // 自定义cardbar样式 marginLeft: 0, padding: '12px 12px 8px 12px', }, }, // { // // title: 'CPU avg', // title() { // return ( //
// CPU AVG // {!cpu?.interval && cpu?.interval !== 0 && ( // // // // )} // {/* setNormsVisible(true)} type="icon-shezhi"> */} //
// ); // }, // value(visibleType: boolean) { // return ( //
//
//
// {cpu?.avg || 0} // % //
//
// 均衡区间: ±{cpu?.interval || 0}% //
//
// //
// // 超过均衡区间的有: {cpu?.bigNu || 0} //
//
// // 在均衡区间内的有: {cpu?.betweenNu || 0} //
//
// // 低于均衡区间的有: {cpu?.smallNu || 0} //
//
// } // getPopupContainer={(triggerNode: any) => { // return triggerNode; // }} // color="#ffffff" // > //
// //
// // // ); // }, // className: 'custom-card-bar', // valueClassName: 'custom-card-bar-value', // }, { title() { return (
Disk AVG {!disk?.interval && disk?.interval !== 0 && ( )}
); }, value(visibleType: boolean) { return (
{Utils.transBToGB(disk?.avg)} GB
均衡区间: ±{disk?.interval || 0}%
超过均衡区间的有: {disk?.bigNu || 0}
在均衡区间内的有: {disk?.betweenNu || 0}
低于均衡区间的有: {disk?.smallNu || 0}
} getPopupContainer={(triggerNode: any) => { return triggerNode; }} >
); }, className: 'custom-card-bar', valueClassName: 'custom-card-bar-value', }, { title() { return (
BytesIn AVG {!bytesIn?.interval && bytesIn?.interval !== 0 && ( )}
); }, value(visibleType: boolean) { return (
{Utils.transBToMB(bytesIn?.avg || 0)} MB/s
均衡区间: ±{bytesIn?.interval || 0}%
超过均衡区间的有: {bytesIn?.bigNu || 0}
在均衡区间内的有: {bytesIn?.betweenNu || 0}
低于均衡区间的有: {bytesIn?.smallNu || 0}
} getPopupContainer={(triggerNode: any) => { return triggerNode; }} >
); }, className: 'custom-card-bar', valueClassName: 'custom-card-bar-value', }, { title() { return (
BytesOut AVG {!bytesOut?.interval && bytesOut?.interval !== 0 && ( )}
); }, value(visibleType: boolean) { return (
{Utils.transBToMB(bytesOut?.avg || 0)} MB/s
均衡区间: ±{bytesOut?.interval || 0}%
超过均衡区间的有: {bytesOut?.bigNu || 0}
在均衡区间内的有: {bytesOut?.betweenNu || 0}
低于均衡区间的有: {bytesOut?.smallNu || 0}
} getPopupContainer={(triggerNode: any) => { return triggerNode; }} >
); }, className: 'custom-card-bar', valueClassName: 'custom-card-bar-value', }, ]; setCardData(cardMap); }) .catch((err) => { const cardMap = [ { title() { return (
State setNormsVisible(true)} type="icon-shezhi">
); }, value: '-', customStyle: { // 自定义cardbar样式 marginLeft: 0, }, }, { title: 'CPU AVG', value: '-', }, { title: 'Disk AVG', value: '-', }, { title: 'BytesIn AVG', value: '-', }, { title: 'BytesOut AVG', value: '-', }, ]; setCardData(cardMap); }) .finally(() => { setLoading(false); }); }, [clusterId, props?.trigger]); return ( <> {} ); }; export default LoadRebalanceCardBar;