query.editor.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 time or time_sec (in UTC), as a unix time stamp or any sql native date data type. You can use the macros below.
  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. Resultsets of time series queries need to be sorted by time.
  45. Table:
  46. - return any set of columns
  47. Macros:
  48. - $__time(column) -&gt; UNIX_TIMESTAMP(column) as time_sec
  49. - $__timeEpoch(column) -&gt; UNIX_TIMESTAMP(column) as time_sec
  50. - $__timeFilter(column) -&gt; column BETWEEN '2017-04-21T05:01:17Z' AND '2017-04-21T05:01:17Z'
  51. - $__unixEpochFilter(column) -&gt; time_unix_epoch &gt; 1492750877 AND time_unix_epoch &lt; 1492750877
  52. - $__timeGroup(column,'5m'[, fillvalue]) -&gt; cast(cast(UNIX_TIMESTAMP(column)/(300) as signed)*300 as signed)
  53. by setting fillvalue grafana will fill in missing values according to the interval
  54. 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
  55. - $__timeGroupAlias(column,'5m') -&gt; cast(cast(UNIX_TIMESTAMP(column)/(300) as signed)*300 as signed) AS "time"
  56. - $__unixEpochGroup(column,'5m') -&gt; column DIV 300 * 300
  57. - $__unixEpochGroupAlias(column,'5m') -&gt; column DIV 300 * 300 AS "time"
  58. Example of group by and order by with $__timeGroup:
  59. SELECT
  60. $__timeGroup(timestamp_col, '1h') AS time,
  61. sum(value_double) as value
  62. FROM yourtable
  63. GROUP BY 1
  64. ORDER BY 1
  65. Or build your own conditionals using these macros which just return the values:
  66. - $__timeFrom() -&gt; '2017-04-21T05:01:17Z'
  67. - $__timeTo() -&gt; '2017-04-21T05:01:17Z'
  68. - $__unixEpochFrom() -&gt; 1492750877
  69. - $__unixEpochTo() -&gt; 1492750877
  70. </pre>
  71. </div>
  72. </div>
  73. <div class="gf-form" ng-show="ctrl.lastQueryError">
  74. <pre class="gf-form-pre alert alert-error">{{ctrl.lastQueryError}}</pre>
  75. </div>
  76. </query-editor-row>