@@ -61,36 +61,89 @@ func (g *Gauges) UnusedIndexes() prometheus.Gauge {
61
61
)
62
62
}
63
63
64
+ type schemaIndexBlocksRead struct {
65
+ Name string `db:"schemaname"`
66
+ IndexBlocksRead float64 `db:"idx_blks_read"`
67
+ }
68
+
64
69
// IndexBlocksRead returns the sum of the number of disk blocks read from all public indexes
65
70
func (g * Gauges ) IndexBlocksRead () prometheus.Gauge {
66
- return g . new (
71
+ var gauge = prometheus . NewGaugeVec (
67
72
prometheus.GaugeOpts {
68
- Name : "postgresql_index_blks_read_sum " ,
73
+ Name : "postgresql_index_blocks_read_sum " ,
69
74
Help : "Sum of the number of disk blocks read from all user indexes" ,
70
75
ConstLabels : g .labels ,
71
76
},
72
- `
73
- SELECT coalesce(sum(idx_blks_read), 0)
74
- FROM pg_statio_user_indexes
75
- WHERE schemaname NOT IN ('pg_catalog','information_schema','monitoring')
76
- ` ,
77
+ []string {"schema" },
77
78
)
79
+
80
+ const schemaIndexBlocksReadQuery = `
81
+ SELECT
82
+ schemaname,
83
+ coalesce(sum(idx_blks_read), 0) AS idx_blks_read
84
+ FROM pg_statio_user_indexes
85
+ WHERE schemaname NOT IN ('pg_catalog','information_schema','monitoring')
86
+ GROUP BY schemaname;
87
+ `
88
+
89
+ go func () {
90
+ for {
91
+ var schemas []schemaIndexBlocksRead
92
+ if err := g .query (schemaIndexBlocksReadQuery , & schemas , emptyParams ); err == nil {
93
+ for _ , schema := range schemas {
94
+ gauge .With (prometheus.Labels {
95
+ "table" : schema .Name ,
96
+ }).Set (table .IndexBlocksRead )
97
+ }
98
+ }
99
+ time .Sleep (g .interval )
100
+ }
101
+ }()
102
+
103
+ return gauge
104
+ }
105
+
106
+
107
+ type schemaIndexBlocksHit struct {
108
+ Name string `db:"schemaname"`
109
+ IndexBlocksRead float64 `db:"idx_blks_hit"`
78
110
}
79
111
80
112
// IndexBlocksHit returns the sum of the number of buffer hits on all user indexes
81
- func (g * Gauges ) IndexBlocksHit () prometheus.Gauge {
82
- return g . new (
113
+ func (g * Gauges ) IndexBlocksRead () prometheus.Gauge {
114
+ var gauge = prometheus . NewGaugeVec (
83
115
prometheus.GaugeOpts {
84
- Name : "postgresql_index_blks_hit_sum " ,
116
+ Name : "postgresql_index_blocks_hit_sum " ,
85
117
Help : "Sum of the number of buffer hits on all user indexes" ,
86
118
ConstLabels : g .labels ,
87
119
},
88
- `
89
- SELECT coalesce(sum(idx_blks_hit), 0)
90
- FROM pg_statio_user_indexes
91
- WHERE schemaname NOT IN ('pg_catalog','information_schema','monitoring')
92
- ` ,
120
+ []string {"schema" },
93
121
)
122
+
123
+ const schemaIndexBlocksHitQuery = `
124
+ SELECT
125
+ schemaname,
126
+ coalesce(sum(idx_blks_hit), 0) AS idx_blks_hit
127
+ FROM pg_statio_user_indexes
128
+ WHERE schemaname NOT IN ('pg_catalog','information_schema','monitoring')
129
+ GROUP BY schemaname;
130
+ `
131
+
132
+ go func () {
133
+ for {
134
+ var schemas []schemaIndexBlocksHit
135
+ if err := g .query (schemaIndexBlocksHitQuery , & schemas , emptyParams ); err == nil {
136
+ for _ , schema := range schemas {
137
+ gauge .With (prometheus.Labels {
138
+ "table" : schema .Name ,
139
+ }).Set (table .IndexBlocksRead )
140
+ }
141
+ }
142
+ time .Sleep (g .interval )
143
+ }
144
+ }()
145
+
146
+ return gauge
94
147
}
95
148
96
149
const indexBloatQuery = `
0 commit comments