Skip to content

Commit

Permalink
Changes to be committed:
Browse files Browse the repository at this point in the history
	modified:   cmd/postgres_exporter/postgres_exporter.go
	modified:   cmd/postgres_exporter/queries.go

Added a query to monitor lock clonflicts. Currently used query for locks is showing only number of different locks.
This one is showing number of conflicting locks, which are preventing others from moving forward, with LABEL that contains information about blocking session PID.
  • Loading branch information
heniek authored and ritbl committed Mar 19, 2023
1 parent b74ef57 commit bf6ad46
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
8 changes: 8 additions & 0 deletions cmd/postgres_exporter/postgres_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ var builtinMetricMaps = map[string]intermediateMetricMap{
true,
0,
},
"pg_lock_conflicts":{
map[string]ColumnMapping{
"blocking_pid": {LABEL, "PID of blocking session", nil, nil},
"count": {GAUGE, "Number of blocked sessions", nil, nil},
},
true,
0,
},
"pg_stat_replication": {
map[string]ColumnMapping{
"procpid": {DISCARD, "Process ID of a WAL sender process", nil, semver.MustParseRange("<9.2.0")},
Expand Down
14 changes: 13 additions & 1 deletion cmd/postgres_exporter/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,19 @@ var queryOverrides = map[string][]OverrideQuery{
ON tmp.mode=tmp2.mode and pg_database.oid = tmp2.database ORDER BY 1`,
},
},

"pg_lock_conflicts": {
{
semver.MustParseRange(">0.0.0"),
`SELECT blockinga.pid AS blocking_pid, count(*) as count
FROM pg_catalog.pg_locks blockedl
JOIN pg_stat_activity blockeda ON blockedl.pid = blockeda.pid
JOIN pg_catalog.pg_locks blockingl ON(blockingl.transactionid=blockedl.transactionid
AND blockedl.pid != blockingl.pid)
JOIN pg_stat_activity blockinga ON blockingl.pid = blockinga.pid
WHERE NOT blockedl.granted
group by blocking_pid`,
},
},
"pg_stat_replication": {
{
semver.MustParseRange(">=10.0.0"),
Expand Down

0 comments on commit bf6ad46

Please sign in to comment.