blob: 77e3cf6a794989cb62c505aaa1eec420e523d1d0 [file] [log] [blame]
koder aka kdanilov36e3a6e2015-04-25 21:21:58 +03001<!DOCTYPE html>
2<meta charset="utf-8">
3<style>
4 @import url(http://fonts.googleapis.com/css?family=Yanone+Kaffeesatz:400,700);
5 @import url(http://square.github.io/cubism/style.css);
6</style>
7<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
8<script src="http://square.github.io/cubism/cubism.v1.js"></script>
9<div id="body"> <div id="graph" /></div>
10
11<script>
12
13// create context and horizon
14var context = cubism.context().serverDelay(3 * 1000).step(1000).size(1000)
15var horizon = context.horizon().extent([0, 100])
16
17// define metric accessor
18function wally_source(name) {
19 function selector(start, stop, step, callback){
20 function on_result(data) {
21 callback(null, data);
22 };
23
24 url = "/sensors?start=" + start + "&stop=" + stop + "&step=" + step + "&name=" + name;
25 d3.json(url, on_result);
26 }
27
28 return context.metric(selector, name);
29}
30
31// draw graph
32var metrics = ["testnodes:io_q", "testnodes:cpu"];
33horizon.metric(wally_source);
34
35d3.select("#graph").selectAll(".horizon")
36 .data(metrics)
37 .enter()
38 .append("div")
39 .attr("class", "horizon")
40 .call(horizon.height(120));
41
42// set rule
43d3.select("#body").append("div")
44 .attr("class", "rule")
45 .call(context.rule());
46
47// set focus
48context.on("focus", function(i) {
49 d3.selectAll(".value")
50 .style( "right", i == null ? null : context.size() - i + "px");
51});
52
53// set axis
54var axis = context.axis()
55d3.select("#graph").append("div").attr("class", "axis").append("g").call(axis);
56
57</script>