editor.html 12 KB

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