Created
February 18, 2016 12:41
-
-
Save bergquist/af6b0233b42b2539e48b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global _ */ | |
/* | |
* Complex scripted dashboard | |
* This script generates a dashboard object that Grafana can load. It also takes a number of user | |
* supplied URL parameters (in the ARGS variable) | |
* | |
* Return a dashboard object, or a function | |
* | |
* For async scripts, return a function, this function must take a single callback function as argument, | |
* call this callback function with the dashboard object (look at scripted_async.js for an example) | |
*/ | |
'use strict'; | |
// accessible variables in this scope | |
var window, document, ARGS, $, jQuery, moment, kbn; | |
// Setup some variables | |
var dashboard; | |
// All url parameters are available via the ARGS object | |
var ARGS; | |
// Intialize a skeleton with nothing but a rows array and service object | |
dashboard = { | |
rows : [], | |
}; | |
// Set a title | |
dashboard.title = 'Scripted dash'; | |
// Set default time | |
// time can be overriden in the url using from/to parameters, but this is | |
// handled automatically in grafana core during dashboard initialization | |
dashboard.time = { | |
from: "now-6h", | |
to: "now" | |
}; | |
var rows = 1; | |
var seriesName = 'argName'; | |
if(!_.isUndefined(ARGS.rows)) { | |
rows = parseInt(ARGS.rows, 10); | |
} | |
if(!_.isUndefined(ARGS.name)) { | |
seriesName = ARGS.name; | |
} | |
for (var i = 0; i < rows; i++) { | |
dashboard.rows.push({ | |
title: 'Chart', | |
height: '300px', | |
panels: [ | |
{ | |
title: 'Events', | |
type: 'graph', | |
span: 12, | |
fill: 1, | |
linewidth: 2, | |
targets: [ | |
{ | |
'target': "randomWalk('" + seriesName + "')" | |
}, | |
{ | |
'target': "randomWalk('random walk2')" | |
} | |
], | |
seriesOverrides: [ | |
{ | |
alias: '/random/', | |
yaxis: 2, | |
fill: 0, | |
linewidth: 5 | |
} | |
], | |
tooltip: { | |
shared: true | |
} | |
} | |
] | |
}); | |
dashboard.templating = { | |
"enable": true, | |
"list": [ | |
{ | |
"allFormat": "regex values", | |
"current": { | |
"tags": [], | |
"text": "server1 + server2 + server3 + server4", | |
"value": [ | |
"server1", | |
"server2", | |
"server3", | |
"server4" | |
] | |
}, | |
"datasource": "InfluxDB", | |
"includeAll": true, | |
"multi": true, | |
"multiFormat": "regex values", | |
"name": "Hostname", | |
"options": [ | |
{ | |
"text": "All", | |
"value": "(10.1.100.1|10.1.100.10|server1|server2|server3|server4|server5|server7)" | |
}, | |
{ | |
"text": "10.1.100.1", | |
"value": "10.1.100.1" | |
}, | |
{ | |
"text": "10.1.100.10", | |
"value": "10.1.100.10" | |
}, | |
{ | |
"selected": true, | |
"text": "server1", | |
"value": "server1" | |
}, | |
{ | |
"selected": true, | |
"text": "server2", | |
"value": "server2" | |
}, | |
{ | |
"selected": true, | |
"text": "server3", | |
"value": "server3" | |
}, | |
{ | |
"selected": true, | |
"text": "server4", | |
"value": "server4" | |
}, | |
{ | |
"selected": false, | |
"text": "server5", | |
"value": "server5" | |
}, | |
{ | |
"text": "server7", | |
"value": "server7" | |
} | |
], | |
"query": "SHOW TAG VALUES WITH KEY = \"hostname\"", | |
"refresh": false, | |
"refresh_on_load": false, | |
"regex": "", | |
"type": "query" | |
}, | |
{ | |
"allFormat": "glob", | |
"auto": true, | |
"auto_count": 5, | |
"current": { | |
"tags": [], | |
"text": "1m", | |
"value": "1m" | |
}, | |
"datasource": null, | |
"includeAll": false, | |
"name": "summarize", | |
"options": [ | |
{ | |
"selected": false, | |
"text": "auto", | |
"value": "$__auto_interval" | |
}, | |
{ | |
"selected": true, | |
"text": "1m", | |
"value": "1m" | |
}, | |
{ | |
"selected": false, | |
"text": "10m", | |
"value": "10m" | |
}, | |
{ | |
"selected": false, | |
"text": "30m", | |
"value": "30m" | |
}, | |
{ | |
"selected": false, | |
"text": "1h", | |
"value": "1h" | |
}, | |
{ | |
"selected": false, | |
"text": "6h", | |
"value": "6h" | |
}, | |
{ | |
"selected": false, | |
"text": "12h", | |
"value": "12h" | |
}, | |
{ | |
"selected": false, | |
"text": "1d", | |
"value": "1d" | |
}, | |
{ | |
"selected": false, | |
"text": "7d", | |
"value": "7d" | |
}, | |
{ | |
"selected": false, | |
"text": "14d", | |
"value": "14d" | |
}, | |
{ | |
"selected": false, | |
"text": "30d", | |
"value": "30d" | |
} | |
], | |
"query": "1m,10m,30m,1h,6h,12h,1d,7d,14d,30d", | |
"refresh_on_load": true, | |
"type": "interval" | |
} | |
] | |
}; | |
} | |
return dashboard; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment