Skip to content

Commit

Permalink
working on views for stats and services
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffsu committed Aug 29, 2012
1 parent be16315 commit 2098c50
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 114 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules node_modules
.DS_Store .DS_Store
dump.rdb
5 changes: 1 addition & 4 deletions bin/upbeat
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@ require('js-yaml');
var path = require('path'); var path = require('path');
var upbeat = require('../lib/upbeat'); var upbeat = require('../lib/upbeat');


/*
if (process.argv.length !== 3) { if (process.argv.length !== 3) {
console.log("USAGE: upbeat <configFile>"); console.log("USAGE: upbeat <configFile>");
process.exit(0); process.exit(0);
} }
*/


//var configFile = process.argv[2]; var configFile = process.argv[2];
var configFile = "example.yml"
var config = require(path.join(process.cwd(), configFile)); var config = require(path.join(process.cwd(), configFile));
var server = new upbeat.Server(config); var server = new upbeat.Server(config);
server.run(); server.run();
15 changes: 0 additions & 15 deletions index.js

This file was deleted.

7 changes: 6 additions & 1 deletion lib/client.ms
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ export class Client {
this.stats = {}; this.stats = {};


this.setInterval(); this.setInterval();
if (config.redisClient) this.redisClient = config.redisClient; if (config.redisClient) this.redis = config.redisClient;
else if (config.redis) this.redis = this.createRedisClient(config.redis); else if (config.redis) this.redis = this.createRedisClient(config.redis);

this.redis.on('error', #{ self.hasRedis = false });
this.redis.on('connect', #{ self.hasRedis = true });
} }




Expand All @@ -27,6 +30,8 @@ export class Client {
} }


