MCPcopy Create free account
hub / github.com/prometheus/procfs / parseDeviceIOErrors

Function parseDeviceIOErrors

bcachefs/get.go:536–583  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

534}
535
536func parseDeviceIOErrors(path string) (map[string]uint64, error) {
537 file, err := openIfExists(path)
538 if err != nil {
539 return nil, err
540 }
541 if file == nil {
542 return map[string]uint64{}, nil
543 }
544 defer file.Close()
545
546 stats := make(map[string]uint64)
547 scanner := bufio.NewScanner(file)
548 inCreationSection := false
549
550 for scanner.Scan() {
551 line := scanner.Text()
552 if strings.HasPrefix(line, "IO errors since filesystem creation") {
553 inCreationSection = true
554 continue
555 }
556 if strings.HasPrefix(line, "IO errors since ") {
557 break
558 }
559 if !inCreationSection {
560 continue
561 }
562 trimmed := strings.TrimSpace(line)
563 if trimmed == "" {
564 continue
565 }
566 parts := strings.SplitN(trimmed, ":", 2)
567 if len(parts) != 2 {
568 continue
569 }
570 errorType := strings.TrimSpace(parts[0])
571 valueStr := strings.TrimSpace(parts[1])
572 value, err := strconv.ParseUint(valueStr, 10, 64)
573 if err != nil {
574 return nil, err
575 }
576 stats[errorType] = value
577 }
578
579 if err := scanner.Err(); err != nil {
580 return nil, err
581 }
582 return stats, nil
583}
584
585func openIfExists(path string) (*os.File, error) {
586 file, err := os.Open(path)

Callers 1

parseDevicesFunction · 0.85

Calls 2

openIfExistsFunction · 0.85
ErrMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…