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

Method parsePoolStateFile

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

Source from the content-addressed store, hash-verified

336}
337
338func (c *zfsCollector) parsePoolStateFile(reader io.Reader, zpoolPath string, handler func(string, string, uint64)) error {
339 scanner := bufio.NewScanner(reader)
340 scanner.Scan()
341
342 actualStateName, err := scanner.Text(), scanner.Err()
343 if err != nil {
344 return err
345 }
346
347 actualStateName = strings.ToLower(actualStateName)
348
349 zpoolPathElements := strings.Split(zpoolPath, "/")
350 pathLen := len(zpoolPathElements)
351 if pathLen < 2 {
352 return fmt.Errorf("zpool path did not return at least two elements")
353 }
354
355 zpoolName := zpoolPathElements[pathLen-2]
356
357 for _, stateName := range zfsPoolStatesName {
358 isActive := uint64(0)
359
360 if actualStateName == stateName {
361 isActive = 1
362 }
363
364 handler(zpoolName, stateName, isActive)
365 }
366
367 return nil
368}
369
370func (c *zfsCollector) constSysctlMetric(subsystem string, sysctl zfsSysctl, value float64) prometheus.Metric {
371 metricName := sysctl.metricName()

Callers 2

TestPoolStateParsingFunction · 0.95
updatePoolStatsMethod · 0.95

Calls 1

handlerStruct · 0.85

Tested by 1

TestPoolStateParsingFunction · 0.76