0

I'm trying to log the latest data from a metric (actually in reality to update a div) but the dummy code below only ever logs out "undefined".

var context, cube, metric;
context = cubism.context().step("1e4").size(1080);
cube = context.cube(CUBE_SERVER);

metric = cube.metric("median(sar(value).eq(key,'ldavg_15').eq(host,'myserver'))");

metric.on("change", function(start, stop) {
  console.log("changing");
  if (typeof this.valueAt !== "undefined") {
    console.log(this, this.valueAt(-1));
  }
});

Can anyone show me some working code for the valueAt function? The same metric does work by the way as it is used elsewhere to plot a horizon graph.

Col Wilson
  • 889
  • 10
  • 16

1 Answers1

0

I'm afraid this in on handler refers to something else.

Use metric.valueAt(<your index>) instead, which will be 1079 (the last index of the metric data array, 1080 is the size of it).

Karel Frajták
  • 4,389
  • 1
  • 23
  • 34