page.tsx 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. "use client";
  2. import { fetchApi } from "@/app/_modules/func";
  3. import { PageContainer, ProCard } from "@ant-design/pro-components";
  4. import { Statistic, Divider, Table } from "antd";
  5. import type { TableProps } from "antd";
  6. import { useEffect, useState } from "react";
  7. import { useRouter } from "next/navigation";
  8. import {
  9. faMicrochip,
  10. faMemory,
  11. faServer,
  12. faMugHot,
  13. faHardDrive,
  14. } from "@fortawesome/free-solid-svg-icons";
  15. import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
  16. import { Col, Row } from "@/node_modules/antd/es/index";
  17. import CountUp from "react-countup";
  18. //查询API
  19. const queryAPI = "/api/monitor/server";
  20. export default function Server() {
  21. const { push } = useRouter();
  22. const [data, setData] = useState(undefined as any);
  23. const columns: TableProps["columns"] = [
  24. {
  25. title: "盘符路径",
  26. dataIndex: "dirName",
  27. key: "dirName",
  28. },
  29. {
  30. title: "文件系统",
  31. dataIndex: "sysTypeName",
  32. key: "sysTypeName",
  33. },
  34. {
  35. title: "盘符类型",
  36. dataIndex: "typeName",
  37. key: "typeName",
  38. },
  39. {
  40. title: "总大小",
  41. dataIndex: "total",
  42. key: "total",
  43. },
  44. {
  45. title: "可用大小",
  46. dataIndex: "free",
  47. key: "free",
  48. },
  49. {
  50. title: "已用大小",
  51. dataIndex: "used",
  52. key: "used",
  53. },
  54. {
  55. title: "已用百分比",
  56. dataIndex: "usage",
  57. key: "usage",
  58. render: (text) => <>{text}%</>,
  59. },
  60. ];
  61. //查询数据
  62. const queryData = async () => {
  63. const body = await fetchApi(queryAPI, push);
  64. if (body !== undefined) {
  65. if (body.code == 200) {
  66. console.log("data:", body.data);
  67. setData(body.data);
  68. }
  69. }
  70. };
  71. useEffect(() => {
  72. queryData();
  73. }, []);
  74. const formatterDecimal = (value: any) => (
  75. <CountUp end={parseFloat(value)} separator="," decimals={2} />
  76. );
  77. return (
  78. <PageContainer title={false}>
  79. {data !== undefined && (
  80. <ProCard gutter={[16, 16]} style={{ marginBlockStart: 16 }} wrap>
  81. <ProCard
  82. title={
  83. <>
  84. <FontAwesomeIcon icon={faMicrochip} />
  85. <span style={{ marginLeft: 6 }}>CPU</span>
  86. </>
  87. }
  88. direction="row"
  89. headerBordered
  90. bordered
  91. hoverable
  92. >
  93. <ProCard>
  94. <Statistic title="核心数" value={data.cpu.cpuNum} />
  95. </ProCard>
  96. <Divider type="vertical" />
  97. <ProCard>
  98. <Statistic
  99. title="用户使用率"
  100. value={data.cpu.used}
  101. suffix="%"
  102. formatter={formatterDecimal}
  103. />
  104. </ProCard>
  105. <Divider type="vertical" />
  106. <ProCard>
  107. <Statistic
  108. title="系统使用率"
  109. value={data.cpu.sys}
  110. suffix="%"
  111. formatter={formatterDecimal}
  112. />
  113. </ProCard>
  114. <Divider type="vertical" />
  115. <ProCard>
  116. <Statistic
  117. title="当前空闲率"
  118. value={data.cpu.free}
  119. suffix="%"
  120. formatter={formatterDecimal}
  121. />
  122. </ProCard>
  123. </ProCard>
  124. <ProCard
  125. title={
  126. <>
  127. <FontAwesomeIcon icon={faMemory} />
  128. <span style={{ marginLeft: 6 }}>内存</span>
  129. </>
  130. }
  131. direction="row"
  132. headerBordered
  133. bordered
  134. hoverable
  135. >
  136. <ProCard title="总内存">
  137. <Statistic title="内存" value={data.mem.total} suffix="G" />
  138. <Statistic title="JVM" value={data.jvm.total} suffix="M" />
  139. </ProCard>
  140. <ProCard title="已用内存">
  141. <Statistic
  142. title="内存"
  143. value={data.mem.used}
  144. suffix="G"
  145. formatter={formatterDecimal}
  146. />
  147. <Statistic
  148. title="JVM"
  149. value={data.jvm.used}
  150. suffix="M"
  151. formatter={formatterDecimal}
  152. />
  153. </ProCard>
  154. <ProCard title="剩余内存">
  155. <Statistic
  156. title="内存"
  157. value={data.mem.free}
  158. suffix="G"
  159. formatter={formatterDecimal}
  160. />
  161. <Statistic
  162. title="JVM"
  163. value={data.jvm.free}
  164. suffix="M"
  165. formatter={formatterDecimal}
  166. />
  167. </ProCard>
  168. <ProCard title="使用率">
  169. <Statistic
  170. title="内存"
  171. value={data.mem.usage}
  172. suffix="%"
  173. valueStyle={{
  174. color: data.mem.usage > 80 ? "#cf1322" : "inherit",
  175. }}
  176. formatter={formatterDecimal}
  177. />
  178. <Statistic
  179. title="JVM"
  180. value={data.jvm.usage}
  181. suffix="%"
  182. valueStyle={{
  183. color: data.jvm.usage > 80 ? "#cf1322" : "inherit",
  184. }}
  185. formatter={formatterDecimal}
  186. />
  187. </ProCard>
  188. </ProCard>
  189. <ProCard
  190. title={
  191. <>
  192. <FontAwesomeIcon icon={faServer} />
  193. <span style={{ marginLeft: 6 }}>服务器信息</span>
  194. </>
  195. }
  196. direction="row"
  197. headerBordered
  198. bordered
  199. hoverable
  200. >
  201. <ProCard>
  202. <Statistic title="服务器名称" value={data.sys.computerName} />
  203. </ProCard>
  204. <ProCard>
  205. <Statistic title="服务器IP" value={data.sys.computerIp} />
  206. </ProCard>
  207. <ProCard>
  208. <Statistic title="操作系统" value={data.sys.osName} />
  209. </ProCard>
  210. <ProCard>
  211. <Statistic title="系统架构" value={data.sys.osArch} />
  212. </ProCard>
  213. </ProCard>
  214. <ProCard
  215. title={
  216. <>
  217. <FontAwesomeIcon icon={faMugHot} />
  218. <span style={{ marginLeft: 6 }}>Java虚拟机信息</span>
  219. </>
  220. }
  221. direction="column"
  222. headerBordered
  223. bordered
  224. hoverable
  225. >
  226. <Row gutter={[0, 16]}>
  227. <Col span={12}>
  228. <Statistic title="名称" value={data.jvm.name} />
  229. </Col>
  230. <Col span={12}>
  231. <Statistic title="版本" value={data.jvm.version} />
  232. </Col>
  233. </Row>
  234. <Row gutter={[0, 16]}>
  235. <Col span={12}>
  236. <Statistic title="启动时间" value={data.jvm.startTime} />
  237. </Col>
  238. <Col span={12}>
  239. <Statistic title="运行时长" value={data.jvm.runTime} />
  240. </Col>
  241. </Row>
  242. <Row gutter={[0, 16]}>
  243. <Col span={24}>
  244. <Statistic title="安装路径" value={data.jvm.home} />
  245. </Col>
  246. </Row>
  247. <Row gutter={[0, 16]}>
  248. <Col span={24}>
  249. <Statistic title="项目路径" value={data.sys.userDir} />
  250. </Col>
  251. </Row>
  252. <Row gutter={[0, 16]}>
  253. <Col span={24}>
  254. <Statistic title="运行参数" value={data.jvm.inputArgs} />
  255. </Col>
  256. </Row>
  257. </ProCard>
  258. <ProCard
  259. title={
  260. <>
  261. <FontAwesomeIcon icon={faHardDrive} />
  262. <span style={{ marginLeft: 6 }}>磁盘状态</span>
  263. </>
  264. }
  265. headerBordered
  266. bordered
  267. hoverable
  268. >
  269. <Table columns={columns} dataSource={data.sysFiles} />
  270. </ProCard>
  271. </ProCard>
  272. )}
  273. </PageContainer>
  274. );
  275. }