Skip to content
This repository
Browse code

Merge branch 'fix-error'

  • Loading branch information...
commit 4e8b01d752301dad6e69c0ebdd0b1240bc39730b 2 parents 795b00b + fec3b51
Mike Bostock mbostock authored
4 lib/cube/server/event.js
@@ -67,8 +67,8 @@ exports.putter = function(db) {
67 67 var floor = tiers[tier].floor;
68 68 metrics.update({
69 69 i: false,
70   - l: +tier,
71   - t: {
  70 + "_id.l": +tier,
  71 + "_id.t": {
72 72 $gte: floor(times[0]),
73 73 $lte: floor(times[1])
74 74 }
59 lib/cube/server/metric.js
@@ -4,10 +4,9 @@ var util = require("util"),
4 4 types = require("./types"),
5 5 reduces = require("./reduces");
6 6
7   -var metric_fields = {t: 1, g: 1, v: 1},
8   - metric_options = {sort: {t: 1}, batchSize: 1000},
9   - event_options = {sort: {t: 1}, batchSize: 1000},
10   - update_options = {upsert: true};
  7 +var metric_fields = {v: 1},
  8 + metric_options = {sort: {_id: 1}, batchSize: 1000},
  9 + event_options = {sort: {t: 1}, batchSize: 1000};
11 10
12 11 // Query for metrics.
13 12 // TODO use expression ids, and record how often expressions are queried?
@@ -68,9 +67,9 @@ exports.getter = function(db) {
68 67 // Query for the desired metric in the cache.
69 68 type.metrics.find({
70 69 i: false,
71   - e: expression.source,
72   - l: tier.key,
73   - t: {
  70 + "_id.e": expression.source,
  71 + "_id.l": tier.key,
  72 + "_id.t": {
74 73 $gte: start,
75 74 $lt: stop
76 75 }
@@ -84,9 +83,9 @@ exports.getter = function(db) {
84 83 cursor.each(function(error, row) {
85 84 if (error) throw error;
86 85 if (row) {
87   - callback(row.t, row.v, row.g);
88   - if (time < row.t) compute(time, row.t);
89   - time = tier.step(row.t);
  86 + callback(row._id.t, row.v, row._id.g);
  87 + if (time < row._id.t) compute(time, row._id.t);
  88 + time = tier.step(row._id.t);
90 89 } else {
91 90 if (time < stop) compute(time, stop);
92 91 }
@@ -203,31 +202,29 @@ exports.getter = function(db) {
203 202
204 203 function saveGroup(time, value, group) {
205 204 callback(time, value, group);
206   - if (value) type.metrics.update({
207   - e: expression.source,
208   - l: tier.key,
209   - t: time,
210   - g: group
211   - }, {
212   - $set: {
213   - i: false,
214   - v: new Double(value)
215   - }
216   - }, update_options);
  205 + if (value) type.metrics.save({
  206 + _id: {
  207 + e: expression.source,
  208 + l: tier.key,
  209 + t: time,
  210 + g: group
  211 + },
  212 + i: false,
  213 + v: new Double(value)
  214 + });
217 215 }
218 216
219 217 function save(time, value) {
220 218 callback(time, value);
221   - if (value) type.metrics.update({
222   - e: expression.source,
223   - l: tier.key,
224   - t: time
225   - }, {
226   - $set: {
227   - i: false,
228   - v: new Double(value)
229   - }
230   - }, update_options);
  219 + if (value) type.metrics.save({
  220 + _id: {
  221 + e: expression.source,
  222 + l: tier.key,
  223 + t: time
  224 + },
  225 + i: false,
  226 + v: new Double(value)
  227 + });
231 228 }
232 229 }
233 230 }
1  lib/cube/server/server.js
@@ -7,6 +7,7 @@ var util = require("util"),
7 7
8 8 // Don't crash on errors.
9 9 process.on("uncaughtException", function(error) {
  10 + util.log("uncaught exception: " + error);
10 11 util.log(error.stack);
11 12 });
12 13
4 package.json
... ... @@ -1,6 +1,6 @@
1 1 {
2 2 "name": "cube",
3   - "version": "0.0.15",
  3 + "version": "0.1.0",
4 4 "description": "A system for time series visualization using MongoDB, Node and D3.",
5 5 "keywords": ["time series", "visualization"],
6 6 "homepage": "http://square.github.com/cube/",
@@ -9,7 +9,7 @@
9 9 "main": "./lib/cube",
10 10 "dependencies": {
11 11 "d3": "2.7.2",
12   - "mongodb": "0.9.7-1.3",
  12 + "mongodb": "0.9.8-1",
13 13 "pegjs": "0.6.2",
14 14 "vows": "0.5.11",
15 15 "websocket": "1.0.2",
9 schema/schema-create.js
... ... @@ -1,11 +1,10 @@
1 1 db.createCollection("boards");
2 2
3   -["random", "stock", "collectd_df", "collectd_load", "collectd_interface", "collectd_memory"].forEach(function(type) {
  3 +["random", "collectd_df", "collectd_load", "collectd_interface", "collectd_memory"].forEach(function(type) {
4 4 var event = type + "_events", metric = type + "_metrics";
5 5 db.createCollection(event);
6 6 db[event].ensureIndex({t: 1});
7   - db.createCollection(metric, {capped: true, size: 1e6, autoIndexId: false});
8   - db[metric].ensureIndex({e: 1, l: 1, t: 1, g: 1}, {unique: true});
9   - db[metric].ensureIndex({i: 1, e: 1, l: 1, t: 1});
10   - db[metric].ensureIndex({i: 1, l: 1, t: 1});
  7 + db.createCollection(metric, {capped: true, size: 1e7, autoIndexId: true});
  8 + db[metric].ensureIndex({"i": 1, "_id.e": 1, "_id.l": 1, "_id.t": 1});
  9 + db[metric].ensureIndex({"i": 1, "_id.l": 1, "_id.t": 1});
11 10 });

0 comments on commit 4e8b01d

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