From dd5aaf3248fe03dc9d08e145abdd8f40a3c9fe16 Mon Sep 17 00:00:00 2001 From: agate Date: Tue, 27 Aug 2013 14:11:14 +0800 Subject: [PATCH] added error history feature --- lib/upbeat/meta-data.ms | 7 +++++++ lib/upbeat/www/routes/services.ms | 13 +++++++------ lib/upbeat/www/views/action.jade | 31 ++++++++++++++++++++++++++----- package.json | 2 +- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/lib/upbeat/meta-data.ms b/lib/upbeat/meta-data.ms index b863bc4..685a515 100644 --- a/lib/upbeat/meta-data.ms +++ b/lib/upbeat/meta-data.ms @@ -23,6 +23,9 @@ export class MetaData { this.totalResTime = 0; this.totalCount = 0; + + this.errorHistory = []; + this.lastErrorMessage = null; this.lastResponseTime = null; @@ -77,6 +80,10 @@ export class MetaData { this.up = passed; this.emit('down', error); this.emit('change'); + this.errorHistory.push({ + error: error, + timestamp: now + }); } this.wasUp = passed; diff --git a/lib/upbeat/www/routes/services.ms b/lib/upbeat/www/routes/services.ms index 440e128..cb58891 100644 --- a/lib/upbeat/www/routes/services.ms +++ b/lib/upbeat/www/routes/services.ms @@ -6,7 +6,7 @@ module.exports = #(app, upbeat) { var service = upbeat.getService(req.params.service); if (! service) { res.send("Service not found", 404); - return false; + return false; } else { return service } @@ -41,23 +41,24 @@ module.exports = #(app, upbeat) { avgRespTime: action.meta.averageResponseTime(period), interval: action.interval, timeout: action.timeout, - passes: action.meta.total('passed-count'), - failures: action.meta.total('failed-count') + passes: action.meta.total('passed-count'), + failures: action.meta.total('failed-count'), + errorHistory: action.meta.errorHistory }, responseTimes: action.meta.plotResponseTimes('min') }; res.send(JSON.stringify(ret)); - } - + } + else { res.render('action', { action: action, service: service }); } } }); - app.get('/services/:service/health', #(req, res, next) { + app.get('/services/:service/health', #(req, res, next) { var service = getService(req, res); if (service) { if (service.up) { diff --git a/lib/upbeat/www/views/action.jade b/lib/upbeat/www/views/action.jade index 2f21dd2..73f94ed 100644 --- a/lib/upbeat/www/views/action.jade +++ b/lib/upbeat/www/views/action.jade @@ -3,7 +3,7 @@ block content ul.breadcrumb li a(href="/services/#{service.name}")= service.name - span.divider / + span.divider / li.active= action.name @@ -31,6 +31,8 @@ block content th Passed Count td#passes + h3 Error History + table.table.table-condensed.table-bordered.table-striped#errorHistory h3 Performance #container(style="width:100%;height:500px") @@ -44,11 +46,30 @@ block content } var chart = null; + function updateData(payload) { var meta = payload.meta; var data = payload.responseTimes; - for (var k in meta) $('#' + k).html(meta[k]); + for (var k in meta) { + var html = ''; + + if (k == 'errorHistory') { + html = meta.errorHistory.map(function (e) { + return '' + + '' + e.error + '' + + '@' + + '' + new Date(e.timestamp) + '' + + ''; + }).join("\n"); + } + + else { + html = meta[k]; + } + + $('#' + k).html(html) + } if (chart) { chart.series[0].setData(data, true); @@ -56,12 +77,12 @@ block content } chart = new Highcharts.Chart({ - chart: { + chart: { renderTo: 'container', type: 'line' - }, + }, - xAxis: { + xAxis: { title: { text: 'Seconds Ago' }, categories: #{categories.min.data} }, diff --git a/package.json b/package.json index ca84147..352ae11 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "Fast health and performance monitoring with process handling", "keywords": ["javascript", "performance", "health", "monitoring", "monit", "haproxy", "forever", "process", "systems"], "author": "Jeff Su ", - "version": "0.2.3-pre12", + "version": "0.2.3-pre13", "licenses": [{ "type": "MIT" }], "engines": { "node": ">=0.5.0" }, "directories" : { "lib" : "./lib/upbeat" },