0

I'm trying to get a graph to generate using this snippet of JS. I seem to be having a problem with metrics2.

if I set metrics2 to be this, then a graph is rendered in my browser.

[1]

 var metrics2 = [
     graphite.metric("servers.<HOSTNAME>-1_domain_local.load.load.shortterm"), 
     graphite.metric("servers.<HOSTNAME>-2_domain_local.load.load.shortterm"), 
     graphite.metric("servers.<HOSTNAME>-3_domain_local.load.load.shortterm"), 
     graphite.metric("servers.<HOSTNAME>-4_domain_local.load.load.shortterm")
 ]

However, in the following js code, a graph does NOT get rendered in my browser.

[2]

var metrics = [];
graphite.find("servers.*.load.load.shortterm", function(error, results) {
    for (var i = 0; i < results.length; i++) {
        metrics[i] = results[i];
    }
});

var metrics2 = metrics.map(function(i) { 
    return graphite.metric(i);
});

This is the cubism snippet that calls metrics2 and generates a graph.

d3.select(".span4").call(function(div) {
    a = metrics.length;
    div.select(".charts2").call(context.axis().orient("top"));
    div.select(".charts2").selectAll(".horizon")
        .data(metrics2)
        .enter().append("div")
        .attr("class", "horizon")
        .call(context.horizon().height(30));
});

Why won't [2] actually generate a graph? is there something with the metrics2 array?

1 Answers1

1

I figured it out. This piece of JS will make the needful happen.

graphite.find("servers.???-in-?-*.load.load.shortterm", function(error, results) {
    var metrics = results.map(function(i) {
        return graphite.metric(i);
    });

    d3.select(".span4").call(function(div) {
        div.select(".charts2").call(context.axis().orient("top"));
        div.select(".charts2").selectAll(".horizon")
            .data(metrics)
            .enter().append("div")
            .attr("class", "horizon")
            .call(context.horizon().height(30));
    });
});