function sync() { function sync() {
if (!this.hasRedis) return;

for (var name in this.stats) { for (var name in this.stats) {
var stats = this.stats[name]; var stats = this.stats[name];
stats.sync(this.redis, name); stats.sync(this.redis, name);
Expand Down
5 changes: 5 additions & 0 deletions lib/server.ms
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ export class Server {
function buildRedis(config) { function buildRedis(config) {
if (!config) return; if (!config) return;
var redis = require('redis').createClient(config); var redis = require('redis').createClient(config);
var stop = true;
redis.on('error', #{ stop = true; console.log('hi') });
redis.on('connect', #{ stop = false; });

setInterval(#{ setInterval(#{
if (stop) return;
for (var k in self.stats) { for (var k in self.stats) {
self.stats[k].sync(redis, k); self.stats[k].sync(redis, k);
} }
Expand Down
20 changes: 20 additions & 0 deletions lib/strategies/index.ms
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ module.exports = {
}; };
}, },


redis: #(options) {
try {
var redis = require('redis');
var client = redis.createClient(options);
} catch (e) {
throw "Please install the redis driver: npm install redis";
}

var error = false;
client.on('error', #{ error = true; });
client.on('connect', #{ error = false });

var command = options.command || [ 'exists', 'foo' ];

return #(cb) {
if (error) return cb("connection error");
client.exec(command, cb);
};
},

process: #(options) { process: #(options) {
return #(cb) { return #(cb) {


Expand Down
20 changes: 13 additions & 7 deletions example.yml → mock/example.yml
Original file line number Original file line Diff line number Diff line change
@@ -1,19 +1,25 @@
services: services:
web-site: web-site:
http: slow-call:
strategy: http
url: http://localhost:3001/slow/good
timeout: 300
interval: 5000
average-call:
strategy: http strategy: http
url: http://www.google.com url: http://localhost:3001/fast/average
timeout: 100 timeout: 100
interval: 5000 interval: 5000
http2: average-call:
strategy: http strategy: http
url: http://www.google.com url: http://localhost:3001/fast/average
timeout: 100 timeout: 100
interval: 6000 interval: 5000
factual-www:
web-site2:
http: http:
strategy: http strategy: http
url: http://www.factual.com url: http://localhost:3001/fast/bad
timeout: 200 timeout: 200
interval: 5000 interval: 5000


Expand Down
File renamed without changes.
12 changes: 12 additions & 0 deletions mock/setup.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,12 @@
var cp = require('child_process');

var exiting = false;

console.log('forking upbeat');
var upbeat = cp.fork(__dirname + '/upbeat-server.js');

console.log('forking test server');
var myServer = cp.fork(__dirname + '/my-server.js');

console.log('starting redis');
cp.exec('redis-server');
7 changes: 7 additions & 0 deletions mock/upbeat-server.js
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,7 @@
require('mochiscript');
require('js-yaml');

var upbeat = require('../lib/upbeat');
var config = require('./example.yml');
var server = new upbeat.Server(config);
server.run();
6 changes: 3 additions & 3 deletions package.json
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"request": ">=2.10.0", "request": ">=2.10.0",
"jade": ">=0.27.2", "jade": ">=0.27.2",
"express": ">=3.0.0rc3", "express": ">=3.0.0rc3",
"mochiscript": ">=0.6.9", "mochiscript": ">=0.6.10",
"js-yaml": ">=0.3.1", "js-yaml": ">=0.3.1",
"tempo": ">=0.1.0-pre6", "winston": ">=0.6.2",
"winston": ">=0.6.2" "tempo": ">=0.1.0-pre7"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
Expand Down
81 changes: 0 additions & 81 deletions server/app.ms

This file was deleted.

6 changes: 6 additions & 0 deletions www/app.ms
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module.exports = #(server, config) {
'<span style="color: red">' + (down || 'down') + '</span>'; '<span style="color: red">' + (down || 'down') + '</span>';
}; };


app.locals.TIMES = [ 'min', 'hour', 'day', 'week' ];

app.configure(function(){ app.configure(function(){
app.set('port', process.env.PORT || 3000); app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views'); app.set('views', __dirname + '/views');
Expand Down Expand Up @@ -62,6 +64,10 @@ module.exports = #(server, config) {
} }
}); });


app.get('/services', #(req, res, next) {
res.render('services', { params: req.params, services: server.services });
});

app.get('/services/:service.:format?', #(req, res, next) { app.get('/services/:service.:format?', #(req, res, next) {
if (req.params.format == 'json') { if (req.params.format == 'json') {
res.json(getResource(req.params).getAverageTimes('day')); res.json(getResource(req.params).getAverageTimes('day'));
Expand Down
10 changes: 10 additions & 0 deletions www/views/index.jade
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,7 @@
extends layout extends layout


block content block content
h3 Services
table.table.table-condensed.table-bordered(style="background-color: #333") table.table.table-condensed.table-bordered(style="background-color: #333")
tr.success tr.success
th Service th Service
Expand All @@ -26,3 +27,12 @@ block content
td= sensor.lastPass td= sensor.lastPass
td= sensor.lastFail td= sensor.lastFail


h3 Stats
ul
each st, name in server.stats
li
= name + ": "
each time in TIMES
= " "
a(href="/stats/#{name}/#{time}")= time.substr(0,1);

2 changes: 1 addition & 1 deletion www/views/sensor.jade
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
extend layout extend layout
block content block content
h5 h5
a(href="/") services a(href="/services") services
= ' > ' = ' > '
a(href="/services/#{params.service}")= params.service a(href="/services/#{params.service}")= params.service
= ' > ' + params.sensor = ' > ' + params.sensor
Expand Down
7 changes: 5 additions & 2 deletions www/views/service.jade
Original file line number Original file line Diff line number Diff line change
@@ -1,8 +1,11 @@
extends layout extends layout
block content block content
h5= params.service h5
a(href="/services") services
= " >> "
= params.service
each sensor, name in service.sensors each sensor, name in service.sensors
h5: a(href="/services/#{params.service}/sensors/#{name}") name h5: a(href="/services/#{params.service}/sensors/#{name}")= name
.chart(data-url="/services/#{params.service}/sensors/#{name}.json", data-type="pass-fail") .chart(data-url="/services/#{params.service}/sensors/#{name}.json", data-type="pass-fail")


style style
Expand Down
27 changes: 27 additions & 0 deletions www/views/services.jade
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,27 @@
extends layout

block content
table.table.table-condensed.table-bordered(style="background-color: #333")
tr.success
th Service
th Status
th Pass/Total
th Last Pass
th Last Failure
- var i = 0;
each service, sname in services
if i++ > 0
tr: td(colspan=5) &nbsp;
tr
td: a(href="/services/#{sname}")= sname
td!= health(service.isHealthy)
td
td
td
each sensor, name in service.sensors
tr
td(style="padding-left: 20px"): a(href="/services/#{sname}/sensors/#{name}")= name
td!= health(sensor.isHealthy)
td #{sensor.passCount}/#{sensor.totalCount}
td= sensor.lastPass
td= sensor.lastFail

0 comments on commit 2098c50

Please sign in to comment.