Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

working on views for stats and services

  • Loading branch information...
commit 2098c50112af9f5aad46b60254eeed336d920e5a 1 parent be16315
@jeffsu authored
View
1  .gitignore
@@ -1,2 +1,3 @@
node_modules
.DS_Store
+dump.rdb
View
5 bin/upbeat
@@ -6,15 +6,12 @@ require('js-yaml');
var path = require('path');
var upbeat = require('../lib/upbeat');
-/*
if (process.argv.length !== 3) {
console.log("USAGE: upbeat <configFile>");
process.exit(0);
}
-*/
-//var configFile = process.argv[2];
-var configFile = "example.yml"
+var configFile = process.argv[2];
var config = require(path.join(process.cwd(), configFile));
var server = new upbeat.Server(config);
server.run();
View
15 index.js
@@ -1,15 +0,0 @@
-var upbeat = require('./lib');
-var server = upbeat.Server.fromConfig({
- services: {
- google: {
- standard: {
- strategy: 'http',
- url: 'https://www.google.com'
- }
- }
- },
- log: [ 'fail', 'pass' ]
-});
-
-
-server.run();
View
7 lib/client.ms
@@ -16,8 +16,11 @@ export class Client {
this.stats = {};
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);
+
+ this.redis.on('error', #{ self.hasRedis = false });
+ this.redis.on('connect', #{ self.hasRedis = true });
}
@@ -27,6 +30,8 @@ export class Client {
}
function sync() {
+ if (!this.hasRedis) return;
+
for (var name in this.stats) {
var stats = this.stats[name];
stats.sync(this.redis, name);
View
5 lib/server.ms
@@ -56,7 +56,12 @@ export class Server {
function buildRedis(config) {
if (!config) return;
var redis = require('redis').createClient(config);
+ var stop = true;
+ redis.on('error', #{ stop = true; console.log('hi') });
+ redis.on('connect', #{ stop = false; });
+
setInterval(#{
+ if (stop) return;
for (var k in self.stats) {
self.stats[k].sync(redis, k);
}
View
20 lib/strategies/index.ms
@@ -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) {
return #(cb) {
View
20 example.yml → mock/example.yml
@@ -1,19 +1,25 @@
services:
web-site:
- http:
+ slow-call:
+ strategy: http
+ url: http://localhost:3001/slow/good
+ timeout: 300
+ interval: 5000
+ average-call:
strategy: http
- url: http://www.google.com
+ url: http://localhost:3001/fast/average
timeout: 100
interval: 5000
- http2:
+ average-call:
strategy: http
- url: http://www.google.com
+ url: http://localhost:3001/fast/average
timeout: 100
- interval: 6000
- factual-www:
+ interval: 5000
+
+ web-site2:
http:
strategy: http
- url: http://www.factual.com
+ url: http://localhost:3001/fast/bad
timeout: 200
interval: 5000
View
0  examples/my-server.js → mock/my-server.js
File renamed without changes
View
12 mock/setup.js
@@ -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');
View
7 mock/upbeat-server.js
@@ -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();
View
6 package.json
@@ -13,10 +13,10 @@
"request": ">=2.10.0",
"jade": ">=0.27.2",
"express": ">=3.0.0rc3",
- "mochiscript": ">=0.6.9",
+ "mochiscript": ">=0.6.10",
"js-yaml": ">=0.3.1",
- "tempo": ">=0.1.0-pre6",
- "winston": ">=0.6.2"
+ "winston": ">=0.6.2",
+ "tempo": ">=0.1.0-pre7"
},
"repository": {
"type": "git",
View
81 server/app.ms
@@ -1,81 +0,0 @@
-
-/**
- * Module dependencies.
- */
-
-require('js-yaml');
-var express = require('express')
- , routes = require('./routes')
- , http = require('http')
- , path = require('path');
-
-var app = express();
-var upbeat = require('../lib/upbeat');
-var config = require(process.cwd() + '/example.yml');
-var server = new upbeat.Server(config);
-server.run();
-
-function getResource(params) {
- var service = server.services[params.service];
- return params.sensor ? service.sensors[params.sensor] : service;
-}
-
-var mochi = require('mochiscript').mochi;
-var jade = require('jade');
-jade.filters.mochi = #(block) {
- return ("<script>" + mochi.parse(block) + "</script>").replace(/#/g, '\\#').replace(/\n/g, '');
-};
-
-
-app.locals.health = #(passed, up, down) {
- return passed ?
- '<span style="color: green">' + (up || 'up') + '</span>' :
- '<span style="color: red">' + (down || 'down') + '</span>';
-};
-
-app.configure(function(){
- app.set('port', process.env.PORT || 3000);
- app.set('views', __dirname + '/views');
- app.set('view engine', 'jade');
- app.use(express.favicon());
- app.use(express.logger('dev'));
- app.use(express.bodyParser());
- app.use(express.methodOverride());
- app.use(app.router);
- app.use(express.static(path.join(__dirname, 'public')));
-});
-
-
-app.configure('development', function(){
- app.use(express.errorHandler());
-});
-
-app.get('/', #(req, res, next) {
- res.render('index', { params: req.params, server: server });
-});
-
-app.get('/services/:service.:format?', #(req, res, next) {
- if (req.params.format == 'json') {
- res.json(getResource(req.params).getAverageTimes('day'));
- } else {
- res.render('service', { params: req.params, server: server });
- }
-});
-
-app.get('/services/:service/health', #(req, res, next) {
-});
-
-app.get('/services/:service/sensors/:sensor.:format?', #(req, res, next) {
- if (req.params.format == 'json') {
- res.json(getResource(req.params).getAverageTimes('min'));
- } else {
- res.render('sensor', { params: req.params, sensor: getResource(req.params) });
- }
-});
-
-app.get('/services/:service/sensors/:sensor/health', #(req, res, next) {
-});
-
-http.createServer(app).listen(app.get('port'), function(){
- console.log("Express server listening on port " + app.get('port'));
-});
View
6 www/app.ms
@@ -31,6 +31,8 @@ module.exports = #(server, config) {
'<span style="color: red">' + (down || 'down') + '</span>';
};
+ app.locals.TIMES = [ 'min', 'hour', 'day', 'week' ];
+
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
@@ -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) {
if (req.params.format == 'json') {
res.json(getResource(req.params).getAverageTimes('day'));
View
10 www/views/index.jade
@@ -1,6 +1,7 @@
extends layout
block content
+ h3 Services
table.table.table-condensed.table-bordered(style="background-color: #333")
tr.success
th Service
@@ -26,3 +27,12 @@ block content
td= sensor.lastPass
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);
+
View
2  www/views/sensor.jade
@@ -1,7 +1,7 @@
extend layout
block content
h5
- a(href="/") services
+ a(href="/services") services
= ' > '
a(href="/services/#{params.service}")= params.service
= ' > ' + params.sensor
View
7 www/views/service.jade
@@ -1,8 +1,11 @@
extends layout
block content
- h5= params.service
+ h5
+ a(href="/services") services
+ = " >> "
+ = params.service
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")
style
View
27 www/views/services.jade
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.