add uptime info

This commit is contained in:
AJ ONeal 2018-10-15 23:08:27 -06:00
parent 66758f4dbf
commit b75552a287
1 changed files with 8 additions and 0 deletions

View File

@ -23,6 +23,8 @@ var recase = require('recase').create({});
var camelCopy = recase.camelCopy.bind(recase);
var snakeCopy = recase.snakeCopy.bind(recase);
var TPLS = TOML.parse(fs.readFileSync(path.join(__dirname, "../lib/en-us.toml"), 'utf8'));
var startTime = Date.now();
var connectTimes = [];
var TelebitRemote = require('../lib/daemon/index.js').TelebitRemote;
@ -586,6 +588,7 @@ function handleApi(req, res) {
}
function getStatus() {
var now = Date.now();
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(
{ module: 'status'
@ -596,6 +599,10 @@ function handleApi(req, res) {
, connected: 'maybe (todo)'
, version: pkg.version
, servernames: state.servernames
, proctime: Math.round(process.uptime() * 1000)
, uptime: now - startTime
, runtime: connectTimes.length && (now - connectTimes[0]) || 0
, reconnects: connectTimes.length
}
));
}
@ -995,6 +1002,7 @@ function rawStartTelebitRemote(keepAlive) {
}
function onConnect() {
connectTimes.unshift(Date.now());
console.info('[connect] relay established');
myRemote.removeListener('error', onConnectError);
myRemote.once('error', function (err) {