Skip to content

Commit 5d10f23

Browse files
committed
Rework postgres_mixin dashboard
Rework the postgres_mixing dashboard to be more composable. The goal is for this to be more maintainable long term. I don't know jsonnet very well, but following other projects, this appears to be in line. This replaces the postgres-overview.json dashboard with an overview.json dashboard with the same panels. While the dashboard does not match perfectly, it does include the same data but with the correct metrics. Signed-off-by: Joe Adams <[email protected]>
1 parent 31ef4ed commit 5d10f23

11 files changed

+367
-1414
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
/.metrics.*.removed
2121
/tools/src
2222
/vendor
23+
vendor/

postgres_mixin/config.libsonnet

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
_config+:: {
33
postgresExporterSelector: '',
4+
5+
dashboardNamePrefix: 'Postgres Exporter / ',
6+
dashboardTags: ['postgres-exporter-mixin'],
47
},
58
}

postgres_mixin/dashboards.jsonnet

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
local dashboards = (import 'mixin.libsonnet').grafanaDashboards;
2+
3+
{ [name]: dashboards[name] for name in std.objectFields(dashboards)}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
1+
local g = import 'g.libsonnet';
2+
3+
local dashboard = g.dashboard;
4+
local row = g.panel.row;
5+
6+
local panels = import './panels.libsonnet';
7+
local variables = import './variables.libsonnet';
8+
local queries = import './queries.libsonnet';
9+
10+
// import config
11+
local c = import '../config.libsonnet';
12+
113
{
214
grafanaDashboards+:: {
3-
'postgres-overview.json': (import 'postgres-overview.json'),
4-
},
15+
'overview.json':
16+
dashboard.new('%s Overview' % $._config.dashboardNamePrefix)
17+
+ dashboard.withTags($._config.dashboardTags)
18+
+ dashboard.withRefresh('1m')
19+
+ dashboard.time.withFrom(value='now-1h')
20+
+ dashboard.graphTooltip.withSharedCrosshair()
21+
+ dashboard.withVariables([
22+
variables.datasource,
23+
])
24+
+ dashboard.withPanels(
25+
g.util.grid.makeGrid([
26+
row.new('Overview')
27+
+ row.withPanels([
28+
panels.stat.qps('QPS', queries.qps),
29+
panels.timeSeries.ratio1('Cache Hit Ratio', queries.cacheHitRatio),
30+
panels.timeSeries.base('Active Connections', queries.activeConnections)
31+
]),
32+
row.new('server')
33+
+ row.withPanels([
34+
panels.timeSeries.base('Conflicts/Deadlocks', [queries.conflicts, queries.deadlocks]),
35+
panels.timeSeries.base('Buffers', [queries.buffersAlloc, queries.buffersBackendFsync, queries.buffersBackend, queries.buffersClean, queries.buffersCheckpoint]),
36+
panels.timeSeries.base('Rows', [queries.databaseTupFetched, queries.databaseTupReturned, queries.databaseTupInserted, queries.databaseTupUpdated, queries.databaseTupDeleted]),
37+
]),
38+
])
39+
)
40+
}
541
}

postgres_mixin/dashboards/g.libsonnet

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'github.com/grafana/grafonnet/gen/grafonnet-latest/main.libsonnet'
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
local g = import 'g.libsonnet';
2+
3+
{
4+
stat: {
5+
local stat = g.panel.stat,
6+
7+
base(title, targets):
8+
stat.new(title)
9+
+stat.queryOptions.withTargets(targets),
10+
11+
qps: self.base,
12+
},
13+
14+
timeSeries: {
15+
local timeSeries = g.panel.timeSeries,
16+
17+
base(title, targets):
18+
timeSeries.new(title)
19+
+timeSeries.queryOptions.withTargets(targets),
20+
21+
ratio(title, targets):
22+
self.base(title, targets)
23+
+ timeSeries.standardOptions.withUnit('percentunit'),
24+
25+
ratio1(title, targets):
26+
self.ratio(title, targets)
27+
+ timeSeries.standardOptions.withUnit('percentunit')
28+
+ timeSeries.standardOptions.withMax(1)
29+
}
30+
}

0 commit comments

Comments
 (0)