Skip to content

Commit aec5cf0

Browse files
authored
lock conflicts monitoring (#111)
1 parent a215869 commit aec5cf0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

cmd/postgres_exporter/postgres_exporter.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ var builtinMetricMaps = map[string]intermediateMetricMap{
225225
true,
226226
0,
227227
},
228+
"pg_lock_conflicts": {
229+
map[string]ColumnMapping{
230+
"blocking_pid": {LABEL, "PID of blocking session", nil, nil},
231+
"count": {GAUGE, "Number of blocked sessions", nil, nil},
232+
},
233+
true,
234+
0,
235+
},
228236
"pg_stat_replication": {
229237
map[string]ColumnMapping{
230238
"procpid": {DISCARD, "Process ID of a WAL sender process", nil, semver.MustParseRange("<9.2.0")},

cmd/postgres_exporter/queries.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,19 @@ var queryOverrides = map[string][]OverrideQuery{
7070
ON tmp.mode=tmp2.mode and pg_database.oid = tmp2.database ORDER BY 1`,
7171
},
7272
},
73-
73+
"pg_lock_conflicts": {
74+
{
75+
semver.MustParseRange(">0.0.0"),
76+
`SELECT blockinga.pid AS blocking_pid, count(*) as count
77+
FROM pg_catalog.pg_locks blockedl
78+
JOIN pg_stat_activity blockeda ON blockedl.pid = blockeda.pid
79+
JOIN pg_catalog.pg_locks blockingl ON(blockingl.transactionid=blockedl.transactionid
80+
AND blockedl.pid != blockingl.pid)
81+
JOIN pg_stat_activity blockinga ON blockingl.pid = blockinga.pid
82+
WHERE NOT blockedl.granted
83+
group by blocking_pid`,
84+
},
85+
},
7486
"pg_stat_replication": {
7587
{
7688
semver.MustParseRange(">=10.0.0"),

0 commit comments

Comments
 (0)