@@ -18,9 +18,13 @@ package collector
1818
1919import (
2020 "fmt"
21+ "strings"
2122
2223 "github.com/go-kit/log"
24+ "github.com/go-kit/log/level"
2325 "github.com/prometheus/client_golang/prometheus"
26+
27+ "golang.org/x/sys/unix"
2428)
2529
2630type zfsCollector struct {
@@ -33,7 +37,7 @@ const (
3337)
3438
3539func init () {
36- registerCollector ("zfs" , defaultEnabled , NewZfsCollector )
40+ registerCollector (zfsCollectorSubsystem , defaultEnabled , NewZfsCollector )
3741}
3842
3943func NewZfsCollector (config * NodeCollectorConfig , logger log.Logger ) (Collector , error ) {
@@ -45,202 +49,253 @@ func NewZfsCollector(config *NodeCollectorConfig, logger log.Logger) (Collector,
4549 mib : "kstat.zfs.misc.abdstats.linear_cnt" ,
4650 dataType : bsdSysctlTypeUint64 ,
4751 valueType : prometheus .CounterValue ,
52+ labels : nil ,
4853 },
4954 {
5055 name : "abdstats_linear_data_bytes" ,
5156 description : "ZFS ARC buffer data linear data size" ,
5257 mib : "kstat.zfs.misc.abdstats.linear_data_size" ,
5358 dataType : bsdSysctlTypeUint64 ,
5459 valueType : prometheus .GaugeValue ,
60+ labels : nil ,
5561 },
5662 {
5763 name : "abdstats_scatter_chunk_waste_bytes" ,
5864 description : "ZFS ARC buffer data scatter chunk waste" ,
5965 mib : "kstat.zfs.misc.abdstats.scatter_chunk_waste" ,
6066 dataType : bsdSysctlTypeUint64 ,
6167 valueType : prometheus .GaugeValue ,
68+ labels : nil ,
6269 },
6370 {
6471 name : "abdstats_scatter_count_total" ,
6572 description : "ZFS ARC buffer data scatter count" ,
6673 mib : "kstat.zfs.misc.abdstats.scatter_cnt" ,
6774 dataType : bsdSysctlTypeUint64 ,
6875 valueType : prometheus .CounterValue ,
76+ labels : nil ,
6977 },
7078 {
7179 name : "abdstats_scatter_data_bytes" ,
7280 description : "ZFS ARC buffer data scatter data size" ,
7381 mib : "kstat.zfs.misc.abdstats.scatter_data_size" ,
7482 dataType : bsdSysctlTypeUint64 ,
7583 valueType : prometheus .GaugeValue ,
84+ labels : nil ,
7685 },
7786 {
7887 name : "abdstats_struct_bytes" ,
7988 description : "ZFS ARC buffer data struct size" ,
8089 mib : "kstat.zfs.misc.abdstats.struct_size" ,
8190 dataType : bsdSysctlTypeUint64 ,
8291 valueType : prometheus .GaugeValue ,
92+ labels : nil ,
8393 },
8494 {
8595 name : "arcstats_anon_bytes" ,
8696 description : "ZFS ARC anon size" ,
8797 mib : "kstat.zfs.misc.arcstats.anon_size" ,
8898 dataType : bsdSysctlTypeUint64 ,
8999 valueType : prometheus .GaugeValue ,
100+ labels : nil ,
90101 },
91102 {
92103 name : "arcstats_c_bytes" ,
93104 description : "ZFS ARC target size" ,
94105 mib : "kstat.zfs.misc.arcstats.c" ,
95106 dataType : bsdSysctlTypeUint64 ,
96107 valueType : prometheus .GaugeValue ,
108+ labels : nil ,
97109 },
98110 {
99111 name : "arcstats_c_max_bytes" ,
100112 description : "ZFS ARC maximum size" ,
101113 mib : "kstat.zfs.misc.arcstats.c_max" ,
102114 dataType : bsdSysctlTypeUint64 ,
103115 valueType : prometheus .GaugeValue ,
116+ labels : nil ,
104117 },
105118 {
106119 name : "arcstats_c_min_bytes" ,
107120 description : "ZFS ARC minimum size" ,
108121 mib : "kstat.zfs.misc.arcstats.c_min" ,
109122 dataType : bsdSysctlTypeUint64 ,
110123 valueType : prometheus .GaugeValue ,
124+ labels : nil ,
111125 },
112126 {
113127 name : "arcstats_data_bytes" ,
114128 description : "ZFS ARC data size" ,
115129 mib : "kstat.zfs.misc.arcstats.data_size" ,
116130 dataType : bsdSysctlTypeUint64 ,
117131 valueType : prometheus .GaugeValue ,
132+ labels : nil ,
118133 },
119134 {
120135 name : "arcstats_demand_data_hits_total" ,
121136 description : "ZFS ARC demand data hits" ,
122137 mib : "kstat.zfs.misc.arcstats.demand_data_hits" ,
123138 dataType : bsdSysctlTypeUint64 ,
124139 valueType : prometheus .CounterValue ,
140+ labels : nil ,
125141 },
126142 {
127143 name : "arcstats_demand_data_misses_total" ,
128144 description : "ZFS ARC demand data misses" ,
129145 mib : "kstat.zfs.misc.arcstats.demand_data_misses" ,
130146 dataType : bsdSysctlTypeUint64 ,
131147 valueType : prometheus .CounterValue ,
148+ labels : nil ,
132149 },
133150 {
134151 name : "arcstats_demand_metadata_hits_total" ,
135152 description : "ZFS ARC demand metadata hits" ,
136153 mib : "kstat.zfs.misc.arcstats.demand_metadata_hits" ,
137154 dataType : bsdSysctlTypeUint64 ,
138155 valueType : prometheus .CounterValue ,
156+ labels : nil ,
139157 },
140158 {
141159 name : "arcstats_demand_metadata_misses_total" ,
142160 description : "ZFS ARC demand metadata misses" ,
143161 mib : "kstat.zfs.misc.arcstats.demand_metadata_misses" ,
144162 dataType : bsdSysctlTypeUint64 ,
145163 valueType : prometheus .CounterValue ,
164+ labels : nil ,
146165 },
147166 {
148167 name : "arcstats_hdr_bytes" ,
149168 description : "ZFS ARC header size" ,
150169 mib : "kstat.zfs.misc.arcstats.hdr_size" ,
151170 dataType : bsdSysctlTypeUint64 ,
152171 valueType : prometheus .GaugeValue ,
172+ labels : nil ,
153173 },
154174 {
155175 name : "arcstats_hits_total" ,
156176 description : "ZFS ARC hits" ,
157177 mib : "kstat.zfs.misc.arcstats.hits" ,
158178 dataType : bsdSysctlTypeUint64 ,
159179 valueType : prometheus .CounterValue ,
180+ labels : nil ,
160181 },
161182 {
162183 name : "arcstats_misses_total" ,
163184 description : "ZFS ARC misses" ,
164185 mib : "kstat.zfs.misc.arcstats.misses" ,
165186 dataType : bsdSysctlTypeUint64 ,
166187 valueType : prometheus .CounterValue ,
188+ labels : nil ,
167189 },
168190 {
169191 name : "arcstats_mfu_ghost_hits_total" ,
170192 description : "ZFS ARC MFU ghost hits" ,
171193 mib : "kstat.zfs.misc.arcstats.mfu_ghost_hits" ,
172194 dataType : bsdSysctlTypeUint64 ,
173195 valueType : prometheus .CounterValue ,
196+ labels : nil ,
174197 },
175198 {
176199 name : "arcstats_mfu_ghost_size" ,
177200 description : "ZFS ARC MFU ghost size" ,
178201 mib : "kstat.zfs.misc.arcstats.mfu_ghost_size" ,
179202 dataType : bsdSysctlTypeUint64 ,
180203 valueType : prometheus .GaugeValue ,
204+ labels : nil ,
181205 },
182206 {
183207 name : "arcstats_mfu_bytes" ,
184208 description : "ZFS ARC MFU size" ,
185209 mib : "kstat.zfs.misc.arcstats.mfu_size" ,
186210 dataType : bsdSysctlTypeUint64 ,
187211 valueType : prometheus .GaugeValue ,
212+ labels : nil ,
188213 },
189214 {
190215 name : "arcstats_mru_ghost_hits_total" ,
191216 description : "ZFS ARC MRU ghost hits" ,
192217 mib : "kstat.zfs.misc.arcstats.mru_ghost_hits" ,
193218 dataType : bsdSysctlTypeUint64 ,
194219 valueType : prometheus .CounterValue ,
220+ labels : nil ,
195221 },
196222 {
197223 name : "arcstats_mru_ghost_bytes" ,
198224 description : "ZFS ARC MRU ghost size" ,
199225 mib : "kstat.zfs.misc.arcstats.mru_ghost_size" ,
200226 dataType : bsdSysctlTypeUint64 ,
201227 valueType : prometheus .GaugeValue ,
228+ labels : nil ,
202229 },
203230 {
204231 name : "arcstats_mru_bytes" ,
205232 description : "ZFS ARC MRU size" ,
206233 mib : "kstat.zfs.misc.arcstats.mru_size" ,
207234 dataType : bsdSysctlTypeUint64 ,
208235 valueType : prometheus .GaugeValue ,
236+ labels : nil ,
209237 },
210238 {
211239 name : "arcstats_other_bytes" ,
212240 description : "ZFS ARC other size" ,
213241 mib : "kstat.zfs.misc.arcstats.other_size" ,
214242 dataType : bsdSysctlTypeUint64 ,
215243 valueType : prometheus .GaugeValue ,
244+ labels : nil ,
216245 },
246+ // when FreeBSD 14.0+, `meta/pm/pd` install of `p`.
217247 {
218248 name : "arcstats_p_bytes" ,
219249 description : "ZFS ARC MRU target size" ,
220250 mib : "kstat.zfs.misc.arcstats.p" ,
221251 dataType : bsdSysctlTypeUint64 ,
222252 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 ,
223275 },
224276 {
225277 name : "arcstats_size_bytes" ,
226278 description : "ZFS ARC size" ,
227279 mib : "kstat.zfs.misc.arcstats.size" ,
228280 dataType : bsdSysctlTypeUint64 ,
229281 valueType : prometheus .GaugeValue ,
282+ labels : nil ,
230283 },
231284 {
232285 name : "zfetchstats_hits_total" ,
233286 description : "ZFS cache fetch hits" ,
234287 mib : "kstat.zfs.misc.zfetchstats.hits" ,
235288 dataType : bsdSysctlTypeUint64 ,
236289 valueType : prometheus .CounterValue ,
290+ labels : nil ,
237291 },
238292 {
239293 name : "zfetchstats_misses_total" ,
240294 description : "ZFS cache fetch misses" ,
241295 mib : "kstat.zfs.misc.zfetchstats.misses" ,
242296 dataType : bsdSysctlTypeUint64 ,
243297 valueType : prometheus .CounterValue ,
298+ labels : nil ,
244299 },
245300 },
246301 logger : logger ,
@@ -251,7 +306,9 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error {
251306 for _ , m := range c .sysctls {
252307 v , err := m .Value ()
253308 if err != nil {
254- return fmt .Errorf ("couldn't get sysctl: %w" , err )
309+ // debug logging
310+ level .Debug (c .logger ).Log ("name" , m .name , "couldn't get sysctl:" , err )
311+ continue
255312 }
256313
257314 ch <- prometheus .MustNewConstMetric (
@@ -264,3 +321,42 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error {
264321
265322 return nil
266323}
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+ zfsDatasetsNames = append (zfsDatasetsNames , 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