scripted_templated.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /* global _ */
  2. /*
  3. * Complex scripted dashboard
  4. * This script generates a dashboard object that Grafana can load. It also takes a number of user
  5. * supplied URL parameters (int ARGS variable)
  6. *
  7. * Return a dashboard object, or a function
  8. *
  9. * For async scripts, return a function, this function must take a single callback function as argument,
  10. * call this callback function with the dashboard object (look at scripted_async.js for an example)
  11. */
  12. 'use strict';
  13. // accessable variables in this scope
  14. var window, document, ARGS, $, jQuery, moment, kbn;
  15. // Setup some variables
  16. var dashboard, timspan;
  17. // All url parameters are available via the ARGS object
  18. var ARGS;
  19. // Set a default timespan if one isn't specified
  20. timspan = '1d';
  21. // Intialize a skeleton with nothing but a rows array and service object
  22. dashboard = {
  23. rows : [],
  24. };
  25. // Set a title
  26. dashboard.title = 'Scripted dash';
  27. dashboard.time = {
  28. from: "now-" + (ARGS.from || timspan),
  29. to: "now"
  30. };
  31. dashboard.templating = {
  32. enable: true,
  33. list: [
  34. {
  35. name: 'test',
  36. query: 'apps.backend.*',
  37. refresh: true,
  38. options: [],
  39. current: null,
  40. },
  41. {
  42. name: 'test2',
  43. query: '*',
  44. refresh: true,
  45. options: [],
  46. current: null,
  47. }
  48. ]
  49. };
  50. var rows = 1;
  51. var seriesName = 'argName';
  52. if(!_.isUndefined(ARGS.rows)) {
  53. rows = parseInt(ARGS.rows, 10);
  54. }
  55. if(!_.isUndefined(ARGS.name)) {
  56. seriesName = ARGS.name;
  57. }
  58. for (var i = 0; i < rows; i++) {
  59. dashboard.rows.push({
  60. title: 'Chart',
  61. height: '300px',
  62. panels: [
  63. {
  64. title: 'Events',
  65. type: 'graph',
  66. span: 12,
  67. fill: 1,
  68. linewidth: 2,
  69. targets: [
  70. {
  71. 'target': "randomWalk('" + seriesName + "')"
  72. },
  73. {
  74. 'target': "randomWalk('[[test2]]')"
  75. }
  76. ],
  77. }
  78. ]
  79. });
  80. }
  81. return dashboard;