I'm plotting some metrics that I have stored in a backbone collection that is being updated every second. I'm not seeing the correct metrics being plotted on cubism. For each metric, I only get the one metric plotted (with an incorrect) value. I don't really see how I can debug this. Here is my code:
var models = dataSet.models;
//aggregate 'metrics'. Each component has a 'metric' which contains its stats over time
for(model in models){
var attributes = models[model].attributes;
var metricData = metricCache.get(models[model].id);
var metrics = metricData['attributes']['metrics'];
if(!attributes['name'] || attributes['type']== "FLOW" || attributes['type'] == "SERVER"){
continue;
}
if(attributes['name'] == null){
continue;
}
var name = attributes['name'];
var type = attributes['type'];
var metName = name;
/* GETTING METRIC. Using js closure to pass correct values to metric call */
if(metricData != null){
//var curContext = getMetric(metName, metrics);
var curContext = (function(val1, val2){
return getMetric(val1, val2);
})(metName,metrics);
}
statsList.push(curContext);
}
'getMetric' takes the metric's name and 'metrics', which is an array of objects where each object has a timestamp and a value. I'm simply trying to plot each value with its corresponding timestamp on the horizon chart. Here is my code for 'getMetric'.
function getMetric(name, metricData){
var format = d3.time.format("%I-%M-%S");
return context.metric(function(start, stop, step, callback){
var statValues = [];
var lookup = {},
i = start.getTime();
//console.log('startTime', i);
var curStat = null;
for(stat in metricData){
curStat = metricData[stat];
curStat.value = +curStat.value;
var curDate = new Date(curStat.timestamp);
curDate = format(curDate);
lookup[curDate] = curStat;
}
var lastValue;
while((i+=step) < stop){
var key = format(new Date(i));
var curVal = key in lookup ? lookup[key].value : NaN;
console.log(name,curVal);
statValues.push(curVal);
}
//console.log(statValues);
callback(null,statValues);
}, name);
}
Here is a screenshot of what I see being plotted, which is each metric plotting the same values (which I verified is incorrect data).