@@ -8,15 +8,16 @@ import (
88
99type locks struct {
1010 Mode string `db:"mode"`
11+ Type string `db:"locktype"`
1112 Count float64 `db:"count"`
1213}
1314
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
1516func (g * Gauges ) Locks () * prometheus.GaugeVec {
1617 var gauge = prometheus .NewGaugeVec (
1718 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" ,
2021 ConstLabels : g .labels ,
2122 },
2223 []string {"mode" },
@@ -27,20 +28,21 @@ func (g *Gauges) Locks() *prometheus.GaugeVec {
2728 var locks []locks
2829 if err := g .query (
2930 `
30- SELECT mode, count(*) as count
31+ SELECT locktype, mode, count(*) as count
3132 FROM pg_locks
3233 WHERE database = (
3334 SELECT datid
3435 FROM pg_stat_database
3536 WHERE datname = current_database()
36- ) GROUP BY mode;
37+ ) GROUP BY locktype, mode;
3738 ` ,
3839 & locks ,
3940 emptyParams ,
4041 ); err == nil {
4142 for _ , lock := range locks {
4243 gauge .With (prometheus.Labels {
43- "mode" : lock .Mode ,
44+ "locktype" : lock .Type ,
45+ "mode" : lock .Mode ,
4446 }).Set (lock .Count )
4547 }
4648 }
@@ -54,7 +56,7 @@ func (g *Gauges) Locks() *prometheus.GaugeVec {
5456func (g * Gauges ) NotGrantedLocks () prometheus.Gauge {
5557 return g .new (
5658 prometheus.GaugeOpts {
57- Name : "postgresql_not_granted_locks_total " ,
59+ Name : "postgresql_not_granted_locks " ,
5860 Help : "Number of not granted locks on the database" ,
5961 ConstLabels : g .labels ,
6062 },
@@ -75,7 +77,7 @@ func (g *Gauges) NotGrantedLocks() prometheus.Gauge {
7577func (g * Gauges ) DeadLocks () prometheus.Gauge {
7678 return g .new (
7779 prometheus.GaugeOpts {
78- Name : "postgresql_deadlocks_total " ,
80+ Name : "postgresql_deadlocks " ,
7981 Help : "Number of deadlocks detected on the database" ,
8082 ConstLabels : g .labels ,
8183 },
0 commit comments