editor.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <h3 class="dashboard-settings__header">Variables</h3>
  2. <div ng-controller="VariableEditorCtrl" ng-init="init()">
  3. <div ng-if="mode === 'list'">
  4. <div ng-if="variables.length === 0">
  5. <div class="empty-list-cta">
  6. <div class="empty-list-cta__title">There are no template variables added yet</div>
  7. <a ng-click="mode = 'new';" class="empty-list-cta__button btn btn-xlarge btn-success">
  8. <i class="gicon gicon-dashboard-new"></i>
  9. Add variable
  10. </a>
  11. <div class="grafana-info-box">
  12. <h5>
  13. What does variables do?
  14. </h5>
  15. <p>Variables enables more interactive and dynamic dashboards. Instead of hard-coding things like server or sensor names
  16. in your metric queries you can use variables in their place. Variables are shown as dropdown select boxes at the top of
  17. the dashboard. These dropdowns make it easy to change the data being displayed in your dashboard.
  18. Checkout the
  19. <a class="external-link" href="http://docs.grafana.org/reference/templating/" target="_blank">
  20. Templating documentation
  21. </a> for more information.
  22. </div>
  23. </div>
  24. </div>
  25. <div ng-if="variables.length">
  26. <div class="page-action-bar">
  27. <div class="page-action-bar__spacer"></div>
  28. <a type="button" class="btn btn-success" ng-click="mode = 'new';"><i class="fa fa-plus" ></i> New</a>
  29. </div>
  30. <table class="filter-table filter-table--hover">
  31. <thead>
  32. <tr>
  33. <th>Variable</th>
  34. <th>Definition</th>
  35. <th colspan="5"></th>
  36. </tr>
  37. </thead>
  38. <tbody>
  39. <tr ng-repeat="variable in variables">
  40. <td style="width: 1%">
  41. <span ng-click="edit(variable)" class="pointer template-variable">
  42. ${{variable.name}}
  43. </span>
  44. </td>
  45. <td style="max-width: 200px;" ng-click="edit(variable)" class="pointer max-width">
  46. {{variable.query}}
  47. </td>
  48. <td style="width: 1%"><i ng-click="_.move(variables,$index,$index-1)" ng-hide="$first" class="pointer fa fa-arrow-up"></i></td>
  49. <td style="width: 1%"><i ng-click="_.move(variables,$index,$index+1)" ng-hide="$last" class="pointer fa fa-arrow-down"></i></td>
  50. <td style="width: 1%">
  51. <a ng-click="duplicate(variable)" class="btn btn-inverse btn-mini">
  52. Duplicate
  53. </a>
  54. </td>
  55. <td style="width: 1%">
  56. <a ng-click="removeVariable(variable)" class="btn btn-danger btn-mini">
  57. <i class="fa fa-remove"></i>
  58. </a>
  59. </td>
  60. </tr>
  61. </tbody>
  62. </table>
  63. </div>
  64. </div>
  65. <form ng-if="mode === 'edit' || mode === 'new'" name="ctrl.form">
  66. <h5 class="section-heading">Variable</h5>
  67. <div class="gf-form-group">
  68. <div class="gf-form-inline">
  69. <div class="gf-form max-width-19">
  70. <span class="gf-form-label width-6">Name</span>
  71. <input type="text" class="gf-form-input" name="name" placeholder="name" ng-model='current.name' required ng-pattern="namePattern"></input>
  72. </div>
  73. <div class="gf-form max-width-19">
  74. <span class="gf-form-label width-6">
  75. Type
  76. <info-popover mode="right-normal">
  77. {{variableTypes[current.type].description}}
  78. </info-popover>
  79. </span>
  80. <div class="gf-form-select-wrapper max-width-17">
  81. <select class="gf-form-input" ng-model="current.type" ng-options="k as v.name for (k, v) in variableTypes" ng-change="typeChanged()"></select>
  82. </div>
  83. </div>
  84. </div>
  85. <div class="gf-form" ng-show="ctrl.form.name.$error.pattern">
  86. <span class="gf-form-label gf-form-label--error">Template names cannot begin with '__' that's reserved for Grafanas global variables</span>
  87. </div>
  88. <div class="gf-form-inline">
  89. <div class="gf-form max-width-19">
  90. <span class="gf-form-label width-6">Label</span>
  91. <input type="text" class="gf-form-input" ng-model='current.label' placeholder="optional display name"></input>
  92. </div>
  93. <div class="gf-form max-width-19">
  94. <span class="gf-form-label width-6">Hide</span>
  95. <div class="gf-form-select-wrapper max-width-15">
  96. <select class="gf-form-input" ng-model="current.hide" ng-options="f.value as f.text for f in hideOptions"></select>
  97. </div>
  98. </div>
  99. </div>
  100. </div>
  101. <div ng-if="current.type === 'interval'" class="gf-form-group">
  102. <h5 class="section-heading">Interval Options</h5>
  103. <div class="gf-form">
  104. <span class="gf-form-label width-9">Values</span>
  105. <input type="text" class="gf-form-input" placeholder="name" ng-model='current.query' placeholder="1m,10m,1h,6h,1d,7d" ng-model-onblur ng-change="runQuery()" required></input>
  106. </div>
  107. <div class="gf-form-inline">
  108. <gf-form-switch class="gf-form" label="Auto Option" label-class="width-9" checked="current.auto" on-change="runQuery()">
  109. </gf-form-switch>
  110. <div class="gf-form">
  111. <span class="gf-form-label width-9" ng-show="current.auto">
  112. Step count <tip>How many times should the current time range be divided to calculate the value</tip>
  113. </span>
  114. <div class="gf-form-select-wrapper max-width-10" ng-show="current.auto">
  115. <select class="gf-form-input" ng-model="current.auto_count" ng-options="f for f in [1,2,3,4,5,10,20,30,40,50,100,200,300,400,500]" ng-change="runQuery()"></select>
  116. </div>
  117. </div>
  118. <div class="gf-form">
  119. <span class="gf-form-label" ng-show="current.auto">
  120. Min interval <tip>The calculated value will not go below this threshold</tip>
  121. </span>
  122. <input type="text" class="gf-form-input max-width-10" ng-show="current.auto" ng-model="current.auto_min" ng-change="runQuery()" placeholder="10s"></input>
  123. </div>
  124. </div>
  125. </div>
  126. <div ng-if="current.type === 'custom'" class="gf-form-group">
  127. <h5 class="section-heading">Custom Options</h5>
  128. <div class="gf-form">
  129. <span class="gf-form-label width-14">Values separated by comma</span>
  130. <input type="text" class="gf-form-input" ng-model='current.query' ng-blur="runQuery()" placeholder="1, 10, 20, myvalue" required></input>
  131. </div>
  132. </div>
  133. <div ng-if="current.type === 'constant'" class="gf-form-group">
  134. <h5 class="section-heading">Constant options</h5>
  135. <div class="gf-form">
  136. <span class="gf-form-label">Value</span>
  137. <input type="text" class="gf-form-input" ng-model='current.query' ng-blur="runQuery()" placeholder="your metric prefix"></input>
  138. </div>
  139. </div>
  140. <div ng-if="current.type === 'query'" class="gf-form-group">
  141. <h5 class="section-heading">Query Options</h5>
  142. <div class="gf-form-inline">
  143. <div class="gf-form max-width-21">
  144. <span class="gf-form-label width-7">Data source</span>
  145. <div class="gf-form-select-wrapper max-width-14">
  146. <select class="gf-form-input" ng-model="current.datasource" ng-options="f.value as f.name for f in datasources" required>
  147. <option value="" ng-if="false"></option>
  148. </select>
  149. </div>
  150. </div>
  151. <div class="gf-form max-width-21">
  152. <span class="gf-form-label width-7">
  153. Refresh
  154. <info-popover mode="right-normal">
  155. When to update the values of this variable.
  156. </info-popover>
  157. </span>
  158. <div class="gf-form-select-wrapper max-width-14">
  159. <select class="gf-form-input" ng-model="current.refresh" ng-options="f.value as f.text for f in refreshOptions"></select>
  160. </div>
  161. </div>
  162. </div>
  163. <div class="gf-form">
  164. <span class="gf-form-label width-7">Query</span>
  165. <input type="text" class="gf-form-input" ng-model='current.query' placeholder="metric name or tags query" ng-model-onblur ng-change="runQuery()" required></input>
  166. </div>
  167. <div class="gf-form">
  168. <span class="gf-form-label width-7">
  169. Regex
  170. <info-popover mode="right-normal">
  171. Optional, if you want to extract part of a series name or metric node segment.
  172. </info-popover>
  173. </span>
  174. <input type="text" class="gf-form-input" ng-model='current.regex' placeholder="/.*-(.*)-.*/" ng-model-onblur ng-change="runQuery()"></input>
  175. </div>
  176. <div class="gf-form max-width-21">
  177. <span class="gf-form-label width-7">
  178. Sort
  179. <info-popover mode="right-normal">
  180. How to sort the values of this variable.
  181. </info-popover>
  182. </span>
  183. <div class="gf-form-select-wrapper max-width-14">
  184. <select class="gf-form-input" ng-model="current.sort" ng-options="f.value as f.text for f in sortOptions" ng-change="runQuery()"></select>
  185. </div>
  186. </div>
  187. </div>
  188. <div ng-show="current.type === 'datasource'" class="gf-form-group">
  189. <h5 class="section-heading">Data source options</h5>
  190. <div class="gf-form">
  191. <label class="gf-form-label width-12">Type</label>
  192. <div class="gf-form-select-wrapper max-width-18">
  193. <select class="gf-form-input" ng-model="current.query" ng-options="f.value as f.text for f in datasourceTypes" ng-change="runQuery()"></select>
  194. </div>
  195. </div>
  196. <div class="gf-form">
  197. <label class="gf-form-label width-12">
  198. Instance name filter
  199. <info-popover mode="right-normal">
  200. Regex filter for which data source instances to choose from in
  201. the variable value dropdown. Leave empty for all.
  202. <br><br>
  203. Example: <code>/^prod/</code>
  204. </info-popover>
  205. </label>
  206. <input type="text" class="gf-form-input max-width-18" ng-model='current.regex' placeholder="/.*-(.*)-.*/" ng-model-onblur ng-change="runQuery()"></input>
  207. </div>
  208. </div>
  209. <div ng-if="current.type === 'adhoc'" class="gf-form-group">
  210. <h5 class="section-heading">Options</h5>
  211. <div class="gf-form max-width-21">
  212. <span class="gf-form-label width-8">Data source</span>
  213. <div class="gf-form-select-wrapper max-width-14">
  214. <select class="gf-form-input" ng-model="current.datasource" ng-options="f.value as f.name for f in datasources" required ng-change="validate()">
  215. <option value="" ng-if="false"></option>
  216. </select>
  217. </div>
  218. </div>
  219. </div>
  220. <div class="section gf-form-group" ng-show="variableTypes[current.type].supportsMulti">
  221. <h5 class="section-heading">Selection Options</h5>
  222. <div class="section">
  223. <gf-form-switch class="gf-form"
  224. label="Multi-value"
  225. label-class="width-10"
  226. tooltip="Enables multiple values to be selected at the same time"
  227. checked="current.multi"
  228. on-change="runQuery()">
  229. </gf-form-switch>
  230. <gf-form-switch class="gf-form"
  231. label="Include All option"
  232. label-class="width-10"
  233. checked="current.includeAll"
  234. on-change="runQuery()">
  235. </gf-form-switch>
  236. </div>
  237. <div class="gf-form" ng-if="current.includeAll">
  238. <span class="gf-form-label width-10">Custom all value</span>
  239. <input type="text" class="gf-form-input max-width-15" ng-model='current.allValue' placeholder="blank = auto"></input>
  240. </div>
  241. </div>
  242. <div class="gf-form-group" ng-if="current.type === 'query'">
  243. <h5>Value groups/tags (Experimental feature)</h5>
  244. <gf-form-switch class="gf-form" label="Enabled" label-class="width-10" checked="current.useTags" on-change="runQuery()">
  245. </gf-form-switch>
  246. <div class="gf-form last" ng-if="current.useTags">
  247. <span class="gf-form-label width-10">Tags query</span>
  248. <input type="text" class="gf-form-input" ng-model='current.tagsQuery' placeholder="metric name or tags query" ng-model-onblur></input>
  249. </div>
  250. <div class="gf-form" ng-if="current.useTags">
  251. <li class="gf-form-label width-10">Tag values query</li>
  252. <input type="text" class="gf-form-input" ng-model='current.tagValuesQuery' placeholder="apps.$tag.*" ng-model-onblur></input>
  253. </div>
  254. </div>
  255. <div class="gf-form-group" ng-show="current.options.length">
  256. <h5>Preview of values (shows max 20)</h5>
  257. <div class="gf-form-inline">
  258. <div class="gf-form" ng-repeat="option in current.options | limitTo: 20">
  259. <span class="gf-form-label">{{option.text}}</span>
  260. </div>
  261. </div>
  262. </div>
  263. <div class="alert alert-info gf-form-group" ng-if="infoText">
  264. {{infoText}}
  265. </div>
  266. <div class="gf-form-button-row p-y-0">
  267. <button type="submit" class="btn btn-success" ng-show="mode === 'edit'" ng-click="update();">Update</button>
  268. <button type="submit" class="btn btn-success" ng-show="mode === 'new'" ng-click="add();">Add</button>
  269. </div>
  270. </form>
  271. </div>