Skip to content
Browse files

Merge branch 'fix-error'

  • Loading branch information...
2 parents 795b00b + fec3b51 commit 4e8b01d752301dad6e69c0ebdd0b1240bc39730b @mbostock mbostock committed Jan 18, 2012
Showing with 37 additions and 40 deletions.
  1. +2 −2 lib/cube/server/event.js
  2. +28 −31 lib/cube/server/metric.js
  3. +1 −0 lib/cube/server/server.js
  4. +2 −2 package.json
  5. +4 −5 schema/schema-create.js
View
4 lib/cube/server/event.js
@@ -67,8 +67,8 @@ exports.putter = function(db) {
var floor = tiers[tier].floor;
metrics.update({
i: false,
- l: +tier,
- t: {
+ "_id.l": +tier,
+ "_id.t": {
$gte: floor(times[0]),
$lte: floor(times[1])
}
View
59 lib/cube/server/metric.js
@@ -4,10 +4,9 @@ var util = require("util"),
types = require("./types"),
reduces = require("./reduces");
-var metric_fields = {t: 1, g: 1, v: 1},
- metric_options = {sort: {t: 1}, batchSize: 1000},
- event_options = {sort: {t: 1}, batchSize: 1000},
- update_options = {upsert: true};
+var metric_fields = {v: 1},
+ metric_options = {sort: {_id: 1}, batchSize: 1000},
+ event_options = {sort: {t: 1}, batchSize: 1000};
// Query for metrics.
// TODO use expression ids, and record how often expressions are queried?
@@ -68,9 +67,9 @@ exports.getter = function(db) {
// Query for the desired metric in the cache.
type.metrics.find({
i: false,
- e: expression.source,
- l: tier.key,
- t: {
+ "_id.e": expression.source,
+ "_id.l": tier.key,
+ "_id.t": {
$gte: start,
$lt: stop
}
@@ -84,9 +83,9 @@ exports.getter = function(db) {
cursor.each(function(error, row) {
if (error) throw error;
if (row) {
- callback(row.t, row.v, row.g);
- if (time < row.t) compute(time, row.t);
- time = tier.step(row.t);
+ callback(row._id.t, row.v, row._id.g);
+ if (time < row._id.t) compute(time, row._id.t);
+ time = tier.step(row._id.t);
} else {
if (time < stop) compute(time, stop);
}
@@ -203,31 +202,29 @@ exports.getter = function(db) {
function saveGroup(time, value, group) {
callback(time, value, group);
- if (value) type.metrics.update({
- e: expression.source,
- l: tier.key,
- t: time,
- g: group
- }, {
- $set: {
- i: false,
- v: new Double(value)
- }
- }, update_options);
+ if (value) type.metrics.save({
+ _id: {
+ e: expression.source,
+ l: tier.key,
+ t: time,
+ g: group
+ },
+ i: false,
+ v: new Double(value)
+ });
}
function save(time, value) {
callback(time, value);
- if (value) type.metrics.update({
- e: expression.source,
- l: tier.key,
- t: time
- }, {
- $set: {
- i: false,
- v: new Double(value)
- }
- }, update_options);
+ if (value) type.metrics.save({
+ _id: {
+ e: expression.source,
+ l: tier.key,
+ t: time
+ },
+ i: false,
+ v: new Double(value)
+ });
}
}
}
View
1 lib/cube/server/server.js
@@ -7,6 +7,7 @@ var util = require("util"),
// Don't crash on errors.
process.on("uncaughtException", function(error) {
+ util.log("uncaught exception: " + error);
util.log(error.stack);
});
View
4 package.json
@@ -1,6 +1,6 @@
{
"name": "cube",
- "version": "0.0.15",
+ "version": "0.1.0",
"description": "A system for time series visualization using MongoDB, Node and D3.",
"keywords": ["time series", "visualization"],
"homepage": "http://square.github.com/cube/",
@@ -9,7 +9,7 @@
"main": "./lib/cube",
"dependencies": {
"d3": "2.7.2",
- "mongodb": "0.9.7-1.3",
+ "mongodb": "0.9.8-1",
"pegjs": "0.6.2",
"vows": "0.5.11",
"websocket": "1.0.2",
View
9 schema/schema-create.js
@@ -1,11 +1,10 @@
db.createCollection("boards");
-["random", "stock", "collectd_df", "collectd_load", "collectd_interface", "collectd_memory"].forEach(function(type) {
+["random", "collectd_df", "collectd_load", "collectd_interface", "collectd_memory"].forEach(function(type) {
var event = type + "_events", metric = type + "_metrics";
db.createCollection(event);
db[event].ensureIndex({t: 1});
- db.createCollection(metric, {capped: true, size: 1e6, autoIndexId: false});
- db[metric].ensureIndex({e: 1, l: 1, t: 1, g: 1}, {unique: true});
- db[metric].ensureIndex({i: 1, e: 1, l: 1, t: 1});
- db[metric].ensureIndex({i: 1, l: 1, t: 1});
+ db.createCollection(metric, {capped: true, size: 1e7, autoIndexId: true});
+ db[metric].ensureIndex({"i": 1, "_id.e": 1, "_id.l": 1, "_id.t": 1});
+ db[metric].ensureIndex({"i": 1, "_id.l": 1, "_id.t": 1});
});

0 comments on commit 4e8b01d

Please sign in to comment.
Something went wrong with that request. Please try again.