return swap information
This commit is contained in:
+17
-2
@@ -2,7 +2,8 @@
|
||||
|
||||
exports = module.exports = {
|
||||
getDisks: getDisks,
|
||||
checkDiskSpace: checkDiskSpace
|
||||
checkDiskSpace: checkDiskSpace,
|
||||
getMemory: getMemory
|
||||
};
|
||||
|
||||
const apps = require('./apps.js'),
|
||||
@@ -13,7 +14,9 @@ const apps = require('./apps.js'),
|
||||
df = require('@sindresorhus/df'),
|
||||
docker = require('./docker.js'),
|
||||
notifications = require('./notifications.js'),
|
||||
paths = require('./paths.js');
|
||||
os = require('os'),
|
||||
paths = require('./paths.js'),
|
||||
safe = require('safetydance');
|
||||
|
||||
function getDisks(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
@@ -94,3 +97,15 @@ function checkDiskSpace(callback) {
|
||||
notifications.alert(notifications.ALERT_DISK_SPACE, 'Server is running out of disk space', oos ? JSON.stringify(disks.disks, null, 4) : '', callback);
|
||||
});
|
||||
}
|
||||
|
||||
function getMemory(callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
const stdout = safe.child_process.execSync('swapon --noheadings --raw --bytes --show=SIZE', { encoding: 'utf8' });
|
||||
const swap = !stdout ? 0 : stdout.split('\n').reduce((acc, cur) => acc + (parseInt(cur, 0) || 0));
|
||||
|
||||
callback(null, {
|
||||
memory: os.totalmem(),
|
||||
swap: swap
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ exports = module.exports = {
|
||||
isRebootRequired: isRebootRequired,
|
||||
getConfig: getConfig,
|
||||
getDisks: getDisks,
|
||||
getMemory: getMemory,
|
||||
getUpdateInfo: getUpdateInfo,
|
||||
update: update,
|
||||
checkForUpdates: checkForUpdates,
|
||||
@@ -62,6 +63,14 @@ function getDisks(req, res, next) {
|
||||
});
|
||||
}
|
||||
|
||||
function getMemory(req, res, next) {
|
||||
disks.getMemory(function (error, result) {
|
||||
if (error) return next(BoxError.toHttpError(error));
|
||||
|
||||
next(new HttpSuccess(200, result));
|
||||
});
|
||||
}
|
||||
|
||||
function update(req, res, next) {
|
||||
if ('skipBackup' in req.body && typeof req.body.skipBackup !== 'boolean') return next(new HttpError(400, 'skipBackup must be a boolean'));
|
||||
|
||||
|
||||
@@ -144,6 +144,7 @@ function initializeExpressSync() {
|
||||
router.post('/api/v1/cloudron/reboot', cloudronScope, routes.cloudron.reboot);
|
||||
router.get ('/api/v1/cloudron/graphs', cloudronScope, routes.graphs.getGraphs);
|
||||
router.get ('/api/v1/cloudron/disks', cloudronScope, routes.cloudron.getDisks);
|
||||
router.get ('/api/v1/cloudron/memory', cloudronScope, routes.cloudron.getMemory);
|
||||
router.get ('/api/v1/cloudron/logs/:unit', cloudronScope, routes.cloudron.getLogs);
|
||||
router.get ('/api/v1/cloudron/logstream/:unit', cloudronScope, routes.cloudron.getLogStream);
|
||||
router.get ('/api/v1/cloudron/eventlog', cloudronScope, routes.eventlog.list);
|
||||
|
||||
Reference in New Issue
Block a user