Skip to content

Commit 2f156dd

Browse files
Bhargav kamineniBhargav kamineni
Bhargav kamineni
authored and
Bhargav kamineni
committed
postgres exporter changes for transaction duration to determine stage change
1 parent cf49216 commit 2f156dd

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

cmd/postgres_exporter/postgres_exporter.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,13 @@ var builtinMetricMaps = map[string]intermediateMetricMap{
258258
},
259259
"pg_stat_activity": {
260260
map[string]ColumnMapping{
261-
"datname": {LABEL, "Name of this database", nil, nil},
262-
"state": {LABEL, "connection state", nil, semver.MustParseRange(">=9.2.0")},
263-
"usename": {LABEL, "Name of the user logged into this backend", nil, nil},
264-
"application_name": {LABEL, "Name of the application that is connected to this backend", nil, nil},
265-
"count": {GAUGE, "number of connections in this state", nil, nil},
266-
"max_tx_duration": {GAUGE, "max duration in seconds any active transaction has been running", nil, nil},
261+
"datname": {LABEL, "Name of this database", nil, nil},
262+
"state": {LABEL, "connection state", nil, semver.MustParseRange(">=9.2.0")},
263+
"usename": {LABEL, "Name of the user logged into this backend", nil, nil},
264+
"application_name": {LABEL, "Name of the application that is connected to this backend", nil, nil},
265+
"count": {GAUGE, "number of connections in this state", nil, nil},
266+
"max_tx_duration": {GAUGE, "max duration in seconds any active transaction has been running", nil, nil},
267+
"max_state_duration": {GAUGE, "max state change duration in seconds any active transaction has been", nil, nil},
267268
},
268269
true,
269270
0,

cmd/postgres_exporter/queries.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ var queryOverrides = map[string][]OverrideQuery{
131131
tmp2.usename,
132132
tmp2.application_name,
133133
COALESCE(count,0) as count,
134-
COALESCE(max_tx_duration,0) as max_tx_duration
134+
COALESCE(max_tx_duration,0) as max_tx_duration,
135+
COALESCE(max_state_duration, 0) AS max_state_duration
135136
FROM
136137
(
137138
VALUES ('active'),
@@ -149,7 +150,8 @@ var queryOverrides = map[string][]OverrideQuery{
149150
usename,
150151
application_name,
151152
count(*) AS count,
152-
MAX(EXTRACT(EPOCH FROM now() - xact_start))::float AS max_tx_duration
153+
MAX(EXTRACT(EPOCH FROM now() - xact_start))::float AS max_tx_duration,
154+
MAX(EXTRACT(EPOCH FROM now() - state_change))::float AS max_state_duration
153155
FROM pg_stat_activity GROUP BY datname,state,usename,application_name) AS tmp2
154156
ON tmp.state = tmp2.state AND pg_database.datname = tmp2.datname
155157
`,
@@ -163,7 +165,8 @@ var queryOverrides = map[string][]OverrideQuery{
163165
usename,
164166
application_name,
165167
COALESCE(count(*),0) AS count,
166-
COALESCE(MAX(EXTRACT(EPOCH FROM now() - xact_start))::float,0) AS max_tx_duration
168+
COALESCE(MAX(EXTRACT(EPOCH FROM now() - xact_start))::float,0) AS max_tx_duration,
169+
COALESCE(MAX(EXTRACT(EPOCH FROM now() - state_change))::float,0) AS max_state_duration
167170
FROM pg_stat_activity GROUP BY datname,usename,application_name
168171
`,
169172
},

0 commit comments

Comments
 (0)