MCPcopy
hub / github.com/prometheus/node_exporter / parsePoolProcfsFile

Method parsePoolProcfsFile

collector/zfs_linux.go:256–295  ·  view source on GitHub ↗
(reader io.Reader, zpoolPath string, handler func(string, zfsSysctl, uint64))

Source from the content-addressed store, hash-verified

254}
255
256func (c *zfsCollector) parsePoolProcfsFile(reader io.Reader, zpoolPath string, handler func(string, zfsSysctl, uint64)) error {
257 scanner := bufio.NewScanner(reader)
258
259 parseLine := false
260 var fields []string
261 for scanner.Scan() {
262 line := strings.Fields(scanner.Text())
263
264 if !parseLine && len(line) >= 12 && line[0] == "nread" {
265 //Start parsing from here.
266 parseLine = true
267 fields = make([]string, len(line))
268 copy(fields, line)
269 continue
270 }
271 if !parseLine {
272 continue
273 }
274
275 zpoolPathElements := strings.Split(zpoolPath, "/")
276 pathLen := len(zpoolPathElements)
277 if pathLen < 2 {
278 return fmt.Errorf("zpool path did not return at least two elements")
279 }
280 zpoolName := zpoolPathElements[pathLen-2]
281 zpoolFile := zpoolPathElements[pathLen-1]
282
283 for i, field := range fields {
284 key := fmt.Sprintf("kstat.zfs.misc.%s.%s", zpoolFile, field)
285
286 value, err := strconv.ParseUint(line[i], 10, 64)
287 if err != nil {
288 return fmt.Errorf("could not parse expected integer value for %q: %w", key, err)
289 }
290 handler(zpoolName, zfsSysctl(key), value)
291 }
292 }
293
294 return scanner.Err()
295}
296
297func (c *zfsCollector) parsePoolObjsetFile(reader io.Reader, zpoolPath string, handler func(string, string, zfsSysctl, uint64)) error {
298 scanner := bufio.NewScanner(reader)

Callers 2

TestZpoolParsingFunction · 0.95
updatePoolStatsMethod · 0.95

Calls 2

handlerStruct · 0.85
zfsSysctlTypeAlias · 0.85

Tested by 1

TestZpoolParsingFunction · 0.76