Browse Source

Add status to node page

pm2
Luke Childs 8 years ago
parent
commit
63c53f4755
  1. 46
      lib/nunjuck-filters.js
  2. 5
      views/node.html

46
lib/nunjuck-filters.js

@ -2,6 +2,27 @@ const prettyBytes = require('pretty-bytes');
const moment = require('moment');
const querystring = require('querystring');
function humanTimeAgo(utcDate) {
const diff = moment.utc().diff(moment.utc(utcDate));
const uptime = {};
uptime.s = Math.round(diff / 1000);
uptime.m = Math.floor(uptime.s / 60);
uptime.h = Math.floor(uptime.m / 60);
uptime.d = Math.floor(uptime.h / 24);
uptime.s %= 60;
uptime.m %= 60;
uptime.h %= 24;
let readableUptime = '';
readableUptime += uptime.d ? ` ${uptime.d}d` : '';
readableUptime += uptime.h ? ` ${uptime.h}h` : '';
readableUptime += !uptime.d || !uptime.h && uptime.m ? ` ${uptime.m}m` : '';
return readableUptime.trim();
}
const filters = {
bandwidth: node => `${prettyBytes(node.advertised_bandwidth)}/s`,
uptime: node => {
@ -12,25 +33,7 @@ const filters = {
}
// Check uptime
const lastRestarted = moment.utc(node.last_restarted);
const diff = moment.utc().diff(lastRestarted);
const uptime = {};
uptime.s = Math.round(diff / 1000);
uptime.m = Math.floor(uptime.s / 60);
uptime.h = Math.floor(uptime.m / 60);
uptime.d = Math.floor(uptime.h / 24);
uptime.s %= 60;
uptime.m %= 60;
uptime.h %= 24;
let readableUptime = '';
readableUptime += uptime.d ? ` ${uptime.d}d` : '';
readableUptime += uptime.h ? ` ${uptime.h}h` : '';
readableUptime += !uptime.d || !uptime.h && uptime.m ? ` ${uptime.m}m` : '';
return readableUptime.trim();
return humanTimeAgo(node.last_restarted);
},
pagination: (req, direction) => {
@ -52,7 +55,10 @@ const filters = {
},
name: node => node.nickname
|| node.fingerprint && node.fingerprint.slice(0, 8)
|| node.hashed_fingerprint && node.hashed_fingerprint.slice(0, 8)
|| node.hashed_fingerprint && node.hashed_fingerprint.slice(0, 8),
status: node => node.running ?
`Up for ${humanTimeAgo(node.last_restarted)}` :
`Down for ${humanTimeAgo(node.last_seen)}`
};
module.exports = app => Object.keys(filters).forEach(filter => {

5
views/node.html

@ -6,6 +6,11 @@
<h2>{{ 'Invalid node' if error.statusCode == 400 else error.statusMessage }}</h2>
{% else %}
<h2>{{ node.type | title }}: {{ node | name }}</h2>
<section class="status">
<h3>Status</h3>
{{ node | status }}
</section>
{% endif %}
{% endblock %}

Loading…
Cancel
Save