metrics-server
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -20,3 +20,3 @@ var util = require('util'); | ||
UDPServer.prototype.onMessage = function(msg) { | ||
UDPServer.prototype.onAdd = function(msg) { | ||
@@ -44,9 +44,15 @@ var time = msg.time; | ||
(new mongoose.Metric(item)).save(function(err) { | ||
if (err) | ||
console.log(err); | ||
}); | ||
(new mongoose.Metric(item)).save(); | ||
this.emit('metric', item); | ||
}; | ||
UDPServer.prototype.onMessage = function(msg) { | ||
if (Array.isArray(msg)) { | ||
msg.forEach(this.onAdd); | ||
} else { | ||
this.onAdd(msg); | ||
} | ||
}; | ||
UDPServer.prototype.start = function() { | ||
@@ -53,0 +59,0 @@ mongoose.start(this.options.mongodb || {}); |
@@ -25,4 +25,5 @@ var fs = require('fs'); | ||
app.get("/count", this.getCount.bind(this)); | ||
app.get("/count/:token", this.getMetricCount.bind(this)); | ||
app.get("/metric/:token", this.getMetric.bind(this)); | ||
app.get("/metric/:token/count", this.getMetricCount.bind(this)); | ||
app.get("/metric/:token/:group/:name", this.getStreamMetric.bind(this)); | ||
@@ -60,3 +61,3 @@ server.listen(this.options.port, this.options.host); | ||
} | ||
return query; | ||
@@ -104,14 +105,14 @@ }; | ||
var _metrics = {}; | ||
var count = 0; | ||
metrics.forEach(function(metric) { | ||
_metrics[metric.group] = _metrics[metric.group] || {}; | ||
_metrics[metric.group][metric.name] = _metrics[metric.group][metric.name] || []; | ||
_metrics[metric.group][metric.name].push({ | ||
time : metric.time, | ||
time : metric.time.getTime(), | ||
metric : metric.metric | ||
}); | ||
count++; | ||
}); | ||
res.header('x-count', count) | ||
res.json(_metrics); | ||
@@ -121,2 +122,42 @@ }); | ||
}; | ||
Server.prototype.getStreamMetric = function(req, res) { | ||
var limit = req.query.limit; | ||
var token = req.params.token; | ||
var name = req.params.name; | ||
var group = req.params.group; | ||
var first = true; | ||
var query = { | ||
token : token, | ||
name : name, | ||
group : group | ||
}; | ||
var stream = mongoose.Metric.find(query).sort({ | ||
'time' : -1 | ||
}); | ||
if (limit) { | ||
stream.limit(limit) | ||
} | ||
stream = stream.stream(); | ||
res.setHeader("Content-Type", "application/json"); | ||
res.write('['); | ||
stream.on('data', function(item) { | ||
var prefix = first ? '' : ', '; | ||
res.write(prefix + '[' + item.time.getTime() + ',' + item.metric + ']'); | ||
first = false; | ||
}); | ||
stream.on('end', function() { | ||
res.write(']'); | ||
res.end(); | ||
}); | ||
}; | ||
Server.prototype.start = function() { | ||
@@ -123,0 +164,0 @@ mongoose.start(this.options.mongodb || {}); |
{ | ||
"name": "metrics-server", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"author": "Tim <mangoraft@gmail.com>", | ||
@@ -5,0 +5,0 @@ "description": "Basic metrics server and client.", |
Sorry, the diff of this file is not supported yet
15556
347