blob: 08f8f991619eae1a0fefd922a4743ddf890544f4 [file] [log] [blame]
koder aka kdanilovdda86d32015-03-16 11:20:04 +02001/* global _ */
2
3/*
4 * Complex scripted dashboard
5 * This script generates a dashboard object that Grafana can load. It also takes a number of user
6 * supplied URL parameters (int ARGS variable)
7 *
8 * Return a dashboard object, or a function
9 *
10 * For async scripts, return a function, this function must take a single callback function as argument,
11 * call this callback function with the dashboard object (look at scripted_async.js for an example)
12 */
13
14
15
16// accessable variables in this scope
17var window, document, ARGS, $, jQuery, moment, kbn;
18
19// Setup some variables
20var dashboard;
21
22// All url parameters are available via the ARGS object
23var ARGS;
24
25// Intialize a skeleton with nothing but a rows array and service object
26dashboard = {
27 rows : [],
28};
29
30// Set a title
31dashboard.title = 'Tests dash';
32
33// Set default time
34// time can be overriden in the url using from/to parameteres, but this is
35// handled automatically in grafana core during dashboard initialization
36dashboard.time = {
37 from: "now-5m",
38 to: "now"
39};
40
41var rows = 1;
42var seriesName = 'argName';
43
44if(!_.isUndefined(ARGS.rows)) {
45 rows = parseInt(ARGS.rows, 10);
46}
47
48if(!_.isUndefined(ARGS.name)) {
49 seriesName = ARGS.name;
50}
51
52for (var i = 0; i < rows; i++) {
53
54 dashboard.rows.push({
55 title: 'Chart',
56 height: '300px',
57 panels: [
58 {
59 title: 'Events',
60 type: 'graph',
61 span: 12,
62 fill: 1,
63 linewidth: 2,
64 targets: [
65 {"target": "disk io",
66 "query": "select value from \"sectors_written\" where $timeFilter and host='192.168.0.104' and device='sda1' order asc",
67 "interval": "",
68 "alias": "host io sw",
69 "rawQuery": true}
70 ],
71 tooltip: {
72 shared: true
73 }
74 }
75 ]
76 });
77}
78
79
80return dashboard;