@@ -34,74 +34,82 @@ func NewPGStatBGWriterCollector(collectorConfig) (Collector, error) {
34
34
35
35
const bgWriterSubsystem = "stat_bgwriter"
36
36
37
- var statBGWriter = map [string ]* prometheus.Desc {
38
- "checkpoints_timed" : prometheus .NewDesc (
39
- prometheus .BuildFQName (namespace , bgWriterSubsystem , "checkpoints_timed_total" ),
40
- "Number of scheduled checkpoints that have been performed" ,
41
- []string {},
42
- prometheus.Labels {},
43
- ),
44
- "checkpoints_req" : prometheus .NewDesc (
45
- prometheus .BuildFQName (namespace , bgWriterSubsystem , "checkpoints_req_total" ),
46
- "Number of requested checkpoints that have been performed" ,
47
- []string {},
48
- prometheus.Labels {},
49
- ),
50
- "checkpoint_write_time" : prometheus .NewDesc (
51
- prometheus .BuildFQName (namespace , bgWriterSubsystem , "checkpoint_write_time_total" ),
52
- "Total amount of time that has been spent in the portion of checkpoint processing where files are written to disk, in milliseconds" ,
53
- []string {},
54
- prometheus.Labels {},
55
- ),
56
- "checkpoint_sync_time" : prometheus .NewDesc (
57
- prometheus .BuildFQName (namespace , bgWriterSubsystem , "checkpoint_sync_time_total" ),
58
- "Total amount of time that has been spent in the portion of checkpoint processing where files are synchronized to disk, in milliseconds" ,
59
- []string {},
60
- prometheus.Labels {},
61
- ),
62
- "buffers_checkpoint" : prometheus .NewDesc (
63
- prometheus .BuildFQName (namespace , bgWriterSubsystem , "buffers_checkpoint_total" ),
64
- "Number of buffers written during checkpoints" ,
65
- []string {},
66
- prometheus.Labels {},
67
- ),
68
- "buffers_clean" : prometheus .NewDesc (
69
- prometheus .BuildFQName (namespace , bgWriterSubsystem , "buffers_clean_total" ),
70
- "Number of buffers written by the background writer" ,
71
- []string {},
72
- prometheus.Labels {},
73
- ),
74
- "maxwritten_clean" : prometheus .NewDesc (
75
- prometheus .BuildFQName (namespace , bgWriterSubsystem , "maxwritten_clean_total" ),
76
- "Number of times the background writer stopped a cleaning scan because it had written too many buffers" ,
77
- []string {},
78
- prometheus.Labels {},
79
- ),
80
- "buffers_backend" : prometheus .NewDesc (
81
- prometheus .BuildFQName (namespace , bgWriterSubsystem , "buffers_backend_total" ),
82
- "Number of buffers written directly by a backend" ,
83
- []string {},
84
- prometheus.Labels {},
85
- ),
86
- "buffers_backend_fsync" : prometheus .NewDesc (
87
- prometheus .BuildFQName (namespace , bgWriterSubsystem , "buffers_backend_fsync_total" ),
88
- "Number of times a backend had to execute its own fsync call (normally the background writer handles those even when the backend does its own write)" ,
89
- []string {},
90
- prometheus.Labels {},
91
- ),
92
- "buffers_alloc" : prometheus .NewDesc (
93
- prometheus .BuildFQName (namespace , bgWriterSubsystem , "buffers_alloc_total" ),
94
- "Number of buffers allocated" ,
95
- []string {},
96
- prometheus.Labels {},
97
- ),
98
- "stats_reset" : prometheus .NewDesc (
99
- prometheus .BuildFQName (namespace , bgWriterSubsystem , "stats_reset_total" ),
100
- "Time at which these statistics were last reset" ,
101
- []string {},
102
- prometheus.Labels {},
103
- ),
104
- }
37
+ var statBGWriterCheckpointsTimed = prometheus .NewDesc (
38
+ prometheus .BuildFQName (namespace , bgWriterSubsystem , "checkpoints_timed_total" ),
39
+ "Number of scheduled checkpoints that have been performed" ,
40
+ []string {},
41
+ prometheus.Labels {},
42
+ )
43
+
44
+ var statBGWriterCheckpointsReq = prometheus .NewDesc (
45
+ prometheus .BuildFQName (namespace , bgWriterSubsystem , "checkpoints_req_total" ),
46
+ "Number of requested checkpoints that have been performed" ,
47
+ []string {},
48
+ prometheus.Labels {},
49
+ )
50
+
51
+ var statBGWriterCheckpointWriteTime = prometheus .NewDesc (
52
+ prometheus .BuildFQName (namespace , bgWriterSubsystem , "checkpoint_write_time_total" ),
53
+ "Total amount of time that has been spent in the portion of checkpoint processing where files are written to disk, in milliseconds" ,
54
+ []string {},
55
+ prometheus.Labels {},
56
+ )
57
+
58
+ var statBGWriterCheckpointSyncTime = prometheus .NewDesc (
59
+ prometheus .BuildFQName (namespace , bgWriterSubsystem , "checkpoint_sync_time_total" ),
60
+ "Total amount of time that has been spent in the portion of checkpoint processing where files are synchronized to disk, in milliseconds" ,
61
+ []string {},
62
+ prometheus.Labels {},
63
+ )
64
+
65
+ var statBGWriterBuffersCheckpoint = prometheus .NewDesc (
66
+ prometheus .BuildFQName (namespace , bgWriterSubsystem , "buffers_checkpoint_total" ),
67
+ "Number of buffers written during checkpoints" ,
68
+ []string {},
69
+ prometheus.Labels {},
70
+ )
71
+
72
+ var statBGWriterBuffersClean = prometheus .NewDesc (
73
+ prometheus .BuildFQName (namespace , bgWriterSubsystem , "buffers_clean_total" ),
74
+ "Number of buffers written by the background writer" ,
75
+ []string {},
76
+ prometheus.Labels {},
77
+ )
78
+
79
+ var statBGWriterMaxWrittenClean = prometheus .NewDesc (
80
+ prometheus .BuildFQName (namespace , bgWriterSubsystem , "maxwritten_clean_total" ),
81
+ "Number of times the background writer stopped a cleaning scan because it had written too many buffers" ,
82
+ []string {},
83
+ prometheus.Labels {},
84
+ )
85
+
86
+ var statBGWriterBuffersBackend = prometheus .NewDesc (
87
+ prometheus .BuildFQName (namespace , bgWriterSubsystem , "buffers_backend_total" ),
88
+ "Number of buffers written directly by a backend" ,
89
+ []string {},
90
+ prometheus.Labels {},
91
+ )
92
+
93
+ var statBGWriterBuffersBackendFsync = prometheus .NewDesc (
94
+ prometheus .BuildFQName (namespace , bgWriterSubsystem , "buffers_backend_fsync_total" ),
95
+ "Number of times a backend had to execute its own fsync call (normally the background writer handles those even when the backend does its own write)" ,
96
+ []string {},
97
+ prometheus.Labels {},
98
+ )
99
+
100
+ var statBGWriterBuffersAlloc = prometheus .NewDesc (
101
+ prometheus .BuildFQName (namespace , bgWriterSubsystem , "buffers_alloc_total" ),
102
+ "Number of buffers allocated" ,
103
+ []string {},
104
+ prometheus.Labels {},
105
+ )
106
+
107
+ var statBGWriterStatsReset = prometheus .NewDesc (
108
+ prometheus .BuildFQName (namespace , bgWriterSubsystem , "stats_reset_total" ),
109
+ "Time at which these statistics were last reset" ,
110
+ []string {},
111
+ prometheus.Labels {},
112
+ )
105
113
106
114
func (PGStatBGWriterCollector ) Update (ctx context.Context , db * sql.DB , ch chan <- prometheus.Metric ) error {
107
115
row := db .QueryRowContext (ctx ,
@@ -137,57 +145,57 @@ func (PGStatBGWriterCollector) Update(ctx context.Context, db *sql.DB, ch chan<-
137
145
}
138
146
139
147
ch <- prometheus .MustNewConstMetric (
140
- statBGWriter [ "checkpoints_timed" ] ,
148
+ statBGWriterCheckpointsTimed ,
141
149
prometheus .CounterValue ,
142
150
float64 (cpt ),
143
151
)
144
152
ch <- prometheus .MustNewConstMetric (
145
- statBGWriter [ "checkpoints_req" ] ,
153
+ statBGWriterCheckpointsReq ,
146
154
prometheus .CounterValue ,
147
155
float64 (cpr ),
148
156
)
149
157
ch <- prometheus .MustNewConstMetric (
150
- statBGWriter [ "checkpoint_write_time" ] ,
158
+ statBGWriterCheckpointWriteTime ,
151
159
prometheus .CounterValue ,
152
160
float64 (cpwt ),
153
161
)
154
162
ch <- prometheus .MustNewConstMetric (
155
- statBGWriter [ "checkpoint_sync_time" ] ,
163
+ statBGWriterCheckpointSyncTime ,
156
164
prometheus .CounterValue ,
157
165
float64 (cpst ),
158
166
)
159
167
ch <- prometheus .MustNewConstMetric (
160
- statBGWriter [ "buffers_checkpoint" ] ,
168
+ statBGWriterBuffersCheckpoint ,
161
169
prometheus .CounterValue ,
162
170
float64 (bcp ),
163
171
)
164
172
ch <- prometheus .MustNewConstMetric (
165
- statBGWriter [ "buffers_clean" ] ,
173
+ statBGWriterBuffersClean ,
166
174
prometheus .CounterValue ,
167
175
float64 (bc ),
168
176
)
169
177
ch <- prometheus .MustNewConstMetric (
170
- statBGWriter [ "maxwritten_clean" ] ,
178
+ statBGWriterMaxWrittenClean ,
171
179
prometheus .CounterValue ,
172
180
float64 (mwc ),
173
181
)
174
182
ch <- prometheus .MustNewConstMetric (
175
- statBGWriter [ "buffers_backend" ] ,
183
+ statBGWriterBuffersBackend ,
176
184
prometheus .CounterValue ,
177
185
float64 (bb ),
178
186
)
179
187
ch <- prometheus .MustNewConstMetric (
180
- statBGWriter [ "buffers_backend_fsync" ] ,
188
+ statBGWriterBuffersBackendFsync ,
181
189
prometheus .CounterValue ,
182
190
float64 (bbf ),
183
191
)
184
192
ch <- prometheus .MustNewConstMetric (
185
- statBGWriter [ "buffers_alloc" ] ,
193
+ statBGWriterBuffersAlloc ,
186
194
prometheus .CounterValue ,
187
195
float64 (ba ),
188
196
)
189
197
ch <- prometheus .MustNewConstMetric (
190
- statBGWriter [ "stats_reset" ] ,
198
+ statBGWriterStatsReset ,
191
199
prometheus .CounterValue ,
192
200
float64 (sr .Unix ()),
193
201
)
0 commit comments