Skip to content
Snippets Groups Projects
Commit 0c639f99 authored by Emanuel Calvo's avatar Emanuel Calvo Committed by DJ Mountney
Browse files

Updating postgres-exporter.yaml accordingly to the...

Updating postgres-exporter.yaml accordingly to the https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/8494 issue
parent 313eeb83
No related branches found
No related tags found
No related merge requests found
---
title: Adding Vacuum Queue metrics to postgres-exporter.yaml
merge_request: 3771
author:
type: added
Loading
Loading
@@ -172,3 +172,120 @@ pg_stuck_idle_in_transaction:
- queries:
usage: "GAUGE"
description: "Current number of queries that are stuck being idle in transactions"
pg_vacuum_queue:
#master: true
# Until postgres_exporter is upgraded. See
# https://gitlab.com/gitlab-org/omnibus-gitlab/issues/4887
query: |
with table_opts_vs_statistic as (
select
pg_class.oid,
pg_class.relname,
coalesce(nspname, 'public') as schemaname,
pg_class.relpages,
pg_class.reltuples,
case
when array_to_string(reloptions, '') like '%autovacuum_vacuum_threshold%' then regexp_replace(array_to_string(reloptions, ''), '.*autovacuum_vacuum_threshold=([0-9.]+).*', E'\\1')::int8
else current_setting('autovacuum_vacuum_threshold')::int8
end as autovacuum_vacuum_threshold,
case
when array_to_string(reloptions, '') like '%autovacuum_vacuum_scale_factor%' then regexp_replace(array_to_string(reloptions, ''), '.*autovacuum_vacuum_scale_factor=([0-9.]+).*', E'\\1')::numeric
else current_setting('autovacuum_vacuum_scale_factor')::numeric
end as autovacuum_vacuum_scale_factor,
case when array_to_string(reloptions, '') ~ 'autovacuum_enabled=(false|off)' then false else true end as autovacuum_enabled,
n_dead_tup,
last_autovacuum,
last_vacuum
from pg_class
join pg_namespace ns on relnamespace = ns.oid
join pg_stat_all_tables psat on psat.relid = pg_class.oid
where relkind in ('r','m')
), p as (
select pgspv.*,a.query,a.wait_event_type,a.wait_event,a.query_start
from pg_stat_progress_vacuum pgspv
left join pg_stat_activity a using (pid)
)
select
table_opts_vs_statistic.schemaname as schemaname,
table_opts_vs_statistic.relname as relname,
round((100 * table_opts_vs_statistic.n_dead_tup::numeric / nullif(table_opts_vs_statistic.reltuples, 0))::numeric, 2) as dead_tup_pct,
table_opts_vs_statistic.reltuples::numeric as reltuples,
table_opts_vs_statistic.n_dead_tup,
(relpages::bigint*8*1024) AS table_size_bytes,
'V. Threshold:' || table_opts_vs_statistic.autovacuum_vacuum_threshold
|| ', V. Scale Factor: ' || (table_opts_vs_statistic.autovacuum_vacuum_scale_factor)::numeric *100 ||' %'
|| case when not autovacuum_enabled then ', DISABLED' else ', enabled' end as "effective_settings",
case
when last_autovacuum > coalesce(last_vacuum, '0001-01-01') then last_autovacuum::timestamp(0)
when last_vacuum is not null then last_vacuum::timestamp(0)
else null
end as "last_vacuumed",
case
when last_autovacuum > coalesce(last_vacuum, '0001-01-01') then 'auto'
when last_vacuum is not null then 'manual'
else null
end as "type",
coalesce(p.phase, 'in queue') as status,
p.pid as pid,
coalesce (p.query,'')as action,
case when p.pid is null then null else coalesce(wait_event_type ||'.'|| wait_event, 'f') end as waiting,
round(100.0 * p.heap_blks_scanned / nullif(p.heap_blks_total, 0), 1) AS scanned_pct,
round(100.0 * p.heap_blks_vacuumed / nullif(p.heap_blks_total, 0), 1) AS vacuumed_pct,
extract ('epoch' from now()-query_start) elapsed_time
from
table_opts_vs_statistic
full outer join p on p.relid = table_opts_vs_statistic.oid and p.datname = current_database()
where
table_opts_vs_statistic.relpages >= 8
and autovacuum_vacuum_threshold + (autovacuum_vacuum_scale_factor::numeric * table_opts_vs_statistic.reltuples) < table_opts_vs_statistic.n_dead_tup
metrics:
- schemaname:
usage: "LABEL"
description: "Table Schema"
- relname:
usage: "LABEL"
description: "Table name"
- dead_tup_pct:
usage: "GAUGE"
description: "Estimated dead tuples percent"
- reltuples:
usage: "GAUGE"
description: "Number of tuples in table"
- n_dead_tup:
usage: "GAUGE"
description: "Estimated number of dead tuples"
- table_size_bytes:
usage: "GAUGE"
description: "Estimated table size"
- effective_settings:
usage: "LABEL"
description: "Autovacuums settings"
- last_vacuumed:
usage: "GAUGE"
description: "Last time at which this table was vacuumed"
- type:
usage: "LABEL"
description: "Last vacuum type"
- status:
usage: "LABEL"
description: "Vacuum actual status"
- pid:
usage: "GAUGE"
description: "Vacuum process id"
- action:
usage: "LABEL"
description: "Type of vacuum executed"
- waiting:
usage: "LABEL"
description: "Vacuum queue status"
- scanned_pct:
usage: "GAUGE"
description: "Estimated rows scanned percent"
- vacuumed_pct:
usage: "GAUGE"
description: "Estimated vacuumed rows percent"
- elapsed_time:
usage: "GAUGE"
description: "Elapsed time vacuuming (in seconds)"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment