You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: config/pgwatch-prometheus/metrics.yml
+22-46Lines changed: 22 additions & 46 deletions
Original file line number
Diff line number
Diff line change
@@ -285,7 +285,7 @@ metrics:
285
285
from
286
286
pg_locks
287
287
where
288
-
pid!= pg_backend_pid()
288
+
pid<> pg_backend_pid()
289
289
and database = (select oid from pg_database where datname = current_database())
290
290
limit 5000
291
291
)
@@ -368,7 +368,7 @@ metrics:
368
368
category as tag_category,
369
369
vartype as tag_vartype,
370
370
case when setting ~ '^-?[0-9]+$' then setting::bigint else null end as numeric_value,
371
-
case when source!= 'default' then 0 else 1 end as is_default,
371
+
case when source<> 'default' then 0 else 1 end as is_default,
372
372
1 as configured
373
373
from pg_settings
374
374
gauges:
@@ -390,7 +390,7 @@ metrics:
390
390
from pg_class c
391
391
join pg_namespace n on n.oid = c.relnamespace
392
392
where relkind in ('p', 'r')
393
-
and relpersistence!= 't'
393
+
and relpersistence<> 't'
394
394
and not n.nspname like any (array[E'pg\\_%', 'information_schema', E'\\_timescaledb%'])
395
395
and not exists(select * from pg_inherits where inhrelid = c.oid)
396
396
and exists(select * from pg_inherits where inhparent = c.oid)
@@ -414,7 +414,7 @@ metrics:
414
414
pg_table_size(relid) as table_size_b,
415
415
abs(greatest(ceil(log((pg_table_size(relid) + 1) / 10 ^ 6)), 0))::text as tag_table_size_cardinality_mb, -- i.e. 0=<1MB, 1=<10MB, 2=<100MB,..
416
416
pg_total_relation_size(relid) as total_relation_size_b,
417
-
case when reltoastrelid!= 0 then pg_total_relation_size(reltoastrelid) else 0::int8 end as toast_size_b,
417
+
case when reltoastrelid<> 0 then pg_total_relation_size(reltoastrelid) else 0::int8 end as toast_size_b,
418
418
(extract(epoch from now() - greatest(last_vacuum, last_autovacuum)))::int8 as seconds_since_last_vacuum,
419
419
(extract(epoch from now() - greatest(last_analyze, last_autoanalyze)))::int8 as seconds_since_last_analyze,
420
420
case when 'autovacuum_enabled=off' = ANY (c.reloptions) then 1 else 0 end as no_autovacuum,
@@ -432,14 +432,14 @@ metrics:
432
432
autovacuum_count,
433
433
analyze_count,
434
434
autoanalyze_count,
435
-
case when c.relkind!= 'p' then age(c.relfrozenxid) else 0 end as tx_freeze_age
435
+
case when c.relkind<> 'p' then age(c.relfrozenxid) else 0 end as tx_freeze_age
436
436
from pg_stat_user_tables ut
437
437
join
438
438
pg_class c on c.oid = ut.relid
439
439
where
440
440
-- leaving out fully locked tables as pg_relation_size also wants a lock and would wait
441
441
not exists(select 1 from pg_locks where relation = relid and mode = 'AccessExclusiveLock')
442
-
and c.relpersistence!= 't' -- and temp tables
442
+
and c.relpersistence<> 't' -- and temp tables
443
443
)
444
444
445
445
select /* pgwatch_generated */
@@ -526,7 +526,7 @@ metrics:
526
526
from pg_class c
527
527
join pg_namespace n on n.oid = c.relnamespace
528
528
where relkind in ('p', 'r')
529
-
and relpersistence!= 't'
529
+
and relpersistence<> 't'
530
530
and not n.nspname like any (array[E'pg\\_%', 'information_schema', E'\\_timescaledb%'])
531
531
and not exists(select * from pg_inherits where inhrelid = c.oid)
532
532
and exists(select * from pg_inherits where inhparent = c.oid)
@@ -550,7 +550,7 @@ metrics:
550
550
pg_table_size(relid) as table_size_b,
551
551
abs(greatest(ceil(log((pg_table_size(relid) + 1) / 10 ^ 6)), 0))::text as tag_table_size_cardinality_mb, -- i.e. 0=<1MB, 1=<10MB, 2=<100MB,..
552
552
pg_total_relation_size(relid) as total_relation_size_b,
553
-
case when c.reltoastrelid!= 0 then pg_total_relation_size(c.reltoastrelid) else 0::int8 end as toast_size_b,
553
+
case when c.reltoastrelid<> 0 then pg_total_relation_size(c.reltoastrelid) else 0::int8 end as toast_size_b,
554
554
(extract(epoch from now() - greatest(last_vacuum, last_autovacuum)))::int8 as seconds_since_last_vacuum,
555
555
(extract(epoch from now() - greatest(last_analyze, last_autoanalyze)))::int8 as seconds_since_last_analyze,
556
556
case when 'autovacuum_enabled=off' = ANY (c.reloptions) then 1 else 0 end as no_autovacuum,
@@ -568,7 +568,7 @@ metrics:
568
568
autovacuum_count,
569
569
analyze_count,
570
570
autoanalyze_count,
571
-
case when c.relkind!= 'p' then age(c.relfrozenxid) else 0 end as tx_freeze_age,
571
+
case when c.relkind<> 'p' then age(c.relfrozenxid) else 0 end as tx_freeze_age,
572
572
extract(epoch from now() - last_seq_scan)::int8 as last_seq_scan_s
573
573
from pg_stat_user_tables ut
574
574
join pg_class c on c.oid = ut.relid
@@ -578,7 +578,7 @@ metrics:
578
578
where
579
579
-- leaving out fully locked tables as pg_relation_size also wants a lock and would wait
580
580
not exists (select 1 from pg_locks where relation = relid and mode = 'AccessExclusiveLock')
581
-
and c.relpersistence!= 't' -- and temp tables
581
+
and c.relpersistence<> 't' -- and temp tables
582
582
order by case when c.relkind = 'p' then 1e9::int else coalesce(c.relpages, 0) + coalesce(t.relpages, 0) + coalesce(tir.relpages, 0) end desc
583
583
limit 1500 /* NB! When changing the bottom final LIMIT also adjust this limit. Should be at least 5x bigger as approx sizes depend a lot on vacuum frequency.
584
584
The general idea is to reduce filesystem "stat"-ing on tables that won't make it to final output anyways based on approximate size */
@@ -1328,40 +1328,24 @@ metrics:
1328
1328
current_database() as tag_datname,
1329
1329
n.nspname as tag_schema,
1330
1330
c.relname as tag_table_name,
1331
-
n.nspname || '.' || c.relname as tag_table_full_name,
1332
1331
c.oid as table_oid,
1333
1332
c.reltoastrelid,
1334
1333
-- Main table size components (bytes)
1335
1334
pg_relation_size(c.oid, 'main') as table_main_size_b,
1336
1335
pg_relation_size(c.oid, 'fsm') as table_fsm_size_b,
1337
1336
pg_relation_size(c.oid, 'vm') as table_vm_size_b,
1338
1337
pg_indexes_size(c.oid) as table_indexes_size_b,
1339
-
-- TOAST table components (if exists)
1340
-
case
1341
-
when c.reltoastrelid != 0 then pg_relation_size(c.reltoastrelid, 'main')
1342
-
else 0::int8
1343
-
end as toast_main_size_b,
1344
-
case
1345
-
when c.reltoastrelid != 0 then pg_relation_size(c.reltoastrelid, 'fsm')
1346
-
else 0::int8
1347
-
end as toast_fsm_size_b,
1348
-
case
1349
-
when c.reltoastrelid != 0 then pg_relation_size(c.reltoastrelid, 'vm')
1350
-
else 0::int8
1351
-
end as toast_vm_size_b,
1352
-
case
1353
-
when c.reltoastrelid != 0 then pg_indexes_size(c.reltoastrelid)
1354
-
else 0::int8
1355
-
end as toast_indexes_size_b,
1356
-
-- Calculated totals for reference
1357
-
pg_table_size(c.oid) as table_total_size_b,
1358
-
pg_total_relation_size(c.oid) as relation_total_size_b,
1359
-
-- Size cardinality for grouping (logarithmic scale)
1338
+
pg_relation_size(c.reltoastrelid, 'main') as toast_main_size_b,
1339
+
pg_relation_size(c.reltoastrelid, 'fsm') as toast_fsm_size_b,
1340
+
pg_relation_size(c.reltoastrelid, 'vm') as toast_vm_size_b,
1341
+
pg_indexes_size(c.reltoastrelid) as toast_indexes_size_b,
1342
+
pg_total_relation_size(c.reltoastrelid) as toast_total_size_b,
1343
+
pg_total_relation_size(c.oid) as total_relation_size_b,
1360
1344
abs(greatest(ceil(log((pg_total_relation_size(c.oid) + 1) / 10 ^ 6)), 0))::text as tag_size_cardinality_mb
1361
1345
from pg_class c
1362
1346
join pg_namespace n on n.oid = c.relnamespace
1363
-
where c.relkind in ('r', 'p') -- regular tables andpartitioned tables
1364
-
and n.nspname not in ('information_schema', 'pg_catalog', 'pg_toast')
1347
+
where c.relkind in ('r', 'p', 'm') -- regular tables,partitioned tables, materialized views
1348
+
and n.nspname not in ('information_schema', 'pg_toast')
1365
1349
and not exists (
1366
1350
select 1 from pg_locks
1367
1351
where relation = c.oid and mode = 'AccessExclusiveLock'
@@ -1373,7 +1357,6 @@ metrics:
1373
1357
tag_datname,
1374
1358
tag_schema,
1375
1359
tag_table_name,
1376
-
tag_table_full_name,
1377
1360
tag_size_cardinality_mb,
1378
1361
table_main_size_b,
1379
1362
table_fsm_size_b,
@@ -1383,16 +1366,10 @@ metrics:
1383
1366
toast_fsm_size_b,
1384
1367
toast_vm_size_b,
1385
1368
toast_indexes_size_b,
1386
-
table_total_size_b,
1387
-
relation_total_size_b,
1388
-
-- Additional calculated metrics
1389
-
(table_main_size_b + toast_main_size_b) as actual_data_size_b,
1390
-
(table_fsm_size_b + table_vm_size_b + toast_fsm_size_b + toast_vm_size_b) as metadata_size_b,
1391
-
(table_indexes_size_b + toast_indexes_size_b) as total_indexes_size_b,
1369
+
total_relation_size_b,
1392
1370
(toast_main_size_b + toast_fsm_size_b + toast_vm_size_b + toast_indexes_size_b) as total_toast_size_b
1393
1371
from table_sizes
1394
-
where table_main_size_b > 0 -- only include tables with actual data
1395
-
order by relation_total_size_b desc
1372
+
where total_relation_size_b > 0
1396
1373
gauges:
1397
1374
-table_main_size_b
1398
1375
-table_fsm_size_b
@@ -1402,13 +1379,12 @@ metrics:
1402
1379
-toast_fsm_size_b
1403
1380
-toast_vm_size_b
1404
1381
-toast_indexes_size_b
1405
-
-table_total_size_b
1406
-
-relation_total_size_b
1382
+
-total_relation_size_b
1407
1383
-actual_data_size_b
1408
1384
-metadata_size_b
1409
1385
-total_indexes_size_b
1410
1386
-total_toast_size_b
1411
-
statement_timeout_seconds:300
1387
+
statement_timeout_seconds:15
1412
1388
pg_invalid_indexes:
1413
1389
description:>
1414
1390
This metric identifies invalid indexes in the database.