You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 389869e
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: en/monitors/alert-rules/description-template.mdx
+59Lines changed: 59 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -111,6 +111,65 @@ Example:
111
111
{{- end }}
112
112
```
113
113
114
+
<spanid="recovery-values"></span>
115
+
## Show values at recovery time in recovery notifications
116
+
117
+
When an alert recovers, the description and custom fields (including `title`) are rendered again, and `$status` is `recovered`. Which check the numbers in `$values` come from depends on the check mode and the **Recovery mode**.
118
+
119
+
### Values for each recovery mode
120
+
121
+
| Check mode | Recovery mode |`$values` in the recovery notification |
122
+
| --- | --- | --- |
123
+
|**Threshold evaluation**| Recovery when no thresholds are triggered | Values at recovery time |
124
+
|**Threshold evaluation**| Recovery only when conditions are met | Values at recovery time, including queries referenced only by the recovery expression |
125
+
|**Threshold evaluation**| Recovery when expression finds data | Main query values; see the note below |
126
+
|**Data exists**| Recover if no data | Values from the most recent firing or repeat notification |
127
+
|**Data exists**| Recover when results found | Main query values; see the note below |
128
+
129
+
In the two modes that use a recovery query, main query values are the values at recovery time if the main query still returns the alerting object. Otherwise, they're the values from the most recent firing or repeat notification. The recovery query only decides whether the alert recovers, and its results aren't available to the template. To show other values in recovery notifications, use a [related query](#recovery-related-query).
130
+
131
+
<Note>
132
+
When there are multiple values, `$value` is 0. When a rule has multiple queries or a query returns multiple value fields, read values by key with `getvalue $values "<key>"`.
With the first two recovery modes, branch on `$status` in the template and reference the same key. In this example, main query A returns CPU usage:
138
+
139
+
```gotemplate
140
+
{{- if eq $status "firing" }}
141
+
CPU usage {{ getvalue $values "$A" "%.1f" }}% exceeds the threshold.
142
+
{{- else }}
143
+
Recovered. Current CPU usage {{ getvalue $values "$A" "%.1f" }}%.
144
+
{{- end }}
145
+
```
146
+
147
+
<spanid="recovery-related-query"></span>
148
+
### Data exists: get values at recovery time with a related query
149
+
150
+
With **Recover if no data**, the recovering check finds no data, so `$values` only has the values from the most recent notification. To show values at recovery time, use a related query: related queries run every time a notification is sent, including recovery notifications, regardless of the check mode and recovery mode. Query the values you want to show, then reference them in the template through `$relates`.
151
+
152
+
Related query results from SQL data sources are returned as text, so read them with `$row.Field "<column name>"`.
153
+
154
+
Related query example: the main query detects error logs by `service`, and related query R1 counts errors in the last 5 minutes.
155
+
156
+
```sql
157
+
SELECTcount(*) AS cnt
158
+
FROM app_logs
159
+
WHERE level ='ERROR'
160
+
AND service ='${service}'
161
+
AND ts > now() - INTERVAL 5 MINUTE
162
+
```
163
+
164
+
```gotemplate
165
+
{{- if eq $status "firing" }}
166
+
Service {{ index $labels "service" }} has error logs.
167
+
{{- else }}
168
+
Service {{ index $labels "service" }} recovered. Errors in the last 5 minutes:
169
+
{{- range $row := $relates.R1 }} {{ $row.Field "cnt" }}{{ end }}
170
+
{{- end }}
171
+
```
172
+
114
173
## Go template built-in functions
115
174
116
175
These functions are provided by Go `text/template`.
Copy file name to clipboardExpand all lines: en/monitors/alert-rules/mysql.mdx
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ Monitors supports using standard SQL syntax to query MySQL and trigger alerts ba
13
13
|**Field Processing**| All field names are automatically converted to lowercase; please use lowercase letters when configuring |
14
14
|**Time Processing**| Recommended to use `now()`, `unix_timestamp()` and other functions for time filtering |
15
15
16
-
Unlike the other SQL data sources, MySQL alert SQL must be fully determined when saved: the query, related queries, and recovery queries cannot use the `${label_name}`placeholder or a `{{ $labels.<label_name> }}` template, or the rule cannot be saved.
16
+
Related queries and recovery queries support the `${label_name}`variable and the Go template `{{ $labels.<label_name> }}`, which require alert engine `v0.76.0`or later. After substituting variables, the alert engine checks that the SQL is a read-only query; if it isn't, that query run fails. The main query doesn't support variables.
17
17
18
18
## Threshold evaluation mode
19
19
@@ -45,7 +45,7 @@ Monitors distinguishes alert objects by their label fields and evaluates thresho
45
45
46
46
### Recovery logic
47
47
48
-
See [Alert recovery](/en/monitors/quickstart/quickstart#alert-recovery) for the recovery options. A recovery query must also be fully determined and cannot use runtime variables.
48
+
See [Alert recovery](/en/monitors/quickstart/quickstart#alert-recovery) for the recovery options. A recovery query is a separate SQL statement that supports the `${label_name}` variable and the Go template `{{ $labels.<label_name> }}` (requires alert engine `v0.76.0` or later).
Copy file name to clipboardExpand all lines: en/monitors/faq/faq.mdx
+9Lines changed: 9 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -56,4 +56,13 @@ If the preview fails, common causes are:
56
56
<Accordionid="notes-format"title="What format does the alert rule notes description support?">
57
57
The notes description supports Markdown format. You can use headings, lists, links, code blocks, and other Markdown syntax to organize content. It also supports variable references, which embed dynamic values such as alert event labels and query results into the notes. Responders can understand the alert context quickly.
58
58
</Accordion>
59
+
60
+
<Accordionid="recovery-values"title="How do I show values at recovery time in recovery notifications?">
61
+
Recovery notifications render the description again. Use `{{ if eq $status "recovered" }}` in the template to tell recovery notifications apart.
62
+
63
+
-**Threshold evaluation**: with **Recovery when no thresholds are triggered** or **Recovery only when conditions are met**, `$values` holds the values at recovery time.
64
+
-**Data exists**: with **Recover if no data**, the query finds no data at recovery, so `$values` holds the values from the most recent notification. To show values at recovery time, use a related query.
65
+
66
+
For syntax and examples, see [Show values at recovery time in recovery notifications](/en/monitors/alert-rules/description-template#recovery-values).
0 commit comments