scripted.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 (in the 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. // accessible variables in this scope
  14. var window, document, ARGS, $, jQuery, moment, kbn;
  15. // Setup some variables
  16. var dashboard;
  17. // All url parameters are available via the ARGS object
  18. // eslint-disable-next-line no-redeclare
  19. var ARGS;
  20. // Initialize a skeleton with nothing but a rows array and service object
  21. dashboard = {
  22. rows: [],
  23. };
  24. // Set a title
  25. dashboard.title = 'Scripted dash';
  26. // Set default time
  27. // time can be overridden in the url using from/to parameters, but this is
  28. // handled automatically in grafana core during dashboard initialization
  29. dashboard.time = {
  30. from: 'now-6h',
  31. to: 'now',
  32. };
  33. var rows = 1;
  34. var seriesName = 'argName';
  35. if (!_.isUndefined(ARGS.rows)) {
  36. rows = parseInt(ARGS.rows, 10);
  37. }
  38. if (!_.isUndefined(ARGS.name)) {
  39. seriesName = ARGS.name;
  40. }
  41. for (var i = 0; i < rows; i++) {
  42. dashboard.rows.push({
  43. title: 'Chart',
  44. height: '300px',
  45. panels: [
  46. {
  47. title: 'Events',
  48. type: 'graph',
  49. span: 12,
  50. fill: 1,
  51. linewidth: 2,
  52. targets: [
  53. {
  54. target: "randomWalk('" + seriesName + "')",
  55. },
  56. {
  57. target: "randomWalk('random walk2')",
  58. },
  59. ],
  60. seriesOverrides: [
  61. {
  62. alias: '/random/',
  63. yaxis: 2,
  64. fill: 0,
  65. linewidth: 5,
  66. },
  67. ],
  68. tooltip: {
  69. shared: true,
  70. },
  71. },
  72. ],
  73. });
  74. }
  75. return dashboard;