Skip to content
Snippets Groups Projects
Commit ba02ca49 authored by Julius Volz's avatar Julius Volz
Browse files

Add multiple gitlab-monitor DB metrics to postgres-exporter

This ports metrics from the following database collectors in
gitlab-monitor:

- BlockedQueriesCollector
- SlowQueriesCollector
- StuckIdleInTransactionsCollector
- VacuumQueriesCollector

The ported queries sometimes have to look somewhat different to work in
the postgres-exporter, and hopefully they have the same or close-enough
outcomes as in gitlab-monitor.

Some of the metric names didn't adhere to best practices in gitlab-monitor
(like "_total" as a suffix for gauges), but for now I'm keeping them the
same in postgres-exporter to keep the number of changing things lower.
parent d66a7ab0
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -160,3 +160,80 @@ pg_stat_statements:
- temp_blks_written:
usage: "COUNTER"
description: "Total number of temp blocks written by the statement"
pg_blocked_queries:
query: |
SELECT
count(blocked.transactionid) AS total,
'__transaction__' AS table
FROM pg_catalog.pg_locks blocked
WHERE NOT blocked.granted AND locktype = 'transactionid'
GROUP BY locktype
UNION
SELECT
count(blocked.relation) AS total,
blocked.relation::regclass::text AS table
FROM pg_catalog.pg_locks blocked
WHERE NOT blocked.granted AND locktype != 'transactionid'
GROUP BY relation
metrics:
- total:
usage: "GAUGE"
description: "The current number of blocked queries"
- table:
usage: "LABEL"
description: "The table on which a query is blocked"
pg_slow_queries:
query: |
SELECT COUNT(*) AS total
FROM pg_stat_activity
WHERE state = 'active' AND (now() - query_start) > '1 seconds'::interval
metrics:
- total:
usage: "GAUGE"
description: "Current number of slow queries"
# TODO: In gitlab-monitor, missing age_in_seconds (nil) gets converted to 0.0,
# here it results in an NaN. Should that be changed to the old behavior?
pg_vacuum:
query: |
SELECT
COUNT(*) AS count,
MAX(EXTRACT(EPOCH FROM (clock_timestamp() - query_start))) AS age_in_seconds
FROM pg_catalog.pg_stat_activity
WHERE state = 'active' AND trim(query) ~* '\AVACUUM (?!ANALYZE)'
metrics:
- count:
usage: "GAUGE"
description: "The current number of VACUUM queries"
- age_in_seconds:
usage: "GAUGE"
description: "The current maximum VACUUM query age in seconds"
# TODO: In gitlab-monitor, missing age_in_seconds (nil) gets converted to 0.0,
# here it results in an NaN. Should that be changed to the old behavior?
pg_vacuum_analyze:
query: |
SELECT
COUNT(*) AS count,
MAX(EXTRACT(EPOCH FROM (clock_timestamp() - query_start))) AS age_in_seconds
FROM pg_catalog.pg_stat_activity
WHERE state = 'active' AND trim(query) ~* '\AVACUUM ANALYZE'
metrics:
- count:
usage: "GAUGE"
description: "The current number of VACUUM ANALYZE queries"
- age_in_seconds:
usage: "GAUGE"
description: "The current maximum VACUUM ANALYZE query age in seconds"
pg_stuck_idle_in_transactions:
query: |
SELECT COUNT(*) AS total
FROM pg_stat_activity
WHERE state = 'idle in transaction' AND (now() - query_start) > '10 minutes'::interval
metrics:
- total:
usage: "GAUGE"
description: "Current number of queries that are stuck being idle in transactions"
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