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

PMM-13697 postgres exporter changes for transaction duration to determine stage… #293

Open
wants to merge 2 commits into
base: main
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
13 changes: 7 additions & 6 deletions cmd/postgres_exporter/postgres_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,13 @@ var builtinMetricMaps = map[string]intermediateMetricMap{
},
"pg_stat_activity": {
map[string]ColumnMapping{
"datname": {LABEL, "Name of this database", nil, nil},
"state": {LABEL, "connection state", nil, semver.MustParseRange(">=9.2.0")},
"usename": {LABEL, "Name of the user logged into this backend", nil, nil},
"application_name": {LABEL, "Name of the application that is connected to this backend", 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},
"datname": {LABEL, "Name of this database", nil, nil},
"state": {LABEL, "connection state", nil, semver.MustParseRange(">=9.2.0")},
"usename": {LABEL, "Name of the user logged into this backend", nil, nil},
"application_name": {LABEL, "Name of the application that is connected to this backend", 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},
"max_state_duration": {GAUGE, "max state change duration in seconds any active transaction has been", nil, nil},
},
true,
0,
Expand Down
9 changes: 6 additions & 3 deletions cmd/postgres_exporter/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ var queryOverrides = map[string][]OverrideQuery{
tmp2.usename,
tmp2.application_name,
COALESCE(count,0) as count,
COALESCE(max_tx_duration,0) as max_tx_duration
COALESCE(max_tx_duration,0) as max_tx_duration,
COALESCE(max_state_duration, 0) AS max_state_duration
FROM
(
VALUES ('active'),
Expand All @@ -149,7 +150,8 @@ var queryOverrides = map[string][]OverrideQuery{
usename,
application_name,
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,
MAX(EXTRACT(EPOCH FROM now() - state_change))::float AS max_state_duration
FROM pg_stat_activity GROUP BY datname,state,usename,application_name) AS tmp2
ON tmp.state = tmp2.state AND pg_database.datname = tmp2.datname
`,
Expand All @@ -163,7 +165,8 @@ var queryOverrides = map[string][]OverrideQuery{
usename,
application_name,
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,
COALESCE(MAX(EXTRACT(EPOCH FROM now() - state_change))::float,0) AS max_state_duration
FROM pg_stat_activity GROUP BY datname,usename,application_name
`,
},
Expand Down