Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c485196

Browse files
committedSep 13, 2023
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 0b6d986 commit c485196

11 files changed

+367
-1414
lines changed
 

‎.gitignore

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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)}
Lines changed: 38 additions & 2 deletions
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import 'github.com/grafana/grafonnet/gen/grafonnet-latest/main.libsonnet'
Lines changed: 30 additions & 0 deletions
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+
}

‎postgres_mixin/dashboards/postgres-overview.json

Lines changed: 0 additions & 1412 deletions
This file was deleted.
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
local g = import './g.libsonnet';
2+
local prometheusQuery = g.query.prometheus;
3+
4+
local variables = import './variables.libsonnet';
5+
6+
{
7+
/*
8+
General overview queries
9+
*/
10+
11+
qps:
12+
prometheusQuery.new(
13+
'$' + variables.datasource.name,
14+
|||
15+
sum(
16+
irate(
17+
pg_stat_database_xact_commit{}[$__rate_interval]
18+
)
19+
)
20+
+
21+
sum(
22+
irate(
23+
pg_stat_database_xact_rollback{}[$__rate_interval]
24+
)
25+
)
26+
|||
27+
),
28+
29+
cacheHitRatio:
30+
prometheusQuery.new(
31+
'$' + variables.datasource.name,
32+
|||
33+
sum by (datname) (
34+
rate(
35+
pg_stat_database_blks_hit{}
36+
[$__rate_interval])
37+
) / (
38+
sum by (datname) (
39+
rate(
40+
pg_stat_database_blks_hit{}
41+
[$__rate_interval])
42+
) + sum by (datname) (
43+
rate(
44+
pg_stat_database_blks_read{}
45+
[$__rate_interval])
46+
)
47+
)
48+
|||
49+
)
50+
+ prometheusQuery.withLegendFormat(|||
51+
{{datname}}
52+
|||),
53+
54+
activeConnections:
55+
prometheusQuery.new(
56+
'$' + variables.datasource.name,
57+
|||
58+
pg_stat_database_numbackends{}
59+
|||
60+
)
61+
+ prometheusQuery.withLegendFormat(|||
62+
{{datname}}
63+
|||),
64+
65+
deadlocks:
66+
prometheusQuery.new(
67+
'$' + variables.datasource.name,
68+
|||
69+
sum(
70+
rate(
71+
pg_stat_database_deadlocks{}[$__rate_interval]
72+
)
73+
)
74+
|||
75+
)
76+
+ prometheusQuery.withLegendFormat(|||
77+
deadlocks
78+
|||),
79+
80+
conflicts:
81+
prometheusQuery.new(
82+
'$' + variables.datasource.name,
83+
|||
84+
sum(
85+
rate(
86+
pg_stat_database_conflicts{}[$__rate_interval]
87+
)
88+
)
89+
|||
90+
)
91+
+ prometheusQuery.withLegendFormat(|||
92+
conflicts
93+
|||),
94+
95+
/* ----------------------
96+
Buffers
97+
---------------------- */
98+
99+
buffersAlloc:
100+
prometheusQuery.new(
101+
'$' + variables.datasource.name,
102+
|||
103+
irate(
104+
pg_stat_bgwriter_buffers_alloc_total{}[$__rate_interval]
105+
)
106+
|||
107+
)
108+
+ prometheusQuery.withLegendFormat('allocated'),
109+
110+
buffersBackendFsync:
111+
prometheusQuery.new(
112+
'$' + variables.datasource.name,
113+
|||
114+
irate(
115+
pg_stat_bgwriter_buffers_backend_fsync_total{}[$__rate_interval]
116+
)
117+
|||
118+
)
119+
+ prometheusQuery.withLegendFormat('backend fsyncs'),
120+
121+
buffersBackend:
122+
prometheusQuery.new(
123+
'$' + variables.datasource.name,
124+
|||
125+
irate(
126+
pg_stat_bgwriter_buffers_backend_total{}[$__rate_interval]
127+
)
128+
|||
129+
)
130+
+ prometheusQuery.withLegendFormat('backend'),
131+
132+
buffersClean:
133+
prometheusQuery.new(
134+
'$' + variables.datasource.name,
135+
|||
136+
irate(
137+
pg_stat_bgwriter_buffers_clean_total{}[$__rate_interval]
138+
)
139+
|||
140+
)
141+
+ prometheusQuery.withLegendFormat('clean'),
142+
143+
buffersCheckpoint:
144+
prometheusQuery.new(
145+
'$' + variables.datasource.name,
146+
|||
147+
irate(
148+
pg_stat_bgwriter_buffers_checkpoint_total{}[$__rate_interval]
149+
)
150+
|||
151+
)
152+
+ prometheusQuery.withLegendFormat('checkpoint'),
153+
154+
/* ----------------------
155+
Database Tups
156+
---------------------- */
157+
158+
databaseTupFetched:
159+
prometheusQuery.new(
160+
'$' + variables.datasource.name,
161+
|||
162+
sum(
163+
irate(
164+
pg_stat_database_tup_fetched{}[$__rate_interval]
165+
)
166+
)
167+
|||
168+
)
169+
+ prometheusQuery.withLegendFormat('fetched'),
170+
171+
databaseTupReturned:
172+
prometheusQuery.new(
173+
'$' + variables.datasource.name,
174+
|||
175+
sum(
176+
irate(
177+
pg_stat_database_tup_returned{}[$__rate_interval]
178+
)
179+
)
180+
|||
181+
)
182+
+ prometheusQuery.withLegendFormat('returned'),
183+
184+
databaseTupInserted:
185+
prometheusQuery.new(
186+
'$' + variables.datasource.name,
187+
|||
188+
sum(
189+
irate(
190+
pg_stat_database_tup_inserted{}[$__rate_interval]
191+
)
192+
)
193+
|||
194+
)
195+
+ prometheusQuery.withLegendFormat('inserted'),
196+
197+
databaseTupUpdated:
198+
prometheusQuery.new(
199+
'$' + variables.datasource.name,
200+
|||
201+
sum(
202+
irate(
203+
pg_stat_database_tup_updated{}[$__rate_interval]
204+
)
205+
)
206+
|||
207+
)
208+
+ prometheusQuery.withLegendFormat('updated'),
209+
210+
databaseTupDeleted:
211+
prometheusQuery.new(
212+
'$' + variables.datasource.name,
213+
|||
214+
sum(
215+
irate(
216+
pg_stat_database_tup_deleted{}[$__rate_interval]
217+
)
218+
)
219+
|||
220+
)
221+
+ prometheusQuery.withLegendFormat('deleted'),
222+
223+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
local g = import './g.libsonnet';
2+
local var = g.dashboard.variable;
3+
4+
{
5+
datasource:
6+
var.datasource.new('datasource', 'prometheus')
7+
}

‎postgres_mixin/jsonnetfile.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": 1,
3+
"dependencies": [
4+
{
5+
"source": {
6+
"git": {
7+
"remote": "https://github.com/grafana/grafonnet.git",
8+
"subdir": "gen/grafonnet-latest"
9+
}
10+
},
11+
"version": "main"
12+
}
13+
],
14+
"legacyImports": true
15+
}

