Skip to content

Commit e1b5fa2

Browse files
committed
Merge remote-tracking branch 'origin/refactor_collectors' into refactor_collectors
2 parents fe9ec39 + 878243c commit e1b5fa2

File tree

3 files changed

+107
-11
lines changed

3 files changed

+107
-11
lines changed

collector/zfs_freebsd.go

Lines changed: 98 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ package collector
1818

1919
import (
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

2630
type zfsCollector struct {
@@ -33,7 +37,7 @@ const (
3337
)
3438

3539
func init() {
36-
registerCollector("zfs", defaultEnabled, NewZfsCollector)
40+
registerCollector(zfsCollectorSubsystem, defaultEnabled, NewZfsCollector)
3741
}
3842

3943
func 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+
zfsDatasetNames := []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+
}

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ require (
2222
github.com/mdlayher/wifi v0.1.0
2323
github.com/opencontainers/selinux v1.11.0
2424
github.com/prometheus-community/go-runit v0.1.0
25-
github.com/prometheus/client_golang v1.16.0
26-
github.com/prometheus/client_model v0.4.0
25+
github.com/prometheus/client_golang v1.17.0
26+
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16
2727
github.com/prometheus/common v0.44.0
2828
github.com/prometheus/exporter-toolkit v0.10.0
2929
github.com/prometheus/procfs v0.11.1
@@ -58,6 +58,6 @@ require (
5858
golang.org/x/sync v0.3.0 // indirect
5959
golang.org/x/text v0.10.0 // indirect
6060
google.golang.org/appengine v1.6.7 // indirect
61-
google.golang.org/protobuf v1.30.0 // indirect
61+
google.golang.org/protobuf v1.31.0 // indirect
6262
gopkg.in/yaml.v2 v2.4.0 // indirect
6363
)

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
7676
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
7777
github.com/prometheus-community/go-runit v0.1.0 h1:uTWEj/Fn2RoLdfg/etSqwzgYNOYPrARx1BHUN052tGA=
7878
github.com/prometheus-community/go-runit v0.1.0/go.mod h1:AvJ9Jo3gAFu2lbM4+qfjdpq30FfiLDJZKbQ015u08IQ=
79-
github.com/prometheus/client_golang v1.16.0 h1:yk/hx9hDbrGHovbci4BY+pRMfSuuat626eFsHb7tmT8=
80-
github.com/prometheus/client_golang v1.16.0/go.mod h1:Zsulrv/L9oM40tJ7T815tM89lFEugiJ9HzIqaAx4LKc=
81-
github.com/prometheus/client_model v0.4.0 h1:5lQXD3cAg1OXBf4Wq03gTrXHeaV0TQvGfUooCfx1yqY=
82-
github.com/prometheus/client_model v0.4.0/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
79+
github.com/prometheus/client_golang v1.17.0 h1:rl2sfwZMtSthVU752MqfjQozy7blglC+1SOtjMAMh+Q=
80+
github.com/prometheus/client_golang v1.17.0/go.mod h1:VeL+gMmOAxkS2IqfCq0ZmHSL+LjWfWDUmp1mBz9JgUY=
81+
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16 h1:v7DLqVdK4VrYkVD5diGdl4sxJurKJEMnODWRJlxV9oM=
82+
github.com/prometheus/client_model v0.4.1-0.20230718164431-9a2bf3000d16/go.mod h1:oMQmHW1/JoDwqLtg57MGgP/Fb1CJEYF2imWWhWtMkYU=
8383
github.com/prometheus/common v0.44.0 h1:+5BrQJwiBB9xsMygAB3TNvpQKOwlkc25LbISbrdOOfY=
8484
github.com/prometheus/common v0.44.0/go.mod h1:ofAIvZbQ1e/nugmZGz4/qCb9Ap1VoSTIO7x0VV9VvuY=
8585
github.com/prometheus/exporter-toolkit v0.10.0 h1:yOAzZTi4M22ZzVxD+fhy1URTuNRj/36uQJJ5S8IPza8=
@@ -167,8 +167,8 @@ google.golang.org/appengine v1.6.7 h1:FZR1q0exgwxzPzp/aF+VccGrSfxfPpkBqjIIEq3ru6
167167
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
168168
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
169169
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
170-
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
171-
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
170+
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
171+
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
172172
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
173173
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
174174
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=

0 commit comments

Comments
 (0)