query.editor.html 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <query-editor-row query-ctrl="ctrl" can-collapse="false">
  2. <div class="gf-form-inline">
  3. <div class="gf-form gf-form--grow">
  4. <code-editor content="ctrl.target.rawSql" datasource="ctrl.datasource" on-change="ctrl.panelCtrl.refresh()" data-mode="sqlserver">
  5. </code-editor>
  6. </div>
  7. </div>
  8. <div class="gf-form-inline">
  9. <div class="gf-form">
  10. <label class="gf-form-label query-keyword">Format as</label>
  11. <div class="gf-form-select-wrapper">
  12. <select class="gf-form-input gf-size-auto" ng-model="ctrl.target.format" ng-options="f.value as f.text for f in ctrl.formats" ng-change="ctrl.refresh()"></select>
  13. </div>
  14. </div>
  15. <div class="gf-form">
  16. <label class="gf-form-label query-keyword" ng-click="ctrl.showHelp = !ctrl.showHelp">
  17. Show Help
  18. <i class="fa fa-caret-down" ng-show="ctrl.showHelp"></i>
  19. <i class="fa fa-caret-right" ng-hide="ctrl.showHelp"></i>
  20. </label>
  21. </div>
  22. <div class="gf-form" ng-show="ctrl.lastQueryMeta">
  23. <label class="gf-form-label query-keyword" ng-click="ctrl.showLastQuerySQL = !ctrl.showLastQuerySQL">
  24. Generated SQL
  25. <i class="fa fa-caret-down" ng-show="ctrl.showLastQuerySQL"></i>
  26. <i class="fa fa-caret-right" ng-hide="ctrl.showLastQuerySQL"></i>
  27. </label>
  28. </div>
  29. <div class="gf-form gf-form--grow">
  30. <div class="gf-form-label gf-form-label--grow"></div>
  31. </div>
  32. </div>
  33. <div class="gf-form" ng-show="ctrl.showLastQuerySQL">
  34. <pre class="gf-form-pre">{{ctrl.lastQueryMeta.sql}}</pre>
  35. </div>
  36. <div class="gf-form" ng-show="ctrl.showHelp">
  37. <pre class="gf-form-pre alert alert-info">Time series:
  38. - return column named time (in UTC), as a unix time stamp or any sql native date data type. You can use the macros below.
  39. - any other columns returned will be the time point values.
  40. Optional:
  41. - return column named <i>metric</i> to represent the series name.
  42. - If multiple value columns are returned the metric column is used as prefix.
  43. - If no column named metric is found the column name of the value column is used as series name
  44. Table:
  45. - return any set of columns
  46. Macros:
  47. - $__time(column) -&gt; column AS time
  48. - $__timeEpoch(column) -&gt; DATEDIFF(second, '1970-01-01', column) AS time
  49. - $__timeFilter(column) -&gt; column BETWEEN '2017-04-21T05:01:17Z' AND '2017-04-21T05:01:17Z'
  50. - $__unixEpochFilter(column) -&gt; column &gt;= 1492750877 AND column &lt;= 1492750877
  51. - $__timeGroup(column, '5m'[, fillvalue]) -&gt; CAST(ROUND(DATEDIFF(second, '1970-01-01', column)/300.0, 0) as bigint)*300.
  52. by setting fillvalue grafana will fill in missing values according to the interval
  53. fillvalue can be either a literal value, NULL or previous; previous will fill in the previous seen value or NULL if none has been seen yet
  54. - $__timeGroupAlias(column, '5m'[, fillvalue]) -&gt; CAST(ROUND(DATEDIFF(second, '1970-01-01', column)/300.0, 0) as bigint)*300 AS [time]
  55. Example of group by and order by with $__timeGroup:
  56. SELECT
  57. $__timeGroup(date_time_col, '1h') AS time,
  58. sum(value) as value
  59. FROM yourtable
  60. GROUP BY $__timeGroup(date_time_col, '1h')
  61. ORDER BY 1
  62. Or build your own conditionals using these macros which just return the values:
  63. - $__timeFrom() -&gt; '2017-04-21T05:01:17Z'
  64. - $__timeTo() -&gt; '2017-04-21T05:01:17Z'
  65. - $__unixEpochFrom() -&gt; 1492750877
  66. - $__unixEpochTo() -&gt; 1492750877
  67. </pre>
  68. </div>
  69. </div>
  70. <div class="gf-form" ng-show="ctrl.lastQueryError">
  71. <pre class="gf-form-pre alert alert-error">{{ctrl.lastQueryError}}</pre>
  72. </div>
  73. </query-editor-row>