@@ -18,13 +18,9 @@ package collector
1818
1919import (
2020 "fmt"
21- "strings"
2221
2322 "github.com/go-kit/log"
24- "github.com/go-kit/log/level"
2523 "github.com/prometheus/client_golang/prometheus"
26-
27- "golang.org/x/sys/unix"
2824)
2925
3026type zfsCollector struct {
@@ -37,7 +33,7 @@ const (
3733)
3834
3935func init () {
40- registerCollector (zfsCollectorSubsystem , defaultEnabled , NewZfsCollector )
36+ registerCollector ("zfs" , defaultEnabled , NewZfsCollector )
4137}
4238
4339func NewZfsCollector (config * NodeCollectorConfig , logger log.Logger ) (Collector , error ) {
@@ -49,253 +45,202 @@ func NewZfsCollector(config *NodeCollectorConfig, logger log.Logger) (Collector,
4945 mib : "kstat.zfs.misc.abdstats.linear_cnt" ,
5046 dataType : bsdSysctlTypeUint64 ,
5147 valueType : prometheus .CounterValue ,
52- labels : nil ,
5348 },
5449 {
5550 name : "abdstats_linear_data_bytes" ,
5651 description : "ZFS ARC buffer data linear data size" ,
5752 mib : "kstat.zfs.misc.abdstats.linear_data_size" ,
5853 dataType : bsdSysctlTypeUint64 ,
5954 valueType : prometheus .GaugeValue ,
60- labels : nil ,
6155 },
6256 {
6357 name : "abdstats_scatter_chunk_waste_bytes" ,
6458 description : "ZFS ARC buffer data scatter chunk waste" ,
6559 mib : "kstat.zfs.misc.abdstats.scatter_chunk_waste" ,
6660 dataType : bsdSysctlTypeUint64 ,
6761 valueType : prometheus .GaugeValue ,
68- labels : nil ,
6962 },
7063 {
7164 name : "abdstats_scatter_count_total" ,
7265 description : "ZFS ARC buffer data scatter count" ,
7366 mib : "kstat.zfs.misc.abdstats.scatter_cnt" ,
7467 dataType : bsdSysctlTypeUint64 ,
7568 valueType : prometheus .CounterValue ,
76- labels : nil ,
7769 },
7870 {
7971 name : "abdstats_scatter_data_bytes" ,
8072 description : "ZFS ARC buffer data scatter data size" ,
8173 mib : "kstat.zfs.misc.abdstats.scatter_data_size" ,
8274 dataType : bsdSysctlTypeUint64 ,
8375 valueType : prometheus .GaugeValue ,
84- labels : nil ,
8576 },
8677 {
8778 name : "abdstats_struct_bytes" ,
8879 description : "ZFS ARC buffer data struct size" ,
8980 mib : "kstat.zfs.misc.abdstats.struct_size" ,
9081 dataType : bsdSysctlTypeUint64 ,
9182 valueType : prometheus .GaugeValue ,
92- labels : nil ,
9383 },
9484 {
9585 name : "arcstats_anon_bytes" ,
9686 description : "ZFS ARC anon size" ,
9787 mib : "kstat.zfs.misc.arcstats.anon_size" ,
9888 dataType : bsdSysctlTypeUint64 ,
9989 valueType : prometheus .GaugeValue ,
100- labels : nil ,
10190 },
10291 {
10392 name : "arcstats_c_bytes" ,
10493 description : "ZFS ARC target size" ,
10594 mib : "kstat.zfs.misc.arcstats.c" ,
10695 dataType : bsdSysctlTypeUint64 ,
10796 valueType : prometheus .GaugeValue ,
108- labels : nil ,
10997 },
11098 {
11199 name : "arcstats_c_max_bytes" ,
112100 description : "ZFS ARC maximum size" ,
113101 mib : "kstat.zfs.misc.arcstats.c_max" ,
114102 dataType : bsdSysctlTypeUint64 ,
115103 valueType : prometheus .GaugeValue ,
116- labels : nil ,
117104 },
118105 {
119106 name : "arcstats_c_min_bytes" ,
120107 description : "ZFS ARC minimum size" ,
121108 mib : "kstat.zfs.misc.arcstats.c_min" ,
122109 dataType : bsdSysctlTypeUint64 ,
123110 valueType : prometheus .GaugeValue ,
124- labels : nil ,
125111 },
126112 {
127113 name : "arcstats_data_bytes" ,
128114 description : "ZFS ARC data size" ,
129115 mib : "kstat.zfs.misc.arcstats.data_size" ,
130116 dataType : bsdSysctlTypeUint64 ,
131117 valueType : prometheus .GaugeValue ,
132- labels : nil ,
133118 },
134119 {
135120 name : "arcstats_demand_data_hits_total" ,
136121 description : "ZFS ARC demand data hits" ,
137122 mib : "kstat.zfs.misc.arcstats.demand_data_hits" ,
138123 dataType : bsdSysctlTypeUint64 ,
139124 valueType : prometheus .CounterValue ,
140- labels : nil ,
141125 },
142126 {
143127 name : "arcstats_demand_data_misses_total" ,
144128 description : "ZFS ARC demand data misses" ,
145129 mib : "kstat.zfs.misc.arcstats.demand_data_misses" ,
146130 dataType : bsdSysctlTypeUint64 ,
147131 valueType : prometheus .CounterValue ,
148- labels : nil ,
149132 },
150133 {
151134 name : "arcstats_demand_metadata_hits_total" ,
152135 description : "ZFS ARC demand metadata hits" ,
153136 mib : "kstat.zfs.misc.arcstats.demand_metadata_hits" ,
154137 dataType : bsdSysctlTypeUint64 ,
155138 valueType : prometheus .CounterValue ,
156- labels : nil ,
157139 },
158140 {
159141 name : "arcstats_demand_metadata_misses_total" ,
160142 description : "ZFS ARC demand metadata misses" ,
161143 mib : "kstat.zfs.misc.arcstats.demand_metadata_misses" ,
162144 dataType : bsdSysctlTypeUint64 ,
163145 valueType : prometheus .CounterValue ,
164- labels : nil ,
165146 },
166147 {
167148 name : "arcstats_hdr_bytes" ,
168149 description : "ZFS ARC header size" ,
169150 mib : "kstat.zfs.misc.arcstats.hdr_size" ,
170151 dataType : bsdSysctlTypeUint64 ,
171152 valueType : prometheus .GaugeValue ,
172- labels : nil ,
173153 },
174154 {
175155 name : "arcstats_hits_total" ,
176156 description : "ZFS ARC hits" ,
177157 mib : "kstat.zfs.misc.arcstats.hits" ,
178158 dataType : bsdSysctlTypeUint64 ,
179159 valueType : prometheus .CounterValue ,
180- labels : nil ,
181160 },
182161 {
183162 name : "arcstats_misses_total" ,
184163 description : "ZFS ARC misses" ,
185164 mib : "kstat.zfs.misc.arcstats.misses" ,
186165 dataType : bsdSysctlTypeUint64 ,
187166 valueType : prometheus .CounterValue ,
188- labels : nil ,
189167 },
190168 {
191169 name : "arcstats_mfu_ghost_hits_total" ,
192170 description : "ZFS ARC MFU ghost hits" ,
193171 mib : "kstat.zfs.misc.arcstats.mfu_ghost_hits" ,
194172 dataType : bsdSysctlTypeUint64 ,
195173 valueType : prometheus .CounterValue ,
196- labels : nil ,
197174 },
198175 {
199176 name : "arcstats_mfu_ghost_size" ,
200177 description : "ZFS ARC MFU ghost size" ,
201178 mib : "kstat.zfs.misc.arcstats.mfu_ghost_size" ,
202179 dataType : bsdSysctlTypeUint64 ,
203180 valueType : prometheus .GaugeValue ,
204- labels : nil ,
205181 },
206182 {
207183 name : "arcstats_mfu_bytes" ,
208184 description : "ZFS ARC MFU size" ,
209185 mib : "kstat.zfs.misc.arcstats.mfu_size" ,
210186 dataType : bsdSysctlTypeUint64 ,
211187 valueType : prometheus .GaugeValue ,
212- labels : nil ,
213188 },
214189 {
215190 name : "arcstats_mru_ghost_hits_total" ,
216191 description : "ZFS ARC MRU ghost hits" ,
217192 mib : "kstat.zfs.misc.arcstats.mru_ghost_hits" ,
218193 dataType : bsdSysctlTypeUint64 ,
219194 valueType : prometheus .CounterValue ,
220- labels : nil ,
221195 },
222196 {
223197 name : "arcstats_mru_ghost_bytes" ,
224198 description : "ZFS ARC MRU ghost size" ,
225199 mib : "kstat.zfs.misc.arcstats.mru_ghost_size" ,
226200 dataType : bsdSysctlTypeUint64 ,
227201 valueType : prometheus .GaugeValue ,
228- labels : nil ,
229202 },
230203 {
231204 name : "arcstats_mru_bytes" ,
232205 description : "ZFS ARC MRU size" ,
233206 mib : "kstat.zfs.misc.arcstats.mru_size" ,
234207 dataType : bsdSysctlTypeUint64 ,
235208 valueType : prometheus .GaugeValue ,
236- labels : nil ,
237209 },
238210 {
239211 name : "arcstats_other_bytes" ,
240212 description : "ZFS ARC other size" ,
241213 mib : "kstat.zfs.misc.arcstats.other_size" ,
242214 dataType : bsdSysctlTypeUint64 ,
243215 valueType : prometheus .GaugeValue ,
244- labels : nil ,
245216 },
246- // when FreeBSD 14.0+, `meta/pm/pd` install of `p`.
247217 {
248218 name : "arcstats_p_bytes" ,
249219 description : "ZFS ARC MRU target size" ,
250220 mib : "kstat.zfs.misc.arcstats.p" ,
251221 dataType : bsdSysctlTypeUint64 ,
252222 valueType : prometheus .GaugeValue ,
253- labels : nil ,
254- },
255- {
256- name : "arcstats_meta_bytes" ,
257- description : "ZFS ARC metadata target frac " ,
258- mib : "kstat.zfs.misc.arcstats.meta" ,
259- dataType : bsdSysctlTypeUint64 ,
260- valueType : prometheus .GaugeValue ,
261- },
262- {
263- name : "arcstats_pd_bytes" ,
264- description : "ZFS ARC data MRU target frac" ,
265- mib : "kstat.zfs.misc.arcstats.pd" ,
266- dataType : bsdSysctlTypeUint64 ,
267- valueType : prometheus .GaugeValue ,
268- },
269- {
270- name : "arcstats_pm_bytes" ,
271- description : "ZFS ARC meta MRU target frac" ,
272- mib : "kstat.zfs.misc.arcstats.pm" ,
273- dataType : bsdSysctlTypeUint64 ,
274- valueType : prometheus .GaugeValue ,
275223 },
276224 {
277225 name : "arcstats_size_bytes" ,
278226 description : "ZFS ARC size" ,
279227 mib : "kstat.zfs.misc.arcstats.size" ,
280228 dataType : bsdSysctlTypeUint64 ,
281229 valueType : prometheus .GaugeValue ,
282- labels : nil ,
283230 },
284231 {
285232 name : "zfetchstats_hits_total" ,
286233 description : "ZFS cache fetch hits" ,
287234 mib : "kstat.zfs.misc.zfetchstats.hits" ,
288235 dataType : bsdSysctlTypeUint64 ,
289236 valueType : prometheus .CounterValue ,
290- labels : nil ,
291237 },
292238 {
293239 name : "zfetchstats_misses_total" ,
294240 description : "ZFS cache fetch misses" ,
295241 mib : "kstat.zfs.misc.zfetchstats.misses" ,
296242 dataType : bsdSysctlTypeUint64 ,
297243 valueType : prometheus .CounterValue ,
298- labels : nil ,
299244 },
300245 },
301246 logger : logger ,
@@ -306,9 +251,7 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error {
306251 for _ , m := range c .sysctls {
307252 v , err := m .Value ()
308253 if err != nil {
309- // debug logging
310- level .Debug (c .logger ).Log ("name" , m .name , "couldn't get sysctl:" , err )
311- continue
254+ return fmt .Errorf ("couldn't get sysctl: %w" , err )
312255 }
313256
314257 ch <- prometheus .MustNewConstMetric (
@@ -321,42 +264,3 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error {
321264
322265 return nil
323266}
324-
325- func (c * zfsCollector ) parseFreeBSDPoolObjsetStats () error {
326-
327- sysCtlMetrics := []string {
328- "nunlinked" , "nunlinks" , "nread" , "reads" , "nwritten" , "writes" ,
329- }
330- zfsPoolMibPrefix := "kstat.zfs.pool.dataset"
331- zfsDatasetsNames := []string {}
332-
333- zfsDatasets , err := unix .Sysctl (zfsPoolMibPrefix )
334- if err != nil {
335- return fmt .Errorf ("couldn't get sysctl: %w" , err )
336- }
337-
338- for dataset , _ := range zfsDatasets {
339- if strings .HasSuffix (dataset , ".dataset_name" ) {
340- zfsDatasetNames = append (zfsDatasetNames , strings .SplitAfter (dataset , "." )[3 ])
341- }
342- }
343-
344- for zpoolDataset := range zfsDatasetsNames {
345- zfsDatasetLabels := map [string ]string {
346- "dataset" : zpoolDataset ,
347- "zpool" : strings .SplitAfter (zpoolDataset , "/" )[0 ],
348- }
349- for metric := range sysCtlMetrics {
350- c .sysctls = append (c .sysctls , bsdSysctl {
351- name : fmt .SprintF ("node_zfs_zpool_dataset_%s" , metric ),
352- description : fmt .SprintF ("node_zfs_zpool_dataset_%s" , metric ),
353- mib : fmt .Sprintf ("%s.%s.%s" , zfsPoolMibPrefix , poolObj , metric ),
354- dataType : bsdSysctlTypeUint64 ,
355- valueType : prometheus .CounterValue ,
356- labels : zfsDatasetLabels ,
357- })
358- }
359- }
360-
361- return nil
362- }
0 commit comments