diff --git a/grafana/postgres/v12/0-health-check.json b/grafana/postgres/v12/0-health-check.json index cc1238ab0..2c77b5361 100644 --- a/grafana/postgres/v12/0-health-check.json +++ b/grafana/postgres/v12/0-health-check.json @@ -5115,24 +5115,97 @@ "type": "stat" }, { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "pgwatch-metrics" + }, + "description": "Total size of user indexes for the selected DB. requires db_size metric.", "fieldConfig": { - "defaults": {}, + "defaults": { + "decimals": 1, + "mappings": [], + "thresholds": {}, + "unit": "bytes" + }, "overrides": [] }, "gridPos": { "h": 2, - "w": 12, + "w": 6, "x": 12, "y": 18 }, - "id": 48, + "id": 51, + "maxDataPoints": 100, + "options": { + "colorMode": "none", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "horizontal", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "12.1.0", + "targets": [ + { + "datasource": { + "type": "grafana-postgresql-datasource", + "uid": "pgwatch-metrics" + }, + "editorMode": "code", + "format": "table", + "group": [], + "groupBy": [], + "measurement": "db_size", + "metricColumn": "none", + "orderByTime": "ASC", + "policy": "default", + "rawQuery": true, + "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", + "refId": "A", + "resultFormat": "time_series", + "select": [], + "sql": {}, + "tags": [], + "timeColumn": "time", + "where": [ + { + "name": "$__timeFilter", + "params": [], + "type": "macro" + } + ] + } + ], + "title": "Total index size", + "type": "stat" + }, + { + "fieldConfig": { + "defaults": {}, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 12, + "x": 0, + "y": 20 + }, + "id": 12, "options": { "code": { "language": "plaintext", "showLineNumbers": false, "showMiniMap": false }, - "content": "### The preset threshold values (green / yellow / red) should be reviewed / adjusted!", + "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", "mode": "markdown" }, "pluginVersion": "12.1.0", @@ -5146,19 +5219,19 @@ "overrides": [] }, "gridPos": { - "h": 7, + "h": 2, "w": 12, - "x": 0, + "x": 12, "y": 20 }, - "id": 12, + "id": 48, "options": { "code": { "language": "plaintext", "showLineNumbers": false, "showMiniMap": false }, - "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", + "content": "### The preset threshold values (green / yellow / red) should be reviewed / adjusted!", "mode": "markdown" }, "pluginVersion": "12.1.0", diff --git a/internal/metrics/metrics.yaml b/internal/metrics/metrics.yaml index 78a6f7cd5..0e36cd913 100644 --- a/internal/metrics/metrics.yaml +++ b/internal/metrics/metrics.yaml @@ -447,7 +447,8 @@ metrics: node_status: standby db_size: description: > - Retrieves the size of the current database and the size of the `pg_catalog` schema, providing insights into the storage usage of the database. + Retrieves the size of the current database, the size of the `pg_catalog` schema, and total indexes size + providing insights into the storage usage of the database. It returns the size in bytes for both the current database and the catalog schema. This metric helps administrators monitor database size and storage consumption. sqls: @@ -458,7 +459,9 @@ metrics: (select sum(pg_total_relation_size(c.oid))::int8 from pg_class c join pg_namespace n on n.oid = c.relnamespace where nspname = 'pg_catalog' and relkind = 'r' - ) as catalog_size_b + ) as catalog_size_b, + (select sum(pg_relation_size(indexrelid))::int8 + from pg_stat_user_indexes) as indexes_size_b gauges: - '*' statement_timeout_seconds: 300