Add alerts to graphs

Graphs can setup alerts.  Add a basic framework for them.

Change-Id: I6a80041eaaa03a3b3ff3e3de76401bbc77f42e96
This commit is contained in:
Ian Wienand 2018-06-12 13:04:25 +10:00
parent 59247628c4
commit c82c2b8ef7
3 changed files with 145 additions and 0 deletions

View File

@ -22,6 +22,19 @@ from grafana_dashboards.schema.panel.base import Base
class Graph(Base):
def get_schema(self):
alert_format = {
# could enforce "evaulator"/"operator"/"query" on this...
v.Required('conditions'): v.All(list),
v.Required('frequency', default='60s'): v.All(str),
v.Required('name'): v.All(str),
v.Required('executionErrorState', default='alerting'): (
v.Any('alerting', 'keep_state')),
v.Required('noDataState', default='no_data'): (
v.Any('no_data', 'alerting', 'ok', 'keep_state')),
v.Optional('notifications', default=[]): v.All(list),
}
yaxes_format = [
{
v.Optional('decimals'): v.All(int),
@ -76,6 +89,7 @@ class Graph(Base):
series_overrides = [series_override]
graph = {
v.Optional('alert'): v.All(alert_format),
v.Required('bars', default=False): v.All(bool),
v.Optional('datasource'): v.All(str),
v.Optional('decimals'): v.All(int),

View File

@ -0,0 +1,90 @@
{
"dashboard": {
"new-dashboard": {
"rows": [
{
"collapse": false,
"editable": true,
"height": "250px",
"panels": [
{
"alert": {
"conditions": [
{
"evaluator": {
"params": [
0.85
],
"type": "gt"
},
"operator": {
"type": "and"
},
"query": {
"params": [
"C",
"5m",
"now"
]
},
"reducer": {
"params": [],
"type": "avg"
},
"type": "query"
}
],
"executionErrorState": "alerting",
"frequency": "60s",
"name": "A test alert",
"noDataState": "no_data",
"notifications": []
},
"bars": false,
"datasource": "graphite",
"editable": true,
"error": false,
"fill": 1,
"lines": true,
"linewidth": 2,
"percentage": false,
"pointradius": 5,
"points": false,
"span": 12,
"stack": false,
"steppedLine": false,
"targets": [
{
"hide": true,
"refId": "A",
"target": "stats.gauges.afs.afs01_dfw_openstack_org.part.vicepa.total"
},
{
"hide": false,
"refId": "B",
"target": "divideSeries(stats.gauges.afs.afs01_dfw_openstack_org.part.vicpa.used, #A)"
}
],
"title": "no title (click here)",
"type": "graph",
"x-axis": true,
"y-axis": true
}
],
"showTitle": false,
"title": "New row"
}
],
"templating": {
"enabled": false,
"list": []
},
"time": {
"from": "2018-02-07T08:42:27.000Z",
"to": "2018-02-07T13:48:32.000Z"
},
"timezone": "utc",
"title": "New dashboard"
}
}
}

View File

@ -0,0 +1,41 @@
dashboard:
time:
from: "2018-02-07T08:42:27.000Z"
to: "2018-02-07T13:48:32.000Z"
title: New dashboard
rows:
- title: New row
height: 250px
panels:
- title: no title (click here)
type: graph
datasource: graphite
targets:
- target: "stats.gauges.afs.afs01_dfw_openstack_org.part.vicepa.total"
refId: "A"
hide: true
- target: "divideSeries(stats.gauges.afs.afs01_dfw_openstack_org.part.vicpa.used, #A)"
refId: "B"
hide: false
alert:
conditions:
- evaluator:
params:
- 0.85
type: gt
operator:
type: and
query:
params:
- C
- 5m
- now
reducer:
params: []
type: avg
type: query
executionErrorState: alerting
frequency: 60s
name: A test alert
noDataState: no_data