scripted.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. services : {}
  25. };
  26. // Set a title
  27. dashboard.title = 'Scripted dash';
  28. dashboard.services.filter = {
  29. time: {
  30. from: "now-" + (ARGS.from || timspan),
  31. to: "now"
  32. }
  33. };
  34. var rows = 1;
  35. var seriesName = 'argName';
  36. if(!_.isUndefined(ARGS.rows)) {
  37. rows = parseInt(ARGS.rows, 10);
  38. }
  39. if(!_.isUndefined(ARGS.name)) {
  40. seriesName = ARGS.name;
  41. }
  42. for (var i = 0; i < rows; i++) {
  43. dashboard.rows.push({
  44. title: 'Chart',
  45. height: '300px',
  46. panels: [
  47. {
  48. title: 'Events',
  49. type: 'graphite',
  50. span: 12,
  51. fill: 1,
  52. linewidth: 2,
  53. targets: [
  54. {
  55. 'target': "randomWalk('" + seriesName + "')"
  56. },
  57. {
  58. 'target': "randomWalk('random walk2')"
  59. }
  60. ],
  61. }
  62. ]
  63. });
  64. }
  65. return dashboard;