BaseStatistics.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import Statistics from '../components/Statistics';
  2. import './index.less';
  3. import Pie from '@/pages/home/components/Pie';
  4. import { getMenuPathByCode, MENUS_CODE } from '@/utils/menu';
  5. import { message } from 'antd';
  6. import { useEffect, useState } from 'react';
  7. import useSendWebsocketMessage from '@/hooks/websocket/useSendWebsocketMessage';
  8. import { map } from 'rxjs';
  9. import useHistory from '@/hooks/route/useHistory';
  10. const BaseStatistics = () => {
  11. const [subscribeTopic] = useSendWebsocketMessage();
  12. const history = useHistory();
  13. const [cpuValue, setCpuValue] = useState<number>(0);
  14. const [jvmValue, setJvmValue] = useState<number>(0);
  15. useEffect(() => {
  16. const cpuRealTime = subscribeTopic!(
  17. `operations-statistics-system-info-cpu-realTime`,
  18. `/dashboard/systemMonitor/stats/info/realTime`,
  19. {
  20. type: 'cpu',
  21. interval: '2s',
  22. agg: 'avg',
  23. },
  24. )
  25. ?.pipe(map((res) => res.payload))
  26. .subscribe((payload: any) => {
  27. setCpuValue(payload.value?.systemUsage || 0);
  28. });
  29. const jvmRealTime = subscribeTopic!(
  30. `operations-statistics-system-info-memory-realTime`,
  31. `/dashboard/systemMonitor/stats/info/realTime`,
  32. {
  33. type: 'memory',
  34. interval: '2s',
  35. agg: 'avg',
  36. },
  37. )
  38. ?.pipe(map((res) => res.payload))
  39. .subscribe((payload: any) => {
  40. setJvmValue(payload.value?.jvmHeapUsage || 0);
  41. });
  42. return () => {
  43. cpuRealTime?.unsubscribe();
  44. jvmRealTime?.unsubscribe();
  45. };
  46. }, []);
  47. return (
  48. <Statistics
  49. data={[
  50. {
  51. name: 'CPU使用率',
  52. value: String(cpuValue) + '%',
  53. children: (
  54. <Pie
  55. value={cpuValue}
  56. color={['#EBEBEB', '#D3ADF7']}
  57. image={require('/public/images/home/top-3.svg')}
  58. />
  59. ),
  60. },
  61. {
  62. name: 'JVM内存',
  63. value: String(jvmValue) + '%',
  64. children: (
  65. <Pie
  66. value={jvmValue}
  67. color={['#D6E4FF', '#85A5FF']}
  68. image={require('/public/images/home/top-4.svg')}
  69. />
  70. ),
  71. },
  72. ]}
  73. title="基础统计"
  74. extra={
  75. <div style={{ fontSize: 14, fontWeight: 400 }}>
  76. <a
  77. onClick={() => {
  78. const url = getMenuPathByCode(MENUS_CODE['link/DashBoard']);
  79. if (!!url) {
  80. history.push(`${url}`);
  81. } else {
  82. message.warning('暂无权限,请联系管理员');
  83. }
  84. }}
  85. >
  86. 详情
  87. </a>
  88. </div>
  89. }
  90. />
  91. );
  92. };
  93. export default BaseStatistics;