2014-08-27 14:47:41 -05:00
|
|
|
/* global _ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Complex scripted dashboard
|
|
|
|
* This script generates a dashboard object that Grafana can load. It also takes a number of user
|
|
|
|
* supplied URL parameters (int 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';
|
|
|
|
|
2017-07-31 05:12:28 -05:00
|
|
|
// accessible variables in this scope
|
2014-08-27 14:47:41 -05:00
|
|
|
var window, document, ARGS, $, jQuery, moment, kbn;
|
|
|
|
|
|
|
|
// Setup some variables
|
2014-11-20 09:32:19 -06:00
|
|
|
var dashboard;
|
2014-08-27 14:47:41 -05:00
|
|
|
|
|
|
|
// 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 : [],
|
2016-11-22 06:28:18 -06:00
|
|
|
schemaVersion: 13,
|
2014-08-27 14:47:41 -05:00
|
|
|
};
|
|
|
|
|
2016-11-22 06:28:18 -06:00
|
|
|
|
2014-08-27 14:47:41 -05:00
|
|
|
// Set a title
|
2014-11-20 09:32:19 -06:00
|
|
|
dashboard.title = 'Scripted and templated dash';
|
|
|
|
|
|
|
|
// Set default time
|
2017-07-31 05:12:28 -05:00
|
|
|
// time can be overridden in the url using from/to parameters, but this is
|
2014-11-20 09:32:19 -06:00
|
|
|
// handled automatically in grafana core during dashboard initialization
|
2014-08-27 14:47:41 -05:00
|
|
|
dashboard.time = {
|
2014-11-20 09:32:19 -06:00
|
|
|
from: "now-6h",
|
2014-08-27 14:47:41 -05:00
|
|
|
to: "now"
|
|
|
|
};
|
2014-11-20 09:32:19 -06:00
|
|
|
|
2014-08-27 14:47:41 -05:00
|
|
|
dashboard.templating = {
|
|
|
|
list: [
|
|
|
|
{
|
|
|
|
name: 'test',
|
|
|
|
query: 'apps.backend.*',
|
2016-11-22 06:28:18 -06:00
|
|
|
refresh: 1,
|
|
|
|
type: 'query',
|
|
|
|
datasource: null,
|
|
|
|
hide: 2,
|
2014-08-27 14:47:41 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'test2',
|
|
|
|
query: '*',
|
2016-11-22 06:28:18 -06:00
|
|
|
refresh: 1,
|
|
|
|
type: 'query',
|
|
|
|
datasource: null,
|
|
|
|
hide: 2,
|
2014-08-27 14:47:41 -05:00
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
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('[[test2]]')"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
}
|
|
|
|
]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return dashboard;
|