From 81c9f3de2b8a77a9b1ec666c00ef3a7bfe5d429d Mon Sep 17 00:00:00 2001 From: "peng.peng" Date: Sun, 25 Jun 2023 10:20:08 +0800 Subject: [PATCH 1/3] =?UTF-8?q?(*)=E8=84=9A=E6=9C=AC=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/0.0.7/03_create_backups.sql | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/0.0.7/03_create_backups.sql b/scripts/0.0.7/03_create_backups.sql index a0d23e2..112564d 100644 --- a/scripts/0.0.7/03_create_backups.sql +++ b/scripts/0.0.7/03_create_backups.sql @@ -1,3 +1,5 @@ +create type enum_task_state as enum ('备份中', '备份成功', '备份失败', '恢复中', '恢复成功', '恢复失败'); + create table backups ( id serial From b2d1211a0026c7ad055b77ba9ff3f8cecd50fcf8 Mon Sep 17 00:00:00 2001 From: "peng.peng" Date: Sun, 25 Jun 2023 10:20:56 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=EF=BC=88*=EF=BC=89=E5=A4=A7=E5=B1=8F?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/homepage/index.js | 66 +++++++++++++++++++ api/app/lib/routes/homepage/index.js | 10 +++ api/package.json | 2 + .../sections/homePage/containers/homePage.js | 7 +- 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 api/app/lib/controllers/homepage/index.js create mode 100644 api/app/lib/routes/homepage/index.js diff --git a/api/app/lib/controllers/homepage/index.js b/api/app/lib/controllers/homepage/index.js new file mode 100644 index 0000000..1c0d886 --- /dev/null +++ b/api/app/lib/controllers/homepage/index.js @@ -0,0 +1,66 @@ +'use strict'; +const moment = require('moment'); +const diskinfo = require('diskinfo'); +const os = require('os-utils'); + +function getNodeResources(opts) { + return async function (ctx, next) { + let errMsg = { message: '获取节点资源失败' } + try { + //获取系统内存情况 + let freeMem = os.freemem() + let totalMem = os.totalmem() + let memory = Math.round(((totalMem - freeMem) / totalMem) * 1000) / 10 + //cpu利用率 + let cpuUsage = await getCPUUsage() + + //硬盘占用率数据 + let disk = await getDiskInfo(); + ctx.status = 200; + ctx.body = { disk, memory, cpu: Math.round(cpuUsage * 1000) / 10 }; + + } catch (error) { + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); + ctx.status = 400; + ctx.body = errMsg + } + } +} + +/** + * 获取硬盘信息 + */ +async function getDiskInfo() { + return new Promise(function (resolve, reject) { + diskinfo.getDrives((err, aDrives) => { + let map = new Map() + //遍历所有磁盘信息 + let total = 0, used = 0; + for (var i = 0; i < aDrives.length; i++) { + if (!map.has(aDrives[i].mounted)) { + map.set(aDrives[i].mounted, true) + total += aDrives[i].blocks; //总量 + used += aDrives[i].used; //已使用 + } + } + let rate = Math.round(used / total * 1000) / 10 + resolve(rate); + }); + }); +} + +/** + * 获取系统cpu利用率 + */ +async function getCPUUsage() { + return new Promise((resolve, reject) => { + os.cpuUsage(function (v) { + resolve(v) + }); + }); +} + + +module.exports = { + getNodeResources +} diff --git a/api/app/lib/routes/homepage/index.js b/api/app/lib/routes/homepage/index.js new file mode 100644 index 0000000..eafcb5d --- /dev/null +++ b/api/app/lib/routes/homepage/index.js @@ -0,0 +1,10 @@ +'use strict'; + +const backups = require('../../controllers/homepage/index'); + +module.exports = function (app, router, opts, AuthCode) { + + app.fs.api.logAttr['GET/homepage/node/resources'] = { content: '获取节点资源信息', visible: true }; + router.get('/homepage/node/resources', backups.getNodeResources(opts)) + +}; diff --git a/api/package.json b/api/package.json index cd41ba8..486827d 100644 --- a/api/package.json +++ b/api/package.json @@ -20,6 +20,7 @@ "better-xlsx": "^0.7.6", "clickhouse": "^2.6.0", "crypto-js": "^4.0.0", + "diskinfo": "0.0.3", "file-saver": "^2.0.2", "fs-web-server-scaffold": "^2.0.2", "ioredis": "^5.0.4", @@ -30,6 +31,7 @@ "mqtt": "^4.3.7", "node-schedule": "^2.1.0", "nodemailer": "^6.7.7", + "os-utils": "0.0.14", "path": "^0.12.7", "path-to-regexp": "^3.0.0", "pg": "^7.9.0", diff --git a/web/client/src/sections/homePage/containers/homePage.js b/web/client/src/sections/homePage/containers/homePage.js index b4db901..ebc7883 100644 --- a/web/client/src/sections/homePage/containers/homePage.js +++ b/web/client/src/sections/homePage/containers/homePage.js @@ -1,8 +1,11 @@ import React, { useEffect, useState } from 'react' import './style.less' -function homePage (props) { - return <>nothing +function homePage(props) { + + return
+ +
} export default homePage \ No newline at end of file From 8b7654f5eab2dccf2c1af20fd9adfd1adbb8f6c9 Mon Sep 17 00:00:00 2001 From: "peng.peng" Date: Sun, 25 Jun 2023 14:37:57 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=EF=BC=88*=EF=BC=89=E5=A4=A7=E5=B1=8F?= =?UTF-8?q?=E9=A1=B5=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sections/homePage/containers/homePage.js | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/web/client/src/sections/homePage/containers/homePage.js b/web/client/src/sections/homePage/containers/homePage.js index ebc7883..701b574 100644 --- a/web/client/src/sections/homePage/containers/homePage.js +++ b/web/client/src/sections/homePage/containers/homePage.js @@ -1,11 +1,25 @@ import React, { useEffect, useState } from 'react' +import { connect } from 'react-redux'; import './style.less' function homePage(props) { - + const { clientHeight } = props; return
- + 1
} -export default homePage \ No newline at end of file +function mapStateToProps(state) { + const { + auth, global + } = state; + return { + clientHeight: global.clientHeight, + actions: global.actions, + + }; +} + +export default connect(mapStateToProps)(homePage); + +