mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 03:32:11 +08:00

Initial support for alerting with SQL expressions - When `format` is set to `alerting`, SQL expressions output in a format suitable for alerting evaluation. - Outstanding TODOs: - Deduplicate output rows - Add more tests - Fix broken alerting UI rendering (likely due to shape change to undocumented full-long format) - Basic usage: - SQL must return one numeric column and one or more string columns. - Each row may become an alert. - The alert fires if the numeric value is non-zero. - String columns are treated as labels. --------- Co-authored-by: Konrad Lalik <konradlalik@gmail.com> Co-authored-by: Tom Ratcliffe <tom.ratcliffe@grafana.com> Co-authored-by: Sam Jewell <sam.jewell@grafana.com>
148 lines
2.9 KiB
JSON
148 lines
2.9 KiB
JSON
{
|
|
"from": "now-1h",
|
|
"to": "now",
|
|
"queries": [
|
|
{
|
|
"refId": "A",
|
|
"maxDataPoints": 1000,
|
|
"intervalMs": 5,
|
|
"expression": "$A + 10",
|
|
"type": "math"
|
|
},
|
|
{
|
|
"refId": "B",
|
|
"maxDataPoints": 1000,
|
|
"intervalMs": 5,
|
|
"expression": "$A - $B",
|
|
"type": "math"
|
|
},
|
|
{
|
|
"refId": "C",
|
|
"maxDataPoints": 1000,
|
|
"intervalMs": 5,
|
|
"expression": "$A",
|
|
"reducer": "max",
|
|
"settings": {
|
|
"mode": "dropNN"
|
|
},
|
|
"type": "reduce"
|
|
},
|
|
{
|
|
"refId": "D",
|
|
"maxDataPoints": 1000,
|
|
"intervalMs": 5,
|
|
"downsampler": "last",
|
|
"expression": "$A",
|
|
"type": "resample",
|
|
"upsampler": "pad",
|
|
"window": "1d"
|
|
},
|
|
{
|
|
"refId": "E",
|
|
"maxDataPoints": 1000,
|
|
"intervalMs": 5,
|
|
"conditions": [
|
|
{
|
|
"evaluator": {
|
|
"params": [
|
|
5
|
|
],
|
|
"type": "gt"
|
|
},
|
|
"operator": {
|
|
"type": "and"
|
|
},
|
|
"query": {
|
|
"params": [
|
|
"A"
|
|
]
|
|
},
|
|
"reducer": {
|
|
"type": "max"
|
|
}
|
|
}
|
|
],
|
|
"type": "classic_conditions"
|
|
},
|
|
{
|
|
"refId": "F",
|
|
"maxDataPoints": 1000,
|
|
"intervalMs": 5,
|
|
"conditions": [
|
|
{
|
|
"evaluator": {
|
|
"params": [
|
|
5
|
|
],
|
|
"type": "gt"
|
|
}
|
|
}
|
|
],
|
|
"expression": "A",
|
|
"type": "threshold"
|
|
},
|
|
{
|
|
"refId": "G",
|
|
"maxDataPoints": 1000,
|
|
"intervalMs": 5,
|
|
"conditions": [
|
|
{
|
|
"evaluator": {
|
|
"params": [
|
|
100
|
|
],
|
|
"type": "gt"
|
|
},
|
|
"loadedDimensions": {
|
|
"data": {
|
|
"values": [
|
|
[
|
|
18446744073709552000,
|
|
2,
|
|
3,
|
|
4,
|
|
5
|
|
]
|
|
]
|
|
},
|
|
"schema": {
|
|
"fields": [
|
|
{
|
|
"name": "fingerprints",
|
|
"type": "number",
|
|
"typeInfo": {
|
|
"frame": "uint64"
|
|
}
|
|
}
|
|
],
|
|
"meta": {
|
|
"type": "fingerprints",
|
|
"typeVersion": [
|
|
1,
|
|
0
|
|
]
|
|
},
|
|
"name": "test"
|
|
}
|
|
},
|
|
"unloadEvaluator": {
|
|
"params": [
|
|
31
|
|
],
|
|
"type": "lt"
|
|
}
|
|
}
|
|
],
|
|
"expression": "B",
|
|
"type": "threshold"
|
|
},
|
|
{
|
|
"refId": "H",
|
|
"maxDataPoints": 1000,
|
|
"intervalMs": 5,
|
|
"expression": "SELECT * FROM A limit 1",
|
|
"format": "",
|
|
"type": "sql"
|
|
}
|
|
]
|
|
} |