scripted.js 1.8 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 (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. var rows = 1;
  32. var seriesName = 'argName';
  33. if(!_.isUndefined(ARGS.rows)) {
  34. rows = parseInt(ARGS.rows, 10);
  35. }
  36. if(!_.isUndefined(ARGS.name)) {
  37. seriesName = ARGS.name;
  38. }
  39. for (var i = 0; i < rows; i++) {
  40. dashboard.rows.push({
  41. title: 'Chart',
  42. height: '300px',
  43. panels: [
  44. {
  45. title: 'Events',
  46. type: 'graph',
  47. span: 12,
  48. fill: 1,
  49. linewidth: 2,
  50. targets: [
  51. {
  52. 'target': "randomWalk('" + seriesName + "')"
  53. },
  54. {
  55. 'target': "randomWalk('random walk2')"
  56. }
  57. ],
  58. seriesOverrides: [
  59. {
  60. alias: '/random/',
  61. yaxis: 2,
  62. fill: 0,
  63. linewidth: 5
  64. }
  65. ],
  66. tooltip: {
  67. shared: true
  68. }
  69. }
  70. ]
  71. });
  72. }
  73. return dashboard;