‎postgres_mixin/jsonnetfile.lock.json

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"version": 1,
3+
"dependencies": [
4+
{
5+
"source": {
6+
"git": {
7+
"remote": "https://github.com/grafana/grafonnet.git",
8+
"subdir": "gen/grafonnet-latest"
9+
}
10+
},
11+
"version": "f86c6b155b8ea527d36cd7194b2cb42dac437166",
12+
"sum": "sVzVlSLbxPkAurwO19YERigLMmRfVsViMcWC0gkTTqU="
13+
},
14+
{
15+
"source": {
16+
"git": {
17+
"remote": "https://github.com/grafana/grafonnet.git",
18+
"subdir": "gen/grafonnet-v10.0.0"
19+
}
20+
},
21+
"version": "f86c6b155b8ea527d36cd7194b2cb42dac437166",
22+
"sum": "brWLY/BpeCL2ThiWlLtLcs4KwgMvouGtPrKAagBnG8g="
23+
},
24+
{
25+
"source": {
26+
"git": {
27+
"remote": "https://github.com/jsonnet-libs/docsonnet.git",
28+
"subdir": "doc-util"
29+
}
30+
},
31+
"version": "7c865ec0606f2b68c0f6b2721f101e6a99cd2593",
32+
"sum": "zjjufxN4yAIevldYEERiZEp27vK0BJKj1VvZcVtWiOo="
33+
},
34+
{
35+
"source": {
36+
"git": {
37+
"remote": "https://github.com/jsonnet-libs/xtd.git",
38+
"subdir": ""
39+
}
40+
},
41+
"version": "0256a910ac71f0f842696d7bca0bf01ea77eb654",
42+
"sum": "zBOpb1oTNvXdq9RF6yzTHill5r1YTJLBBoqyx4JYtAg="
43+
}
44+
],
45+
"legacyImports": false
46+
}

0 commit comments

Comments
 (0)
Please sign in to comment.