Skip to content

Commit 59c4b1f

Browse files
0xgoudapashagolub
andauthored
[+] add Total index size panel to Health Check dashboard (#1115)
* Add `indexes_size_b` column to `db_size` metric The column returns the total index size aggregated from `pg_stat_user_indexes` * Add `Total index size` panel to `Health Check` dashboard * Maintain styling for metric query Co-authored-by: Pavlo Golub <[email protected]> --------- Co-authored-by: Pavlo Golub <[email protected]>
1 parent 1122464 commit 59c4b1f

File tree

2 files changed

+86
-10
lines changed

2 files changed

+86
-10
lines changed

grafana/postgres/v12/0-health-check.json

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5115,24 +5115,97 @@
51155115
"type": "stat"
51165116
},
51175117
{
5118+
"datasource": {
5119+
"type": "grafana-postgresql-datasource",
5120+
"uid": "pgwatch-metrics"
5121+
},
5122+
"description": "Total size of user indexes for the selected DB. requires db_size metric.",
51185123
"fieldConfig": {
5119-
"defaults": {},
5124+
"defaults": {
5125+
"decimals": 1,
5126+
"mappings": [],
5127+
"thresholds": {},
5128+
"unit": "bytes"
5129+
},
51205130
"overrides": []
51215131
},
51225132
"gridPos": {
51235133
"h": 2,
5124-
"w": 12,
5134+
"w": 6,
51255135
"x": 12,
51265136
"y": 18
51275137
},
5128-
"id": 48,
5138+
"id": 51,
5139+
"maxDataPoints": 100,
5140+
"options": {
5141+
"colorMode": "none",
5142+
"graphMode": "none",
5143+
"justifyMode": "auto",
5144+
"orientation": "horizontal",
5145+
"percentChangeColorMode": "standard",
5146+
"reduceOptions": {
5147+
"calcs": [],
5148+
"fields": "",
5149+
"values": false
5150+
},
5151+
"showPercentChange": false,
5152+
"textMode": "auto",
5153+
"wideLayout": true
5154+
},
5155+
"pluginVersion": "12.1.0",
5156+
"targets": [
5157+
{
5158+
"datasource": {
5159+
"type": "grafana-postgresql-datasource",
5160+
"uid": "pgwatch-metrics"
5161+
},
5162+
"editorMode": "code",
5163+
"format": "table",
5164+
"group": [],
5165+
"groupBy": [],
5166+
"measurement": "db_size",
5167+
"metricColumn": "none",
5168+
"orderByTime": "ASC",
5169+
"policy": "default",
5170+
"rawQuery": true,
5171+
"rawSql": "SELECT\n (data->>'indexes_size_b')::int8\nFROM\n db_size\nWHERE\n $__timeFilter(time)\n AND dbname = '$dbname'\nORDER BY time DESC\nLIMIT 1",
5172+
"refId": "A",
5173+
"resultFormat": "time_series",
5174+
"select": [],
5175+
"sql": {},
5176+
"tags": [],
5177+
"timeColumn": "time",
5178+
"where": [
5179+
{
5180+
"name": "$__timeFilter",
5181+
"params": [],
5182+
"type": "macro"
5183+
}
5184+
]
5185+
}
5186+
],
5187+
"title": "Total index size",
5188+
"type": "stat"
5189+
},
5190+
{
5191+
"fieldConfig": {
5192+
"defaults": {},
5193+
"overrides": []
5194+
},
5195+
"gridPos": {
5196+
"h": 7,
5197+
"w": 12,
5198+
"x": 0,
5199+
"y": 20
5200+
},
5201+
"id": 12,
51295202
"options": {
51305203
"code": {
51315204
"language": "plaintext",
51325205
"showLineNumbers": false,
51335206
"showMiniMap": false
51345207
},
5135-
"content": "### The preset threshold values (green / yellow / red) should be reviewed / adjusted!",
5208+
"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",
51365209
"mode": "markdown"
51375210
},
51385211
"pluginVersion": "12.1.0",
@@ -5146,19 +5219,19 @@
51465219
"overrides": []
51475220
},
51485221
"gridPos": {
5149-
"h": 7,
5222+
"h": 2,
51505223
"w": 12,
5151-
"x": 0,
5224+
"x": 12,
51525225
"y": 20
51535226
},
5154-
"id": 12,
5227+
"id": 48,
51555228
"options": {
51565229
"code": {
51575230
"language": "plaintext",
51585231
"showLineNumbers": false,
51595232
"showMiniMap": false
51605233
},
5161-
"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",
5234+
"content": "### The preset threshold values (green / yellow / red) should be reviewed / adjusted!",
51625235
"mode": "markdown"
51635236
},
51645237
"pluginVersion": "12.1.0",

internal/metrics/metrics.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,8 @@ metrics:
447447
node_status: standby
448448
db_size:
449449
description: >
450-
Retrieves the size of the current database and the size of the `pg_catalog` schema, providing insights into the storage usage of the database.
450+
Retrieves the size of the current database, the size of the `pg_catalog` schema, and total indexes size
451+
providing insights into the storage usage of the database.
451452
It returns the size in bytes for both the current database and the catalog schema.
452453
This metric helps administrators monitor database size and storage consumption.
453454
sqls:
@@ -458,7 +459,9 @@ metrics:
458459
(select sum(pg_total_relation_size(c.oid))::int8
459460
from pg_class c join pg_namespace n on n.oid = c.relnamespace
460461
where nspname = 'pg_catalog' and relkind = 'r'
461-
) as catalog_size_b
462+
) as catalog_size_b,
463+
(select sum(pg_relation_size(indexrelid))::int8
464+
from pg_stat_user_indexes) as indexes_size_b
462465
gauges:
463466
- '*'
464467
statement_timeout_seconds: 300

0 commit comments

Comments
 (0)