Browse Source

(*)大屏更新

master
peng.peng 2 years ago
parent
commit
b2d1211a00
  1. 66
      api/app/lib/controllers/homepage/index.js
  2. 10
      api/app/lib/routes/homepage/index.js
  3. 2
      api/package.json
  4. 7
      web/client/src/sections/homePage/containers/homePage.js

66
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
}

10
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))
};

2
api/package.json

@ -20,6 +20,7 @@
"better-xlsx": "^0.7.6", "better-xlsx": "^0.7.6",
"clickhouse": "^2.6.0", "clickhouse": "^2.6.0",
"crypto-js": "^4.0.0", "crypto-js": "^4.0.0",
"diskinfo": "0.0.3",
"file-saver": "^2.0.2", "file-saver": "^2.0.2",
"fs-web-server-scaffold": "^2.0.2", "fs-web-server-scaffold": "^2.0.2",
"ioredis": "^5.0.4", "ioredis": "^5.0.4",
@ -30,6 +31,7 @@
"mqtt": "^4.3.7", "mqtt": "^4.3.7",
"node-schedule": "^2.1.0", "node-schedule": "^2.1.0",
"nodemailer": "^6.7.7", "nodemailer": "^6.7.7",
"os-utils": "0.0.14",
"path": "^0.12.7", "path": "^0.12.7",
"path-to-regexp": "^3.0.0", "path-to-regexp": "^3.0.0",
"pg": "^7.9.0", "pg": "^7.9.0",

7
web/client/src/sections/homePage/containers/homePage.js

@ -1,8 +1,11 @@
import React, { useEffect, useState } from 'react' import React, { useEffect, useState } from 'react'
import './style.less' import './style.less'
function homePage (props) { function homePage(props) {
return <>nothing</>
return <div style={{ width: '100%', height: clientHeight, overflow: 'hidden' }}>
</div>
} }
export default homePage export default homePage
Loading…
Cancel
Save