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

Function parseNFSTransportStats

mountstats.go:596–710  ·  view source on GitHub ↗

parseNFSTransportStats parses a NFSTransportStats line using an input set of integer fields matched to a specific stats version.

(ss []string, statVersion string)

Source from the content-addressed store, hash-verified

594// parseNFSTransportStats parses a NFSTransportStats line using an input set of
595// integer fields matched to a specific stats version.
596func parseNFSTransportStats(ss []string, statVersion string) (*NFSTransportStats, error) {
597 // Extract the protocol field. It is the only string value in the line
598 protocol := ss[0]
599 ss = ss[1:]
600
601 switch statVersion {
602 case statVersion10:
603 var expectedLength int
604 switch protocol {
605 case "tcp":
606 expectedLength = fieldTransport10TCPLen
607 case "udp":
608 expectedLength = fieldTransport10UDPLen
609 default:
610 return nil, fmt.Errorf("%w: Invalid NFS protocol \"%s\" in stats 1.0 statement: %v", ErrFileParse, protocol, ss)
611 }
612 if len(ss) != expectedLength {
613 return nil, fmt.Errorf("%w: Invalid NFS transport stats 1.0 statement: %v", ErrFileParse, ss)
614 }
615 case statVersion11:
616 var expectedLength int
617 switch protocol {
618 case "tcp":
619 expectedLength = fieldTransport11TCPLen
620 case "udp":
621 expectedLength = fieldTransport11UDPLen
622 case "rdma":
623 expectedLength = fieldTransport11RDMAMinLen
624 default:
625 return nil, fmt.Errorf("%w: invalid NFS protocol \"%s\" in stats 1.1 statement: %v", ErrFileParse, protocol, ss)
626 }
627 if (len(ss) != expectedLength && (protocol == "tcp" || protocol == "udp")) ||
628 (protocol == "rdma" && len(ss) < expectedLength) {
629 return nil, fmt.Errorf("%w: invalid NFS transport stats 1.1 statement: %v, protocol: %v", ErrFileParse, ss, protocol)
630 }
631 default:
632 return nil, fmt.Errorf("%w: Unrecognized NFS transport stats version: %q, protocol: %v", ErrFileParse, statVersion, protocol)
633 }
634
635 // Allocate enough for v1.1 stats since zero value for v1.1 stats will be okay
636 // in a v1.0 response. Since the stat length is bigger for TCP stats, we use
637 // the TCP length here.
638 //
639 // Note: slice length must be set to length of v1.1 stats to avoid a panic when
640 // only v1.0 stats are present.
641 // See: https://github.com/prometheus/node_exporter/issues/571.
642 //
643 // Note: NFS Over RDMA slice length is fieldTransport11RDMAMaxLen
644 ns := make([]uint64, fieldTransport11RDMAMaxLen+3)
645 for i, s := range ss {
646 n, err := strconv.ParseUint(s, 10, 64)
647 if err != nil {
648 return nil, err
649 }
650
651 ns[i] = n
652 }
653

Callers 1

parseMountStatsNFSFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected