@@ -8,15 +8,16 @@ import (
8
8
9
9
type locks struct {
10
10
Mode string `db:"mode"`
11
+ Type string `db:"locktype"`
11
12
Count float64 `db:"count"`
12
13
}
13
14
14
- // Locks returns the number of active locks on the database by mode
15
+ // Locks returns the number of active locks on the database by locktype and mode
15
16
func (g * Gauges ) Locks () * prometheus.GaugeVec {
16
17
var gauge = prometheus .NewGaugeVec (
17
18
prometheus.GaugeOpts {
18
- Name : "postgresql_locks_total " ,
19
- Help : "Number of active locks on the database by mode" ,
19
+ Name : "postgresql_locks " ,
20
+ Help : "Number of active locks on the database by locktype and mode" ,
20
21
ConstLabels : g .labels ,
21
22
},
22
23
[]string {"mode" },
@@ -27,20 +28,21 @@ func (g *Gauges) Locks() *prometheus.GaugeVec {
27
28
var locks []locks
28
29
if err := g .query (
29
30
`
30
- SELECT mode, count(*) as count
31
+ SELECT locktype, mode, count(*) as count
31
32
FROM pg_locks
32
33
WHERE database = (
33
34
SELECT datid
34
35
FROM pg_stat_database
35
36
WHERE datname = current_database()
36
- ) GROUP BY mode;
37
+ ) GROUP BY locktype, mode;
37
38
` ,
38
39
& locks ,
39
40
emptyParams ,
40
41
); err == nil {
41
42
for _ , lock := range locks {
42
43
gauge .With (prometheus.Labels {
43
- "mode" : lock .Mode ,
44
+ "locktype" : lock .Type ,
45
+ "mode" : lock .Mode ,
44
46
}).Set (lock .Count )
45
47
}
46
48
}
@@ -54,7 +56,7 @@ func (g *Gauges) Locks() *prometheus.GaugeVec {
54
56
func (g * Gauges ) NotGrantedLocks () prometheus.Gauge {
55
57
return g .new (
56
58
prometheus.GaugeOpts {
57
- Name : "postgresql_not_granted_locks_total " ,
59
+ Name : "postgresql_not_granted_locks " ,
58
60
Help : "Number of not granted locks on the database" ,
59
61
ConstLabels : g .labels ,
60
62
},
@@ -75,7 +77,7 @@ func (g *Gauges) NotGrantedLocks() prometheus.Gauge {
75
77
func (g * Gauges ) DeadLocks () prometheus.Gauge {
76
78
return g .new (
77
79
prometheus.GaugeOpts {
78
- Name : "postgresql_deadlocks_total " ,
80
+ Name : "postgresql_deadlocks " ,
79
81
Help : "Number of deadlocks detected on the database" ,
80
82
ConstLabels : g .labels ,
81
83
},
0 commit comments