You've already forked postgres_exporter
mirror of
https://github.com/prometheus-community/postgres_exporter.git
synced 2025-11-04 18:51:42 +03:00
Capture usename and application_name for pg_stat_activity
It is necessary to be able to exclude backups from long-running transaction alerts, as they are to be expected. With the current pg_stat_activity metric there is no ability to filter out specific users or application names. Resolves #668 Signed-off-by: cezmunsta <github@incoming-email.co.uk>
This commit is contained in:
@@ -137,6 +137,8 @@ var queryOverrides = map[string][]OverrideQuery{
|
||||
SELECT
|
||||
pg_database.datname,
|
||||
tmp.state,
|
||||
tmp2.usename,
|
||||
tmp2.application_name,
|
||||
COALESCE(count,0) as count,
|
||||
COALESCE(max_tx_duration,0) as max_tx_duration
|
||||
FROM
|
||||
@@ -153,9 +155,11 @@ var queryOverrides = map[string][]OverrideQuery{
|
||||
SELECT
|
||||
datname,
|
||||
state,
|
||||
usename,
|
||||
application_name,
|
||||
count(*) AS count,
|
||||
MAX(EXTRACT(EPOCH FROM now() - xact_start))::float AS max_tx_duration
|
||||
FROM pg_stat_activity GROUP BY datname,state) AS tmp2
|
||||
FROM pg_stat_activity GROUP BY datname,state,usename,application_name) AS tmp2
|
||||
ON tmp.state = tmp2.state AND pg_database.datname = tmp2.datname
|
||||
`,
|
||||
},
|
||||
@@ -165,9 +169,11 @@ var queryOverrides = map[string][]OverrideQuery{
|
||||
SELECT
|
||||
datname,
|
||||
'unknown' AS state,
|
||||
usename,
|
||||
application_name,
|
||||
COALESCE(count(*),0) AS count,
|
||||
COALESCE(MAX(EXTRACT(EPOCH FROM now() - xact_start))::float,0) AS max_tx_duration
|
||||
FROM pg_stat_activity GROUP BY datname
|
||||
FROM pg_stat_activity GROUP BY datname,usename,application_name
|
||||
`,
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user