This repository was archived by the owner on Nov 28, 2022. It is now read-only.
File tree 2 files changed +33
-1
lines changed
2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -11,11 +11,12 @@ type lockCountWithMode struct {
11
11
Count float64 `db:"count"`
12
12
}
13
13
14
+ // Locks returns the number of locks by mode
14
15
func (g * Gauges ) Locks () * prometheus.GaugeVec {
15
16
var gauge = prometheus .NewGaugeVec (
16
17
prometheus.GaugeOpts {
17
18
Name : "postgresql_lock_count" ,
18
- Help : "count of locks by mode" ,
19
+ Help : "Number of locks by mode" ,
19
20
ConstLabels : g .labels ,
20
21
},
21
22
[]string {"mode" },
@@ -47,3 +48,24 @@ func (g *Gauges) Locks() *prometheus.GaugeVec {
47
48
}()
48
49
return gauge
49
50
}
51
+
52
+ // NotGrantedLocks returns the number of not granted locks
53
+ func (g * Gauges ) NotGrantedLocks () prometheus.Gauge {
54
+ return g .new (
55
+ prometheus.GaugeOpts {
56
+ Name : "postgresql_not_granted_locks" ,
57
+ Help : "Number of not granted locks" ,
58
+ ConstLabels : g .labels ,
59
+ },
60
+ `
61
+ SELECT count(*) as count
62
+ FROM pg_locks
63
+ WHERE NOT granted
64
+ AND database = (
65
+ SELECT datid
66
+ FROM pg_stat_database
67
+ WHERE datname = current_database()
68
+ );
69
+ ` ,
70
+ )
71
+ }
Original file line number Diff line number Diff line change @@ -15,3 +15,13 @@ func TestLocks(t *testing.T) {
15
15
assertGreaterThan (t , - 1 , metrics [0 ])
16
16
assertNoErrs (t , gauges )
17
17
}
18
+
19
+ func TestNotGrantedLocks (t * testing.T ) {
20
+ var assert = assert .New (t )
21
+ _ , gauges , close := prepare (t )
22
+ defer close ()
23
+ var metrics = evaluate (t , gauges .NotGrantedLocks ())
24
+ assert .Len (metrics , 1 )
25
+ assertGreaterThan (t , - 1 , metrics [0 ])
26
+ assertNoErrs (t , gauges )
27
+ }
You can’t perform that action at this time.
0 commit comments