Browse Source

Make sure to normalize points for metric.send

fixes #20
pull/21/head
Brett Langdon 10 years ago
parent
commit
330814f25c
1 changed files with 16 additions and 0 deletions
  1. +16
    -0
      lib/api/metric.js

+ 16
- 0
lib/api/metric.js View File

@ -38,6 +38,22 @@ function send(metric, points, extra, callback){
callback = extra;
extra = {};
}
// Try to normalize `points`
// DEV: We need `points` to be an array of arrays regardless of what they give us
// Always wrap points in an array, this way we will get:
// 500 => [500]
// [<timestamp>, 500] => [[<timestamp>, 500]]
points = [points];
points = points.map(function(point){
// Make sure each point is an array, if not make array with current timestamp
// 500 => [<timestamp>, 500]
// [<timestamp>, 500] => unchanged
if(!Array.isArray(point)){
var now = parseInt(new Date().getTime() / 1000);
point = [now, point];
}
return point;
});
extra = extra || {};
var series = [


Loading…
Cancel
Save