query.editor.html 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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="sql">
  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 <i>time</i> (UTC in seconds or timestamp)
  39. - return column(s) with numeric datatype as 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 -&gt; extract(epoch from 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; (extract(epoch from column)/300)::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') -&gt; (extract(epoch from column)/300)::bigint*300 AS "time"
  55. - $__unixEpochGroup(column,'5m') -&gt; floor(column/300)*300
  56. - $__unixEpochGroupAlias(column,'5m') -&gt; floor(column/300)*300 AS "time"
  57. Example of group by and order by with $__timeGroup:
  58. SELECT
  59. $__timeGroup(date_time_col, '1h'),
  60. sum(value) as value
  61. FROM yourtable
  62. GROUP BY time
  63. ORDER BY time
  64. Or build your own conditionals using these macros which just return the values:
  65. - $__timeFrom() -&gt; '2017-04-21T05:01:17Z'
  66. - $__timeTo() -&gt; '2017-04-21T05:01:17Z'
  67. - $__unixEpochFrom() -&gt; 1492750877
  68. - $__unixEpochTo() -&gt; 1492750877
  69. </pre>
  70. </div>
  71. </div>
  72. <div class="gf-form" ng-show="ctrl.lastQueryError">
  73. <pre class="gf-form-pre alert alert-error">{{ctrl.lastQueryError}}</pre>
  74. </div>
  75. </query-editor-row>