Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updates for human time and services

  • Loading branch information...
commit e67b18a5180aa64fcb52cdf39ba3532bd2b04adf 1 parent 024fddc
@vipworld vipworld authored
View
4 www/app.ms
@@ -29,7 +29,8 @@ module.exports = #(server, config) {
, routes = require('./routes')
, http = require('http')
, jade = require('jade')
- , path = require('path');
+ , path = require('path')
+ , HumanTime = require('./htime');
var app = express();
@@ -70,6 +71,7 @@ module.exports = #(server, config) {
locals.path = req.path;
locals.query = req.query;
locals.body = req.body;
+ locals.htime = new HumanTime();
next();
});
View
47 www/helpers.ms
@@ -1,4 +1,5 @@
module.exports = #(app) {
+
var SUFFIXES = {
min: 'seconds ago',
hour: 'minutes ago',
@@ -36,50 +37,6 @@ module.exports = #(app) {
'<span style="color: red">' + (down || 'down') + '</span>';
};
- app.locals.humanTime = #(time) {
- var now = (new Date()).getTime();
- var sec = 0, min = 0, hr = 0;
- sec = secondsAgo(time);
-
- function secondsAgo(t) {
- return Math.floor((now - t)/1000);
- }
-
- if (sec >= 60) {
- min = Math.floor(sec/60);
- sec = sec % 60;
- if (min >= 60) {
- hr = Math.floor(min/60);
- min = min % 60
- }
- }
- var hrMinSec = { hour: hr, minute: min, second: sec };
- var timeTxt = '';
-
- for (var division in hrMinSec) {
- var t = hrMinSec[division];
- if (t > 0 || division == 'second') {
- timeTxt += (t.toString() + ' ' + division + (t != 1 ? 's ago ' : ' ago '));
- }
- }
- return timeTxt;
- };
-
- app.locals.dateTime = #(t) {
- if (typeof t != 'number') return '';
- var d = new Date(t);
- var date = [d.getMonth(), d.getDay(), d.getFullYear()].join('-');
- var pad = #(t) {
- if (t < 10) => '0' + t.toString();
- else return t.toString();
- }
- var minute = pad(d.getMinutes());
- var second = pad(d.getSeconds());
- var time = [d.getHours(), minute, second].join(':');
- return date + ' ' + time;
- };
-
- app.locals.suffixes = SUFFIXES;
-
+ app.locals.suffixes = SUFFIXES;
};
View
59 www/htime.ms
@@ -0,0 +1,59 @@
+export class HumanTime {
+ function now() {
+ return this._now || (this._now = (new Date()).getTime());
+ }
+
+ function secondsAgo(t) {
+ return Math.floor((self.now() - t)/1000);
+ }
+
+ function timeDistance(time) {
+ var now = this.now();
+ var sec = 0, min = 0, hr = 0, day = 0;
+ sec = this.secondsAgo(time);
+ if (isNaN(sec)) => '---';
+
+ if (sec >= 60) {
+ min = Math.floor(sec/60);
+ sec = sec % 60;
+ if (min >= 60) {
+ hr = Math.floor(min/60);
+ min = min % 60;
+ if (hr >= 24) {
+ day = Math.floor(hr/24);
+ hr = hr % 24;
+ }
+ }
+ }
+ var hrMinSec = [
+ ['d', day],
+ ['h', hr],
+ ['m', min],
+ ['s', sec]
+ ];
+ var timeTxt = '';
+ var nStr;
+
+ foreach (var division in hrMinSec) {
+ var t = division[1];
+ if (t === 0 && division[0] != 's') continue;
+ nStr = t.toString();
+ timeTxt += (nStr + division[0] + ' ');
+ }
+ return timeTxt;
+ };
+
+ function dateTime(t) {
+ if (typeof t != 'number') return '';
+ var d = new Date(t);
+ var date = [d.getMonth(), d.getDay(), d.getFullYear()].join('-');
+ var pad = #(t) {
+ if (t < 10) => '0' + t.toString();
+ else return t.toString();
+ }
+ var minute = pad(d.getMinutes());
+ var second = pad(d.getSeconds());
+ var time = [d.getHours(), minute, second].join(':');
+ return date + ' ' + time;
+ };
+}
View
10 www/views/_services.jade
@@ -6,7 +6,6 @@ table.table.table-condensed.table-bordered
th Pass/Total
th Last Pass
th Last Failure
- th Avg. Request Time
- var i = 0;
each service, name in server.services
- var sname = name;
@@ -21,11 +20,12 @@ table.table.table-condensed.table-bordered
- first = false
td(style="padding-left: 20px"): a(href="/services/#{sname}/sensors/#{name}?time=min")= name
- td!= health(sensor.isHealthy)
+ td
+ != health(sensor.isHealthy)
+ span.inlinesparkline= sensor.getAvgResponse('hour').join(',');
td #{sensor.passCount}/#{sensor.totalCount}
- td= humanTime(sensor.lastPass);
- td= humanTime(sensor.lastFail);
- td: span.inlinesparkline= sensor.getAvgResponse('hour').join(',');
+ td= htime.timeDistance(sensor.lastPass) + ' ago';
+ td= htime.timeDistance(sensor.lastFail) + ' ago';
:mochi
$(function() {
Please sign in to comment.
Something went wrong with that request. Please try again.