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

Method parseLine

net_protocols.go:98–146  ·  view source on GitHub ↗
(rawLine string)

Source from the content-addressed store, hash-verified

96}
97
98func (ps NetProtocolStats) parseLine(rawLine string) (*NetProtocolStatLine, error) {
99 line := &NetProtocolStatLine{Capabilities: NetProtocolCapabilities{}}
100 var err error
101 const enabled = "yes"
102 const disabled = "no"
103
104 fields := strings.Fields(rawLine)
105 line.Name = fields[0]
106 line.Size, err = strconv.ParseUint(fields[1], 10, 64)
107 if err != nil {
108 return nil, err
109 }
110 line.Sockets, err = strconv.ParseInt(fields[2], 10, 64)
111 if err != nil {
112 return nil, err
113 }
114 line.Memory, err = strconv.ParseInt(fields[3], 10, 64)
115 if err != nil {
116 return nil, err
117 }
118 switch fields[4] {
119 case enabled:
120 line.Pressure = 1
121 case disabled:
122 line.Pressure = 0
123 default:
124 line.Pressure = -1
125 }
126 line.MaxHeader, err = strconv.ParseUint(fields[5], 10, 64)
127 if err != nil {
128 return nil, err
129 }
130 switch fields[6] {
131 case enabled:
132 line.Slab = true
133 case disabled:
134 line.Slab = false
135 default:
136 return nil, fmt.Errorf("%w: capability for protocol: %s", ErrFileParse, line.Name)
137 }
138 line.ModuleName = fields[7]
139
140 err = line.Capabilities.parseCapabilities(fields[8:])
141 if err != nil {
142 return nil, err
143 }
144
145 return line, nil
146}
147
148func (pc *NetProtocolCapabilities) parseCapabilities(capabilities []string) error {
149 // The capabilities are all bools so we can loop over to map them

Callers 2

TestProtocolsParseLineFunction · 0.95
parseNetProtocolsFunction · 0.95

Calls 1

parseCapabilitiesMethod · 0.80

Tested by 1

TestProtocolsParseLineFunction · 0.76