scripted.js 1.84 KB
Newer Older
1 2 3 4 5
/* global _ */

/*
 * Complex scripted dashboard
 * This script generates a dashboard object that Grafana can load. It also takes a number of user
6
 * supplied URL parameters (in the ARGS variable)
7
 *
8 9 10 11
 * 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)
12 13 14 15
 */

'use strict';

16
// accessible variables in this scope
17 18
var window, document, ARGS, $, jQuery, moment, kbn;

19
// Setup some variables
20
var dashboard;
21 22 23 24

// All url parameters are available via the ARGS object
var ARGS;

Cedric Cellier committed
25
// Initialize a skeleton with nothing but a rows array and service object
26 27 28 29 30 31
dashboard = {
  rows : [],
};

// Set a title
dashboard.title = 'Scripted dash';
32

33
// Set default time
Cedric Cellier committed
34
// time can be overridden in the url using from/to parameters, but this is
35
// handled automatically in grafana core during dashboard initialization
36
dashboard.time = {
37
  from: "now-6h",
38
  to: "now"
39 40 41
};

var rows = 1;
Torkel Odegaard committed
42
var seriesName = 'argName';
43 44 45 46 47 48

if(!_.isUndefined(ARGS.rows)) {
  rows = parseInt(ARGS.rows, 10);
}

if(!_.isUndefined(ARGS.name)) {
Torkel Odegaard committed
49
  seriesName = ARGS.name;
50 51 52 53 54 55 56 57 58 59
}

for (var i = 0; i < rows; i++) {

  dashboard.rows.push({
    title: 'Chart',
    height: '300px',
    panels: [
      {
        title: 'Events',
60
        type: 'graph',
61 62 63 64 65
        span: 12,
        fill: 1,
        linewidth: 2,
        targets: [
          {
Torkel Odegaard committed
66
            'target': "randomWalk('" + seriesName + "')"
67 68 69 70 71
          },
          {
            'target': "randomWalk('random walk2')"
          }
        ],
72 73 74 75 76 77 78 79 80 81 82
        seriesOverrides: [
          {
            alias: '/random/',
            yaxis: 2,
            fill: 0,
            linewidth: 5
          }
        ],
        tooltip: {
          shared: true
        }
83 84 85 86 87
      }
    ]
  });
}

88

89
return dashboard;