Skip to content

Commit 838e15b

Browse files
committed
feat: add wait/backend to pg_stat_activity
Signed-off-by: Felipe Galindo Sanchez <[email protected]>
1 parent 5bb1702 commit 838e15b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

cmd/postgres_exporter/postgres_exporter.go

+3
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ var builtinMetricMaps = map[string]intermediateMetricMap{
251251
"state": {LABEL, "connection state", nil, semver.MustParseRange(">=9.2.0")},
252252
"usename": {LABEL, "connection usename", nil, nil},
253253
"application_name": {LABEL, "connection application_name", nil, nil},
254+
"backend_type": {LABEL, "connection backend_type", nil, nil},
255+
"wait_event_type": {LABEL, "connection wait_event_type", nil, nil},
256+
"wait_event": {LABEL, "connection wait_event", nil, nil},
254257
"count": {GAUGE, "number of connections in this state", nil, nil},
255258
"max_tx_duration": {GAUGE, "max duration in seconds any active transaction has been running", nil, nil},
256259
},

cmd/postgres_exporter/queries.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ var queryOverrides = map[string][]OverrideQuery{
115115
tmp.state,
116116
tmp2.usename,
117117
tmp2.application_name,
118+
tmp2.backend_type,
119+
tmp2.wait_event_type,
120+
tmp2.wait_event,
118121
COALESCE(count,0) as count,
119122
COALESCE(max_tx_duration,0) as max_tx_duration
120123
FROM
@@ -133,9 +136,13 @@ var queryOverrides = map[string][]OverrideQuery{
133136
state,
134137
usename,
135138
application_name,
139+
backend_type,
140+
wait_event_type,
141+
wait_event,
136142
count(*) AS count,
137143
MAX(EXTRACT(EPOCH FROM now() - xact_start))::float AS max_tx_duration
138-
FROM pg_stat_activity GROUP BY datname,state,usename,application_name) AS tmp2
144+
FROM pg_stat_activity
145+
GROUP BY datname,state,usename,application_name,backend_type,wait_event_type,wait_event) AS tmp2
139146
ON tmp.state = tmp2.state AND pg_database.datname = tmp2.datname
140147
`,
141148
},

0 commit comments

Comments
 (0)