alerts.jsonnet 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. local numAlerts = std.extVar('alerts');
  2. local condition = std.extVar('condition');
  3. local arr = std.range(1, numAlerts);
  4. local alertDashboardTemplate = {
  5. "editable": true,
  6. "gnetId": null,
  7. "graphTooltip": 0,
  8. "id": null,
  9. "links": [],
  10. "panels": [
  11. {
  12. "alert": {
  13. "conditions": [
  14. {
  15. "evaluator": {
  16. "params": [
  17. 65
  18. ],
  19. "type": "gt"
  20. },
  21. "operator": {
  22. "type": "and"
  23. },
  24. "query": {
  25. "params": [
  26. "A",
  27. "5m",
  28. "now"
  29. ]
  30. },
  31. "reducer": {
  32. "params": [],
  33. "type": "avg"
  34. },
  35. "type": "query"
  36. }
  37. ],
  38. "executionErrorState": "alerting",
  39. "frequency": "10s",
  40. "handler": 1,
  41. "for": "1m",
  42. "name": "bulk alerting",
  43. "noDataState": "no_data",
  44. "notifications": [
  45. {
  46. "id": 2
  47. }
  48. ]
  49. },
  50. "aliasColors": {},
  51. "bars": false,
  52. "dashLength": 10,
  53. "dashes": false,
  54. "datasource": "Prometheus",
  55. "fill": 1,
  56. "gridPos": {
  57. "h": 9,
  58. "w": 12,
  59. "x": 0,
  60. "y": 0
  61. },
  62. "id": 2,
  63. "legend": {
  64. "avg": false,
  65. "current": false,
  66. "max": false,
  67. "min": false,
  68. "show": true,
  69. "total": false,
  70. "values": false
  71. },
  72. "lines": true,
  73. "linewidth": 1,
  74. "nullPointMode": "null",
  75. "percentage": false,
  76. "pointradius": 5,
  77. "points": false,
  78. "renderer": "flot",
  79. "seriesOverrides": [],
  80. "spaceLength": 10,
  81. "stack": false,
  82. "steppedLine": false,
  83. "targets": [
  84. {
  85. "$$hashKey": "object:117",
  86. "expr": "go_goroutines",
  87. "format": "time_series",
  88. "intervalFactor": 1,
  89. "refId": "A"
  90. }
  91. ],
  92. "thresholds": [
  93. {
  94. "colorMode": "critical",
  95. "fill": true,
  96. "line": true,
  97. "op": "gt",
  98. "value": 50
  99. }
  100. ],
  101. "timeFrom": null,
  102. "timeShift": null,
  103. "title": "Panel Title",
  104. "tooltip": {
  105. "shared": true,
  106. "sort": 0,
  107. "value_type": "individual"
  108. },
  109. "type": "graph",
  110. "xaxis": {
  111. "buckets": null,
  112. "mode": "time",
  113. "name": null,
  114. "show": true,
  115. "values": []
  116. },
  117. "yaxes": [
  118. {
  119. "format": "short",
  120. "label": null,
  121. "logBase": 1,
  122. "max": null,
  123. "min": null,
  124. "show": true
  125. },
  126. {
  127. "format": "short",
  128. "label": null,
  129. "logBase": 1,
  130. "max": null,
  131. "min": null,
  132. "show": true
  133. }
  134. ]
  135. }
  136. ],
  137. "schemaVersion": 16,
  138. "style": "dark",
  139. "tags": [],
  140. "templating": {
  141. "list": []
  142. },
  143. "time": {
  144. "from": "now-6h",
  145. "to": "now"
  146. },
  147. "timepicker": {
  148. "refresh_intervals": [
  149. "5s",
  150. "10s",
  151. "30s",
  152. "1m",
  153. "5m",
  154. "15m",
  155. "30m",
  156. "1h",
  157. "2h",
  158. "1d"
  159. ],
  160. "time_options": [
  161. "5m",
  162. "15m",
  163. "1h",
  164. "6h",
  165. "12h",
  166. "24h",
  167. "2d",
  168. "7d",
  169. "30d"
  170. ]
  171. },
  172. "timezone": "",
  173. "title": "New dashboard",
  174. "uid": null,
  175. "version": 0
  176. };
  177. {
  178. ['alert-' + std.toString(x) + '.json']:
  179. alertDashboardTemplate + {
  180. panels: [
  181. alertDashboardTemplate.panels[0] +
  182. {
  183. alert+: {
  184. name: 'Alert rule ' + x,
  185. conditions: [
  186. alertDashboardTemplate.panels[0].alert.conditions[0] +
  187. {
  188. evaluator+: {
  189. params: [condition]
  190. }
  191. },
  192. ],
  193. },
  194. },
  195. ],
  196. uid: 'alert-' + x,
  197. title: 'Alert ' + x
  198. },
  199. for x in arr
  200. }