Skip to content

Instantly share code, notes, and snippets.

@johann8384
Created November 8, 2012 00:10
Show Gist options
  • Save johann8384/4035540 to your computer and use it in GitHub Desktop.
Save johann8384/4035540 to your computer and use it in GitHub Desktop.
Render TSDB Graphs for Cacti Style Display
var page = require('webpage').create(),
address, output, size;
var tsdb_host = 'opentsdb.sv2.box.net';
var tsdb_port = 4242;
var start = '1h-ago';
var metric = 'sum:' + phantom.args[0];
var width = 1280;
var height = 720;
var address = 'http://' + tsdb_host + ':' + tsdb_port + '/q?start=' + start;
var address = address + '&m=' + metric + '&0=&yrange=[0:]&wxh=' + width + 'x' + height + '&png';
var output = phantom.args[0] + '_hourly.png';
console.log(address);
console.log(output);
page.viewportSize = { width: width, height: height };
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
window.setTimeout(function () {
page.render(output);
phantom.exit();
}, 200);
}
});
var start = '1d-ago';
var metric = 'sum:30m-avg:' + phantom.args[0];
var width = 1280;
var height = 720;
var address = 'http://' + tsdb_host + ':' + tsdb_port + '/q?start=' + start;
var address = address + '&m=' + metric + '&0=&yrange=[0:]&wxh=' + width + 'x' + height + '&png';
var output = phantom.args[0] + '_daily.png';
console.log(address);
console.log(output);
page.viewportSize = { width: width, height: height };
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
window.setTimeout(function () {
page.render(output);
phantom.exit();
}, 200);
}
});
var start = '1w-ago';
var metric = 'sum:6h-avg:' + phantom.args[0];
var width = 1280;
var height = 720;
var address = 'http://' + tsdb_host + ':' + tsdb_port + '/q?start=' + start;
var address = address + '&m=' + metric + '&0=&yrange=[0:]&wxh=' + width + 'x' + height + '&png';
var output = phantom.args[0] + '_weekly.png';
console.log(address);
console.log(output);
page.viewportSize = { width: width, height: height };
page.open(address, function (status) {
if (status !== 'success') {
console.log('Unable to load the address!');
} else {
window.setTimeout(function () {
page.render(output);
phantom.exit();
}, 200);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment