blob: 9ea396952386d77ef5f8e189af1cd4c25a90a868 [file] [log] [blame]
Jiarenxiang38dcb052025-03-13 16:40:09 +08001import React, { useEffect, useState } from 'react';
2import { getServerInfo } from '@/services/monitor/server';
3import { Card, Col, Row, Table } from 'antd';
4import { FormattedMessage } from '@umijs/max';
5import styles from './style.less';
6
7
8/* *
9 *
10 * @author whiteshader@163.com
11 * @datetime 2023/02/07
12 *
13 * */
14
15
16const columns = [
17 {
18 title: '属性',
19 dataIndex: 'name',
20 key: 'name',
21 },
22 {
23 title: '值',
24 dataIndex: 'value',
25 key: 'value',
26 },
27];
28
29const memColumns = [
30 {
31 title: '属性',
32 dataIndex: 'name',
33 key: 'name',
34 },
35 {
36 title: '内存',
37 dataIndex: 'mem',
38 key: 'mem',
39 },
40 {
41 title: 'JVM',
42 dataIndex: 'jvm',
43 key: 'jvm',
44 },
45];
46
47const hostColumns = [
48 {
49 title: 'col1',
50 dataIndex: 'col1',
51 key: 'col1',
52 },
53 {
54 title: 'col2',
55 dataIndex: 'col2',
56 key: 'col2',
57 },
58 {
59 title: 'col3',
60 dataIndex: 'col3',
61 key: 'col3',
62 },
63 {
64 title: 'col4',
65 dataIndex: 'col4',
66 key: 'col4',
67 },
68];
69
70const diskColumns = [
71 {
72 title: <FormattedMessage id="monitor.server.disk.dirName" defaultMessage="盘符路径" />,
73 dataIndex: 'dirName',
74 key: 'dirName',
75 },
76 {
77 title: <FormattedMessage id="monitor.server.disk.sysTypeName" defaultMessage="文件系统" />,
78 dataIndex: 'sysTypeName',
79 key: 'sysTypeName',
80 },
81 {
82 title: <FormattedMessage id="monitor.server.disk.typeName" defaultMessage="盘符类型" />,
83 dataIndex: 'typeName',
84 key: 'typeName',
85 },
86 {
87 title: <FormattedMessage id="monitor.server.disk.total" defaultMessage="总大小" />,
88 dataIndex: 'total',
89 key: 'total',
90 },
91 {
92 title: <FormattedMessage id="monitor.server.disk.free" defaultMessage="可用大小" />,
93 dataIndex: 'free',
94 key: 'free',
95 },
96 {
97 title: <FormattedMessage id="monitor.server.disk.used" defaultMessage="已用大小" />,
98 dataIndex: 'used',
99 key: 'used',
100 },
101 {
102 title: <FormattedMessage id="monitor.server.disk.usage" defaultMessage="已用百分比" />,
103 dataIndex: 'usage',
104 key: 'usage',
105 },
106];
107
108const ServerInfo: React.FC = () => {
109 const [cpuData, setCpuData] = useState<API.Monitor.CpuRowType[]>([]);
110 const [memData, setMemData] = useState<API.Monitor.MemRowType[]>([]);
111 const [hostData, setHostData] = useState<any>([]);
112 const [jvmData, setJvmData] = useState<any>([]);
113 const [diskData, setDiskData] = useState<any>([]);
114
115 useEffect(() => {
116 getServerInfo().then((res: API.Monitor.ServerInfoResponseType) => {
117 if (res.code === 200) {
118 // const cpuinfo: CpuRowType[] = [];
119 // Object.keys(res.data.cpu).forEach((item: any) => {
120 // cpuinfo.push({
121 // name: item,
122 // value: res.data.cpu[item],
123 // });
124 // });
125 // setCpuData(cpuinfo);
126
127 const cpuinfo: API.Monitor.CpuRowType[] = [];
128 cpuinfo.push({ name: '核心数', value: res.data.cpu.cpuNum });
129 cpuinfo.push({ name: '用户使用率', value: `${res.data.cpu.used}%` });
130 cpuinfo.push({ name: '系统使用率', value: `${res.data.cpu.sys}%` });
131 cpuinfo.push({ name: '当前空闲率', value: `${res.data.cpu.free}%` });
132
133 setCpuData(cpuinfo);
134
135 const memDatas: API.Monitor.MemRowType[] = [];
136 memDatas.push({
137 name: '总内存',
138 mem: `${res.data.mem.total}G`,
139 jvm: `${res.data.jvm.total}M`,
140 });
141 memDatas.push({
142 name: '已用内存',
143 mem: `${res.data.mem.used}G`,
144 jvm: `${res.data.jvm.used}M`,
145 });
146 memDatas.push({
147 name: '剩余内存',
148 mem: `${res.data.mem.free}G`,
149 jvm: `${res.data.jvm.free}M`,
150 });
151 memDatas.push({
152 name: '使用率',
153 mem: `${res.data.mem.usage}%`,
154 jvm: `${res.data.jvm.usage}%`,
155 });
156 setMemData(memDatas);
157
158 const hostinfo = [];
159 hostinfo.push({
160 col1: '服务器名称',
161 col2: res.data.sys.computerName,
162 col3: '操作系统',
163 col4: res.data.sys.osName,
164 });
165 hostinfo.push({
166 col1: '服务器IP',
167 col2: res.data.sys.computerIp,
168 col3: '系统架构',
169 col4: res.data.sys.osArch,
170 });
171 setHostData(hostinfo);
172
173 const jvminfo = [];
174 jvminfo.push({
175 col1: 'Java名称',
176 col2: res.data.jvm.name,
177 col3: 'Java版本',
178 col4: res.data.jvm.version,
179 });
180 jvminfo.push({
181 col1: '启动时间',
182 col2: res.data.jvm.startTime,
183 col3: '运行时长',
184 col4: res.data.jvm.runTime,
185 });
186 jvminfo.push({
187 col1: '安装路径',
188 col2: res.data.jvm.home,
189 col3: '项目路径',
190 col4: res.data.sys.userDir,
191 });
192 setJvmData(jvminfo);
193
194 const diskinfo = res.data.sysFiles.map((item: API.Monitor.DiskInfoType) => {
195 return {
196 dirName: item.dirName,
197 sysTypeName: item.sysTypeName,
198 typeName: item.typeName,
199 total: item.total,
200 free: item.free,
201 used: item.used,
202 usage: `${item.usage}%`,
203 };
204 });
205 setDiskData(diskinfo);
206 }
207 });
208 }, []);
209
210 return (
211 <div>
212 <Row gutter={[24, 24]}>
213 <Col span={12}>
214 <Card title="CPU" className={styles.card}>
215 <Table rowKey="name" pagination={false} showHeader={false} dataSource={cpuData} columns={columns} />
216 </Card>
217 </Col>
218 <Col span={12}>
219 <Card title="内存" className={styles.card}>
220 <Table
221 rowKey="name"
222 pagination={false}
223 showHeader={false}
224 dataSource={memData}
225 columns={memColumns}
226 />
227 </Card>
228 </Col>
229 </Row>
230 <Row gutter={[16, 16]}>
231 <Col span={24}>
232 <Card title="服务器信息" className={styles.card}>
233 <Table
234 rowKey="col1"
235 pagination={false}
236 showHeader={false}
237 dataSource={hostData}
238 columns={hostColumns}
239 />
240 </Card>
241 </Col>
242 </Row>
243 <Row gutter={[16, 16]}>
244 <Col span={24}>
245 <Card title="Java虚拟机信息" className={styles.card}>
246 <Table
247 rowKey="col1"
248 pagination={false}
249 showHeader={false}
250 dataSource={jvmData}
251 columns={hostColumns}
252 />
253 </Card>
254 </Col>
255 </Row>
256 <Row gutter={[16, 16]}>
257 <Col span={24}>
258 <Card title="磁盘状态" className={styles.card}>
259 <Table rowKey="dirName" pagination={false} dataSource={diskData} columns={diskColumns} />
260 </Card>
261 </Col>
262 </Row>
263 </div>
264 );
265};
266
267export default ServerInfo;