mirror of
https://github.com/prometheus-community/postgres_exporter
synced 2025-04-04 23:29:30 +00:00
Merge pull request #673 from cezmunsta/pg_stat_activity-enhancements
Capture usename and application_name for pg_stat_activity
This commit is contained in:
commit
36773e06dc
@ -282,10 +282,12 @@ var builtinMetricMaps = map[string]intermediateMetricMap{
|
|||||||
},
|
},
|
||||||
"pg_stat_activity": {
|
"pg_stat_activity": {
|
||||||
map[string]ColumnMapping{
|
map[string]ColumnMapping{
|
||||||
"datname": {LABEL, "Name of this database", nil, nil},
|
"datname": {LABEL, "Name of this database", nil, nil},
|
||||||
"state": {LABEL, "connection state", nil, semver.MustParseRange(">=9.2.0")},
|
"state": {LABEL, "connection state", nil, semver.MustParseRange(">=9.2.0")},
|
||||||
"count": {GAUGE, "number of connections in this state", nil, nil},
|
"usename": {LABEL, "connection usename", nil, nil},
|
||||||
"max_tx_duration": {GAUGE, "max duration in seconds any active transaction has been running", nil, nil},
|
"application_name": {LABEL, "connection application_name", nil, nil},
|
||||||
|
"count": {GAUGE, "number of connections in this state", nil, nil},
|
||||||
|
"max_tx_duration": {GAUGE, "max duration in seconds any active transaction has been running", nil, nil},
|
||||||
},
|
},
|
||||||
true,
|
true,
|
||||||
0,
|
0,
|
||||||
|
@ -137,6 +137,8 @@ var queryOverrides = map[string][]OverrideQuery{
|
|||||||
SELECT
|
SELECT
|
||||||
pg_database.datname,
|
pg_database.datname,
|
||||||
tmp.state,
|
tmp.state,
|
||||||
|
tmp2.usename,
|
||||||
|
tmp2.application_name,
|
||||||
COALESCE(count,0) as count,
|
COALESCE(count,0) as count,
|
||||||
COALESCE(max_tx_duration,0) as max_tx_duration
|
COALESCE(max_tx_duration,0) as max_tx_duration
|
||||||
FROM
|
FROM
|
||||||
@ -153,9 +155,11 @@ var queryOverrides = map[string][]OverrideQuery{
|
|||||||
SELECT
|
SELECT
|
||||||
datname,
|
datname,
|
||||||
state,
|
state,
|
||||||
|
usename,
|
||||||
|
application_name,
|
||||||
count(*) AS count,
|
count(*) AS count,
|
||||||
MAX(EXTRACT(EPOCH FROM now() - xact_start))::float AS max_tx_duration
|
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
|
ON tmp.state = tmp2.state AND pg_database.datname = tmp2.datname
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
@ -165,9 +169,11 @@ var queryOverrides = map[string][]OverrideQuery{
|
|||||||
SELECT
|
SELECT
|
||||||
datname,
|
datname,
|
||||||
'unknown' AS state,
|
'unknown' AS state,
|
||||||
|
usename,
|
||||||
|
application_name,
|
||||||
COALESCE(count(*),0) AS count,
|
COALESCE(count(*),0) AS count,
|
||||||
COALESCE(MAX(EXTRACT(EPOCH FROM now() - xact_start))::float,0) AS max_tx_duration
|
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
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user