Skip to content

Commit f3fae8a

Browse files
Merge remote-tracking branch 'origin/main' into add-table-bloat
2 parents 5ee3b87 + c60f55d commit f3fae8a

File tree

2 files changed

+287
-1
lines changed

2 files changed

+287
-1
lines changed
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
{
2+
"annotations": {
3+
"list": [
4+
{
5+
"builtIn": 1,
6+
"datasource": {
7+
"type": "grafana",
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": 10,
22+
"links": [],
23+
"panels": [
24+
{
25+
"datasource": {
26+
"type": "prometheus",
27+
"uid": "P7A0D6631BB10B34F"
28+
},
29+
"fieldConfig": {
30+
"defaults": {
31+
"color": {
32+
"mode": "palette-classic"
33+
},
34+
"custom": {
35+
"axisBorderShow": false,
36+
"axisCenteredZero": false,
37+
"axisColorMode": "text",
38+
"axisLabel": "",
39+
"axisPlacement": "auto",
40+
"barAlignment": 0,
41+
"barWidthFactor": 0.6,
42+
"drawStyle": "line",
43+
"fillOpacity": 0,
44+
"gradientMode": "none",
45+
"hideFrom": {
46+
"legend": false,
47+
"tooltip": false,
48+
"viz": false
49+
},
50+
"insertNulls": false,
51+
"lineInterpolation": "linear",
52+
"lineWidth": 1,
53+
"pointSize": 1,
54+
"scaleDistribution": {
55+
"type": "linear"
56+
},
57+
"showPoints": "auto",
58+
"spanNulls": false,
59+
"stacking": {
60+
"group": "A",
61+
"mode": "none"
62+
},
63+
"thresholdsStyle": {
64+
"mode": "off"
65+
}
66+
},
67+
"mappings": [],
68+
"thresholds": {
69+
"mode": "absolute",
70+
"steps": [
71+
{
72+
"color": "green"
73+
},
74+
{
75+
"color": "red",
76+
"value": 80
77+
}
78+
]
79+
}
80+
},
81+
"overrides": [
82+
{
83+
"matcher": {
84+
"id": "byName",
85+
"options": "Baseline Boguk ratio"
86+
},
87+
"properties": [
88+
{
89+
"id": "custom.lineStyle",
90+
"value": {
91+
"dash": [
92+
10,
93+
10
94+
],
95+
"fill": "dash"
96+
}
97+
},
98+
{
99+
"id": "color",
100+
"value": {
101+
"fixedColor": "dark-red",
102+
"mode": "fixed"
103+
}
104+
}
105+
]
106+
},
107+
{
108+
"matcher": {
109+
"id": "byName",
110+
"options": "Boguk ratio"
111+
},
112+
"properties": [
113+
{
114+
"id": "color",
115+
"value": {
116+
"fixedColor": "green",
117+
"mode": "fixed"
118+
}
119+
}
120+
]
121+
}
122+
]
123+
},
124+
"gridPos": {
125+
"h": 18,
126+
"w": 24,
127+
"x": 0,
128+
"y": 0
129+
},
130+
"id": 1,
131+
"options": {
132+
"legend": {
133+
"calcs": [],
134+
"displayMode": "table",
135+
"placement": "bottom",
136+
"showLegend": true
137+
},
138+
"tooltip": {
139+
"hideZeros": false,
140+
"mode": "single",
141+
"sort": "none"
142+
}
143+
},
144+
"pluginVersion": "12.0.2",
145+
"targets": [
146+
{
147+
"datasource": {
148+
"type": "prometheus",
149+
"uid": "P7A0D6631BB10B34F"
150+
},
151+
"disableTextWrap": false,
152+
"editorMode": "code",
153+
"expr": "pgwatch_pg_class_total_relation_size_bytes{relname=\"$index_name\", schemaname=\"$schema_name\"} / pgwatch_pg_class_reltuples{relname=\"$index_name\", schemaname=\"$schema_name\"}",
154+
"fullMetaSearch": false,
155+
"includeNullMetadata": true,
156+
"interval": "",
157+
"legendFormat": "Current Boguk ratio",
158+
"range": true,
159+
"refId": "A",
160+
"useBackend": false
161+
},
162+
{
163+
"datasource": {
164+
"type": "prometheus",
165+
"uid": "P7A0D6631BB10B34F"
166+
},
167+
"editorMode": "code",
168+
"expr": "pgwatch_pg_index_pilot_best_ratio{indexrelname=\"$index_name\", schemaname=\"$schema_name\"}",
169+
"hide": false,
170+
"instant": false,
171+
"legendFormat": "Baseline Boguk ratio",
172+
"range": true,
173+
"refId": "B"
174+
}
175+
],
176+
"title": "",
177+
"type": "timeseries"
178+
}
179+
],
180+
"preload": false,
181+
"schemaVersion": 41,
182+
"tags": [],
183+
"templating": {
184+
"list": [
185+
{
186+
"current": {
187+
"text": "test_pilot",
188+
"value": "test_pilot"
189+
},
190+
"definition": "label_values(pgwatch_pg_index_pilot_estimated_tuples,schemaname)",
191+
"name": "schema_name",
192+
"options": [],
193+
"query": {
194+
"qryType": 1,
195+
"query": "label_values(pgwatch_pg_index_pilot_estimated_tuples,schemaname)",
196+
"refId": "PrometheusVariableQueryEditor-VariableQuery"
197+
},
198+
"refresh": 1,
199+
"regex": "",
200+
"type": "query"
201+
},
202+
{
203+
"current": {
204+
"text": "",
205+
"value": ""
206+
},
207+
"definition": "label_values(pgwatch_pg_index_pilot_estimated_tuples{schemaname=\"$schema_name\"},indexrelname)",
208+
"name": "index_name",
209+
"options": [],
210+
"query": {
211+
"qryType": 1,
212+
"query": "label_values(pgwatch_pg_index_pilot_estimated_tuples{schemaname=\"$schema_name\"},indexrelname)",
213+
"refId": "PrometheusVariableQueryEditor-VariableQuery"
214+
},
215+
"refresh": 1,
216+
"regex": "",
217+
"type": "query"
218+
}
219+
]
220+
},
221+
"time": {
222+
"from": "now-1h",
223+
"to": "now"
224+
},
225+
"timepicker": {},
226+
"timezone": "browser",
227+
"title": "10. Single index analysis",
228+
"uid": "aa0128c5-c5a0-4418-a99e-c941af10426e",
229+
"version": 6
230+
}

config/pgwatch-prometheus/metrics.yml

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,33 @@ metrics:
966966
- wal_bytes
967967
- temp_bytes_read
968968
- temp_bytes_written
969+
pg_class:
970+
description: >
971+
Direct access to pg_class system catalog data for all relations (tables, indexes, etc).
972+
Provides reltuples, relpages, and other pg_class columns with relname and schemaname
973+
as tags for easy filtering and querying.
974+
sqls:
975+
11: |
976+
select
977+
current_database() as tag_datname,
978+
n.nspname as tag_schemaname,
979+
c.relname as tag_relname,
980+
c.relkind as tag_relkind,
981+
c.reltuples,
982+
c.relpages,
983+
pg_relation_size(c.oid) as relation_size_bytes,
984+
pg_total_relation_size(c.oid) as total_relation_size_bytes
985+
from pg_class c
986+
join pg_namespace n on n.oid = c.relnamespace
987+
where n.nspname not in ('information_schema', 'pg_catalog')
988+
and c.relkind in ('r', 'i', 'm', 'v') -- tables, indexes, materialized views, views
989+
order by pg_total_relation_size(c.oid) desc
990+
limit 10000
991+
gauges:
992+
- reltuples
993+
- relpages
994+
- relation_size_bytes
995+
- total_relation_size_bytes
969996
pg_stat_user_indexes:
970997
sqls:
971998
11: |
@@ -1208,6 +1235,7 @@ metrics:
12081235
- bloat_size
12091236
- bloat_pct
12101237
- is_na
1238+
- reltuples
12111239

12121240
pg_table_bloat:
12131241
description: >
@@ -1285,6 +1313,7 @@ metrics:
12851313
- bloat_size
12861314
- bloat_pct
12871315
- is_na
1316+
- reltuples
12881317
statement_timeout_seconds: 300
12891318
pg_invalid_indexes:
12901319
description: >
@@ -1912,6 +1941,29 @@ metrics:
19121941
join pg_namespace N on (N.oid = C.relnamespace)
19131942
gauges:
19141943
- '*'
1944+
pg_index_pilot:
1945+
sqls:
1946+
11: |
1947+
select
1948+
(extract(epoch from now()) * 1e9)::int8 as epoch_ns,
1949+
current_database() as tag_datname,
1950+
database_name as tag_database_name,
1951+
datname as tag_datname,
1952+
schemaname as tag_schemaname,
1953+
relname as tag_relname,
1954+
indexrelname as tag_indexrelname,
1955+
indexsize as index_size_bytes,
1956+
indisvalid::int as is_valid,
1957+
estimated_tuples,
1958+
best_ratio
1959+
from index_pilot.index_current_state
1960+
order by indexsize desc
1961+
limit 2000;
1962+
gauges:
1963+
- index_size_bytes
1964+
- is_valid
1965+
- estimated_tuples
1966+
- best_ratio
19151967

19161968
presets:
19171969
full:
@@ -1932,6 +1984,7 @@ presets:
19321984
pg_stat_wal_receiver: 30
19331985
pg_archiver: 30
19341986
pg_stat_user_tables: 30
1987+
pg_class: 30
19351988
pg_stat_user_indexes: 30
19361989
pg_stat_statements: 30
19371990
pg_stat_replication: 30
@@ -1949,4 +2002,7 @@ presets:
19492002
unused_indexes: 7200
19502003
rarely_used_indexes: 10800
19512004
archive_lag: 15
1952-
pg_vacuum_progress: 30
2005+
pg_vacuum_progress: 30
2006+
pg_index_pilot:
2007+
metrics:
2008+
pg_index_pilot: 30

0 commit comments

Comments
 (0)