scripted.js 1.8 KB

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