6
6
"github.com/prometheus/client_golang/prometheus"
7
7
)
8
8
9
+ // UnusedIndexes returns the count of unused indexes in the database
9
10
func (g * Gauges ) UnusedIndexes () prometheus.Gauge {
10
11
return g .new (
11
12
prometheus.GaugeOpts {
@@ -23,31 +24,33 @@ func (g *Gauges) UnusedIndexes() prometheus.Gauge {
23
24
)
24
25
}
25
26
27
+ // IndexBlocksRead returns the sum of the number of disk blocks read from all public indexes
26
28
func (g * Gauges ) IndexBlocksRead () prometheus.Gauge {
27
29
return g .new (
28
30
prometheus.GaugeOpts {
29
31
Name : "postgresql_index_blks_read_sum" ,
30
- Help : "Sum of the number of disk blocks read from all public indexes" ,
32
+ Help : "Sum of the number of disk blocks read from all user indexes" ,
31
33
ConstLabels : g .labels ,
32
34
},
33
35
`
34
36
SELECT coalesce(sum(idx_blks_read), 0)
35
- FROM pg_statio_all_indexes
37
+ FROM pg_statio_user_indexes
36
38
WHERE schemaname = 'public'
37
39
` ,
38
40
)
39
41
}
40
42
43
+ // IndexBlocksHit returns the sum of the number of buffer hits on all user indexes
41
44
func (g * Gauges ) IndexBlocksHit () prometheus.Gauge {
42
45
return g .new (
43
46
prometheus.GaugeOpts {
44
47
Name : "postgresql_index_blks_hit_sum" ,
45
- Help : "Sum of the number of buffer hits on all public indexes" ,
48
+ Help : "Sum of the number of buffer hits on all user indexes" ,
46
49
ConstLabels : g .labels ,
47
50
},
48
51
`
49
52
SELECT coalesce(sum(idx_blks_hit), 0)
50
- FROM pg_statio_all_indexes
53
+ FROM pg_statio_user_indexes
51
54
WHERE schemaname = 'public'
52
55
` ,
53
56
)
@@ -160,11 +163,13 @@ type indexBloat struct {
160
163
Pct float64 `db:"bloat_pct"`
161
164
}
162
165
166
+ // IndexBloat returns bloat percentage of an index reporting only for indexes
167
+ // with size greater than 10mb and bloat lower than 50%
163
168
func (g * Gauges ) IndexBloat () * prometheus.GaugeVec {
164
169
var gauge = prometheus .NewGaugeVec (
165
170
prometheus.GaugeOpts {
166
171
Name : "postgresql_index_bloat_pct" ,
167
- Help : "bloat percentage of an index. reports only for indexes > 10mb and > 50% bloat" ,
172
+ Help : "Bloat percentage of an index. This metric reports only indexes > 10mb and > 50% bloat" ,
168
173
ConstLabels : g .labels ,
169
174
},
170
175
[]string {"index" , "table" },
0 commit comments