Feature : #14 : _health and _version

This commit is contained in:
oof1lab
2018-01-06 16:43:22 +00:00
parent fe9133221e
commit c0ee4166cd
7 changed files with 195 additions and 23 deletions

View File

@@ -3,8 +3,11 @@
var Xsql = require('./xsql.js');
var Xctrl = require('./xctrl.js');
var multer = require('multer');
var path = require('path');
const path = require('path');
const pkginfo = require('pkginfo')(module);
const v8 = require('v8'),
os = require('os');
//define class
class Xapi {
@@ -267,6 +270,12 @@ class Xapi {
this.app.get('/download', this.downloadFile.bind(this));
/**************** END : multer routes ****************/
/**************** START : health and version ****************/
this.app.get('/_health', this.asyncMiddleware(this.health.bind(this)));
this.app.get('/_version', this.asyncMiddleware(this.version.bind(this)));
/**************** END : health and version ****************/
stat.api += 4;
}
@@ -371,6 +380,50 @@ class Xapi {
/**************** END : files related ****************/
/**************** START : health and version ****************/
async getMysqlUptime() {
let v = await this.mysql.exec('SHOW GLOBAL STATUS LIKE \'Uptime\';', []);
return v[0]['Value'];
}
async getMysqlHealth() {
let v = await this.mysql.exec('select version() as version', []);
return v[0]['version'];
}
async health(req, res) {
let status = {};
status['process_uptime'] = process.uptime();
status['mysql_uptime'] = await this.getMysqlUptime();
if (Object.keys(req.query).length) {
status['process_memory_usage'] = process.memoryUsage;
status['os_total_memory'] = os.totalmem();
status['os_free_memory'] = os.freemem();
status['os_load_average'] = os.loadavg();
status['v8_heap_statistics'] = v8.getHeapStatistics();
}
res.json(status);
}
async version(req, res) {
let version = {};
version['Xmysql'] = pkginfo.version;
version['mysql'] = await this.getMysqlHealth();
version['node'] = process.versions.node;
res.json(version);
}
/**************** END : health and version ****************/
}