Skip to content

Commit

Permalink
Rework postgres_mixin dashboard
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
sysadmind committed Sep 13, 2023
1 parent 31ef4ed commit 5d10f23
Show file tree
Hide file tree
Showing 11 changed files with 367 additions and 1,414 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
/.metrics.*.removed
/tools/src
/vendor
vendor/
3 changes: 3 additions & 0 deletions postgres_mixin/config.libsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
_config+:: {
postgresExporterSelector: '',

dashboardNamePrefix: 'Postgres Exporter / ',
dashboardTags: ['postgres-exporter-mixin'],
},
}
3 changes: 3 additions & 0 deletions postgres_mixin/dashboards.jsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
local dashboards = (import 'mixin.libsonnet').grafanaDashboards;

{ [name]: dashboards[name] for name in std.objectFields(dashboards)}
40 changes: 38 additions & 2 deletions postgres_mixin/dashboards/dashboards.libsonnet
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
local g = import 'g.libsonnet';

local dashboard = g.dashboard;
local row = g.panel.row;

local panels = import './panels.libsonnet';
local variables = import './variables.libsonnet';
local queries = import './queries.libsonnet';

// import config
local c = import '../config.libsonnet';

{
grafanaDashboards+:: {
'postgres-overview.json': (import 'postgres-overview.json'),
},
'overview.json':
dashboard.new('%s Overview' % $._config.dashboardNamePrefix)
+ dashboard.withTags($._config.dashboardTags)
+ dashboard.withRefresh('1m')
+ dashboard.time.withFrom(value='now-1h')
+ dashboard.graphTooltip.withSharedCrosshair()
+ dashboard.withVariables([
variables.datasource,
])
+ dashboard.withPanels(
g.util.grid.makeGrid([
row.new('Overview')
+ row.withPanels([
panels.stat.qps('QPS', queries.qps),
panels.timeSeries.ratio1('Cache Hit Ratio', queries.cacheHitRatio),
panels.timeSeries.base('Active Connections', queries.activeConnections)
]),
row.new('server')
+ row.withPanels([
panels.timeSeries.base('Conflicts/Deadlocks', [queries.conflicts, queries.deadlocks]),
panels.timeSeries.base('Buffers', [queries.buffersAlloc, queries.buffersBackendFsync, queries.buffersBackend, queries.buffersClean, queries.buffersCheckpoint]),
panels.timeSeries.base('Rows', [queries.databaseTupFetched, queries.databaseTupReturned, queries.databaseTupInserted, queries.databaseTupUpdated, queries.databaseTupDeleted]),
]),
])
)
}
}
1 change: 1 addition & 0 deletions postgres_mixin/dashboards/g.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'github.com/grafana/grafonnet/gen/grafonnet-latest/main.libsonnet'
30 changes: 30 additions & 0 deletions postgres_mixin/dashboards/panels.libsonnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
local g = import 'g.libsonnet';

{
stat: {
local stat = g.panel.stat,

base(title, targets):
stat.new(title)
+stat.queryOptions.withTargets(targets),

qps: self.base,
},

timeSeries: {
local timeSeries = g.panel.timeSeries,

base(title, targets):
timeSeries.new(title)
+timeSeries.queryOptions.withTargets(targets),

ratio(title, targets):
self.base(title, targets)
+ timeSeries.standardOptions.withUnit('percentunit'),

ratio1(title, targets):
self.ratio(title, targets)
+ timeSeries.standardOptions.withUnit('percentunit')
+ timeSeries.standardOptions.withMax(1)
}
}
Loading

0 comments on commit 5d10f23

Please sign in to comment.