Skip to content

Commit ab8ee13

Browse files
committed
[+] add Stat Statements [Top|Visual|Search] dashboards (#18)
1 parent 9c6d4ef commit ab8ee13

4 files changed

Lines changed: 3309 additions & 0 deletions

File tree

Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
1+
{
2+
"annotations": {
3+
"list": [
4+
{
5+
"builtIn": 1,
6+
"datasource": {
7+
"type": "datasource",
8+
"uid": "grafana"
9+
},
10+
"enable": true,
11+
"hide": true,
12+
"iconColor": "rgba(0, 211, 255, 1)",
13+
"name": "Annotations & Alerts",
14+
"type": "dashboard"
15+
}
16+
]
17+
},
18+
"editable": true,
19+
"fiscalYearStartMonth": 0,
20+
"graphTooltip": 0,
21+
"id": 5,
22+
"links": [],
23+
"panels": [
24+
{
25+
"datasource": {
26+
"type": "grafana-postgresql-datasource",
27+
"uid": "pgwatch-metrics"
28+
},
29+
"description": "",
30+
"fieldConfig": {
31+
"defaults": {
32+
"color": {
33+
"mode": "thresholds"
34+
},
35+
"custom": {
36+
"align": "auto",
37+
"cellOptions": {
38+
"type": "auto"
39+
},
40+
"inspect": false
41+
},
42+
"mappings": [],
43+
"thresholds": {
44+
"mode": "absolute",
45+
"steps": [
46+
{
47+
"color": "green"
48+
},
49+
{
50+
"color": "red",
51+
"value": 80
52+
}
53+
]
54+
}
55+
},
56+
"overrides": [
57+
{
58+
"matcher": {
59+
"id": "byRegexp",
60+
"options": "/time/"
61+
},
62+
"properties": [
63+
{
64+
"id": "unit",
65+
"value": "ms"
66+
},
67+
{
68+
"id": "decimals",
69+
"value": 2
70+
},
71+
{
72+
"id": "custom.align"
73+
}
74+
]
75+
},
76+
{
77+
"matcher": {
78+
"id": "byName",
79+
"options": "calls"
80+
},
81+
"properties": [
82+
{
83+
"id": "unit",
84+
"value": "short"
85+
},
86+
{
87+
"id": "custom.align"
88+
}
89+
]
90+
},
91+
{
92+
"matcher": {
93+
"id": "byRegexp",
94+
"options": "/queryid/"
95+
},
96+
"properties": [
97+
{
98+
"id": "unit",
99+
"value": "short"
100+
},
101+
{
102+
"id": "decimals",
103+
"value": 2
104+
},
105+
{
106+
"id": "links",
107+
"value": [
108+
{
109+
"targetBlank": true,
110+
"title": "Go to Query Details dash",
111+
"url": "/d/single-query-details?var-dbname=$dbname&var-queryid=$__cell"
112+
}
113+
]
114+
},
115+
{
116+
"id": "custom.align"
117+
}
118+
]
119+
},
120+
{
121+
"matcher": {
122+
"id": "byRegexp",
123+
"options": "/last_exec/"
124+
},
125+
"properties": [
126+
{
127+
"id": "unit",
128+
"value": "dtdurations"
129+
},
130+
{
131+
"id": "custom.align"
132+
}
133+
]
134+
}
135+
]
136+
},
137+
"gridPos": {
138+
"h": 16,
139+
"w": 24,
140+
"x": 0,
141+
"y": 0
142+
},
143+
"id": 2,
144+
"options": {
145+
"cellHeight": "sm",
146+
"footer": {
147+
"countRows": false,
148+
"fields": "",
149+
"reducer": [
150+
"sum"
151+
],
152+
"show": false
153+
},
154+
"showHeader": true
155+
},
156+
"pluginVersion": "12.0.0",
157+
"targets": [
158+
{
159+
"datasource": {
160+
"type": "grafana-postgresql-datasource",
161+
"uid": "pgwatch-metrics"
162+
},
163+
"format": "table",
164+
"group": [],
165+
"metricColumn": "none",
166+
"rawQuery": true,
167+
"rawSql": "SELECT\n total_time, mean_time, calls as total_calls, seconds_since_last_exec, queryid, query\nFROM (\n\nSELECT\n DISTINCT ON (queryid) queryid, time, total_time, mean_time, calls, query\nFROM (\n\nSELECT\n time, (data->>'total_time')::float as total_time, (data->>'total_time')::float / (data->>'calls')::int8 as mean_time, (data->>'calls')::int8 as calls, tag_data->>'queryid' as queryid, tag_data->>'query' as query\nFROM stat_statements\nWHERE\n dbname = '$dbname'\n AND time > now() - '$calls_interval'::interval\n AND tag_data->>'query' ~* '$sql_fragment'\n AND CASE WHEN length('$sql_fragment') > 2 THEN true ELSE false END\n) x\nORDER BY queryid, time DESC, mean_time, calls, query\n\n) y\nJOIN LATERAL \n (select (extract(epoch from now() - prev.time))::int8 as seconds_since_last_exec\n from stat_statements prev\n where dbname = '$dbname' and time > now() - '$calls_interval'::interval\n and prev.time < y.time and (prev.data->>'calls')::int8 != y.calls\n order by time desc limit 1\n) z on true\n\nORDER BY total_time DESC LIMIT 100",
168+
"refId": "A",
169+
"select": [
170+
[
171+
{
172+
"params": [
173+
"value"
174+
],
175+
"type": "column"
176+
}
177+
]
178+
],
179+
"timeColumn": "time",
180+
"where": [
181+
{
182+
"name": "$__timeFilter",
183+
"params": [],
184+
"type": "macro"
185+
}
186+
]
187+
}
188+
],
189+
"title": "Matching Queries",
190+
"transformations": [
191+
{
192+
"id": "merge",
193+
"options": {
194+
"reducers": []
195+
}
196+
}
197+
],
198+
"type": "table"
199+
},
200+
{
201+
"fieldConfig": {
202+
"defaults": {},
203+
"overrides": []
204+
},
205+
"gridPos": {
206+
"h": 5,
207+
"w": 24,
208+
"x": 0,
209+
"y": 16
210+
},
211+
"id": 4,
212+
"options": {
213+
"code": {
214+
"language": "plaintext",
215+
"showLineNumbers": false,
216+
"showMiniMap": false
217+
},
218+
"content": "### Brought to you by\n\n[![Cybertec – The PostgreSQL Database Company](https://www.cybertec-postgresql.com/wp-content/uploads/2025/02/cybertec-logo-white-blue.svg)](https://www.cybertec-postgresql.com/en/)\n",
219+
"mode": "markdown"
220+
},
221+
"pluginVersion": "12.0.0",
222+
"title": "",
223+
"transparent": true,
224+
"type": "text"
225+
}
226+
],
227+
"preload": false,
228+
"refresh": "",
229+
"schemaVersion": 41,
230+
"tags": [
231+
"pgwatch"
232+
],
233+
"templating": {
234+
"list": [
235+
{
236+
"datasource": {
237+
"type": "grafana-postgresql-datasource",
238+
"uid": "pgwatch-metrics"
239+
},
240+
"definition": "SELECT DISTINCT dbname FROM admin.all_distinct_dbname_metrics WHERE metric = 'stat_statements' ORDER BY 1;",
241+
"includeAll": false,
242+
"name": "dbname",
243+
"options": [],
244+
"query": "SELECT DISTINCT dbname FROM admin.all_distinct_dbname_metrics WHERE metric = 'stat_statements' ORDER BY 1;",
245+
"refresh": 1,
246+
"regex": "",
247+
"type": "query"
248+
},
249+
{
250+
"current": {
251+
"text": "",
252+
"value": ""
253+
},
254+
"label": "SQL search fragment (case insensitive, 3 char min.)",
255+
"name": "sql_fragment",
256+
"options": [
257+
{
258+
"selected": true,
259+
"text": "",
260+
"value": ""
261+
}
262+
],
263+
"query": "",
264+
"type": "textbox"
265+
},
266+
{
267+
"auto": false,
268+
"auto_count": 30,
269+
"auto_min": "10s",
270+
"current": {
271+
"text": "12h",
272+
"value": "12h"
273+
},
274+
"label": "Having some executions within last",
275+
"name": "calls_interval",
276+
"options": [
277+
{
278+
"selected": false,
279+
"text": "30m",
280+
"value": "30m"
281+
},
282+
{
283+
"selected": false,
284+
"text": "1h",
285+
"value": "1h"
286+
},
287+
{
288+
"selected": false,
289+
"text": "6h",
290+
"value": "6h"
291+
},
292+
{
293+
"selected": true,
294+
"text": "12h",
295+
"value": "12h"
296+
},
297+
{
298+
"selected": false,
299+
"text": "1d",
300+
"value": "1d"
301+
},
302+
{
303+
"selected": false,
304+
"text": "7d",
305+
"value": "7d"
306+
},
307+
{
308+
"selected": false,
309+
"text": "14d",
310+
"value": "14d"
311+
},
312+
{
313+
"selected": false,
314+
"text": "30d",
315+
"value": "30d"
316+
}
317+
],
318+
"query": "30m,1h,6h,12h,1d,7d,14d,30d",
319+
"refresh": 2,
320+
"type": "interval"
321+
}
322+
]
323+
},
324+
"time": {
325+
"from": "now-12h",
326+
"to": "now"
327+
},
328+
"timepicker": {},
329+
"timezone": "",
330+
"title": "Stat Statements SQL Search",
331+
"uid": "stat-statements-sql-search",
332+
"version": 1
333+
}

0 commit comments

Comments
 (0)