Last active
September 14, 2022 15:13
-
-
Save niels-s/55d00b7d3072d99ab7b277788031fce3 to your computer and use it in GitHub Desktop.
An example Grafana dashboard defined in Grafonnet with alerts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local grafana = import 'grafonnet/grafana.libsonnet'; | |
local influxdb = grafana.influxdb; | |
local graphPanel = grafana.graphPanel; | |
local alertCondition = grafana.alertCondition; | |
local dashboard = grafana.dashboard; | |
local warning_threshold = 644245094400; | |
local db_instances = [ | |
'db-1', | |
'db-2', | |
'...' | |
]; | |
local postgresqlAlertTimeseries( | |
db_instance, | |
threshold, | |
) = | |
graphPanel.new( | |
db_instance, | |
).addTarget( | |
influxdb.target( | |
measurement='disk-usage' | |
) | |
.where('server', '=', db_instance) | |
.selectField('available') | |
.addConverter('mean') | |
) | |
.resetYaxes() | |
.addYaxis( | |
decimals=1, | |
format='bytes' | |
) | |
.addYaxis( | |
format='short', | |
max=1, | |
min=0, | |
show=false, | |
).addAlert( | |
'Warning: ' + db_instance + ' disk usage alert', | |
notifications = [{id: 1}] | |
).addCondition( | |
alertCondition.new( | |
evaluatorType='lt', | |
evaluatorParams=[threshold], | |
operatorType='and', | |
reducerType='min', | |
queryRefId='A', | |
queryTimeStart='5m', | |
queryTimeEnd='now', | |
), | |
); | |
local generateDBPanel(db_instance) = | |
postgresqlAlertTimeseries(db_instance, warning_threshold) { | |
gridPos: { h: 6, w: 24, x: 0, y: 0 } | |
}; | |
dashboard.new( | |
'Postgresql Storage Warning Alerts', | |
uid='90C6DB2A-946C-446B-9D2B-8B1E03673F03', | |
style='dark', | |
tags=['postgresql','alerting'], | |
timezone='utc', | |
graphTooltip='shared_crosshair', | |
hideControls=false, | |
description='Configures storage alerts for DB servers at a warning level', | |
time_from='now-7d/m', | |
time_to='now/m', | |
).addPanels(std.map(generateDBPanel, db_instances)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment