Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add client_addr to metric pg_stat_activity_max_tx_duration #986

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/postgres_exporter/postgres_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ var builtinMetricMaps = map[string]intermediateMetricMap{
"state": {LABEL, "connection state", nil, semver.MustParseRange(">=9.2.0")},
"usename": {LABEL, "connection usename", nil, nil},
"application_name": {LABEL, "connection application_name", nil, nil},
"client_addr": {LABEL, "connection client_addr", 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},
},
Expand Down
4 changes: 3 additions & 1 deletion cmd/postgres_exporter/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ var queryOverrides = map[string][]OverrideQuery{
tmp.state,
tmp2.usename,
tmp2.application_name,
tmp2.client_addr,
COALESCE(count,0) as count,
COALESCE(max_tx_duration,0) as max_tx_duration
FROM
Expand All @@ -132,9 +133,10 @@ var queryOverrides = map[string][]OverrideQuery{
state,
usename,
application_name,
client_addr,
count(*) AS count,
MAX(EXTRACT(EPOCH FROM now() - xact_start))::float AS max_tx_duration
FROM pg_stat_activity GROUP BY datname,state,usename,application_name) AS tmp2
FROM pg_stat_activity GROUP BY datname,state,usename,application_name, client_addr) AS tmp2
ON tmp.state = tmp2.state AND pg_database.datname = tmp2.datname
`,
},
Expand Down