Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change the step for Cube metrics?

Tags:

cubism.js

I am just starting out with cubism.js

Stripping down the example code I am able to show two metrics .. one calculated (kpi1) -- random function , one from Cube (kpi2). It works perfect at a context step of 1e4 as soon as I change it to 1e3 the calculated one - random - shows fine at a resolution of 1s while the one from Cube does not show at all.

this works:

var context = cubism.context()
    .serverDelay(0)
    .clientDelay(0)
    .step(1e4)
    .size(960);

this does not:

var context = cubism.context()
    .serverDelay(0)
    .clientDelay(0)
    .step(1e3)
    .size(960);

What am I doing wrong?

<!DOCTYPE html>
<html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><meta charset="utf-8">

<title>Dashboard</title>

</head><body><div id="body">


<div id="kpi1"></div>
<div id="kpi2"></div>


<script src="../d3.v2.js"></script>
<script src="../cubism.v1.js"></script>

<script>function random(name) {
  var value = 0,
      values = [],
      i = 0,
      last;
  return context.metric(function(start, stop, step, callback) {
    start = +start, stop = +stop;
    if (isNaN(last)) last = start;
    while (last < stop) {
      last += step;
      value = Math.max(-10, Math.min(10, value + .8 * Math.random() - .4 + .2 * Math.cos(i += .2)));
      values.push(value);
    }
    callback(null, values = values.slice((start - stop) / step));
  }, name);
}</script>

<script>

var context = cubism.context()
    .serverDelay(0)
    .clientDelay(0)
    .step(1e4)
    .size(960);

var foo = random("foo");
var cube = context.cube();

d3.select("#kpi1").call(function(div) {

   div.selectAll(".horizon")
      .data([foo])
    .enter().append("div")
      .attr("class", "horizon")
      .call(context.horizon());

});

d3.select("#kpi2").call(function(div) {

   div.selectAll(".horizon")
      .data([cube.metric("median(cube_compute(ms))")])
    .enter().append("div")
      .attr("class", "horizon")
      .call(context.horizon());

});

</script>

</body></html>
like image 803
user1771703 Avatar asked Oct 24 '12 15:10

user1771703


1 Answers

Cubism.js supports any step but the Cube backend system only supports metric aggregation from storage on one of these five steps:

  1e4 or 10 seconds
  6e4 or 1 minute
  3e5 or 5 minutes
  36e5 or 1 hour
  864e5 or 1 day

If you were to use a step which is between or below these, Cube would not be able to take advantage of the precalculations made at the lower and lowest supported levels, using pyramidal reducers.

like image 183
thadk Avatar answered Sep 23 '22 07:09

thadk