Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Postgres locks: show lock of all types even if there are zero values.
Browse files Browse the repository at this point in the history
  • Loading branch information
lesovsky committed Feb 23, 2021
1 parent 32799e3 commit ffcf7b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
11 changes: 10 additions & 1 deletion internal/collector/postgres_locks.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,16 @@ func (c *postgresLocksCollector) Update(config Config, ch chan<- prometheus.Metr
func parsePostgresLocksStats(r *model.PGResult) map[string]float64 {
log.Debug("parse postgres locks stats")

stats := make(map[string]float64)
stats := map[string]float64{
"AccessShareLock": 0,
"RowShareLock": 0,
"RowExclusiveLock": 0,
"ShareUpdateExclusiveLock": 0,
"ShareLock": 0,
"ShareRowExclusiveLock": 0,
"ExclusiveLock": 0,
"AccessExclusiveLock": 0,
}

for _, row := range r.Rows {
if len(row) != 2 {
Expand Down
12 changes: 8 additions & 4 deletions internal/collector/postgres_locks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ func Test_parsePostgresLocksStats(t *testing.T) {
},
},
want: map[string]float64{
"RowExclusiveLock": 150,
"RowShareLock": 100,
"ExclusiveLock": 50,
"AccessShareLock": 2000,
"AccessShareLock": 2000,
"RowShareLock": 100,
"RowExclusiveLock": 150,
"ShareUpdateExclusiveLock": 0,
"ShareLock": 0,
"ShareRowExclusiveLock": 0,
"ExclusiveLock": 50,
"AccessExclusiveLock": 0,
},
},
}
Expand Down

0 comments on commit ffcf7b5

Please sign in to comment.