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

Function parseProcNetstat

proc_netstat.go:185–443  ·  view source on GitHub ↗

parseProcNetstat parses the metrics from proc/ /net/netstat file and returns a ProcNetstat structure.

(r io.Reader, fileName string)

Source from the content-addressed store, hash-verified

183// parseProcNetstat parses the metrics from proc/<pid>/net/netstat file
184// and returns a ProcNetstat structure.
185func parseProcNetstat(r io.Reader, fileName string) (ProcNetstat, error) {
186 var (
187 scanner = bufio.NewScanner(r)
188 procNetstat = ProcNetstat{}
189 )
190
191 for scanner.Scan() {
192 nameParts := strings.Split(scanner.Text(), " ")
193 scanner.Scan()
194 valueParts := strings.Split(scanner.Text(), " ")
195 // Remove trailing :.
196 protocol := strings.TrimSuffix(nameParts[0], ":")
197 if len(nameParts) != len(valueParts) {
198 return procNetstat, fmt.Errorf("%w: mismatch field count mismatch in %s: %s",
199 ErrFileParse, fileName, protocol)
200 }
201 for i := 1; i < len(nameParts); i++ {
202 value, err := strconv.ParseFloat(valueParts[i], 64)
203 if err != nil {
204 return procNetstat, err
205 }
206 key := nameParts[i]
207
208 switch protocol {
209 case "TcpExt":
210 switch key {
211 case "SyncookiesSent":
212 procNetstat.SyncookiesSent = &value
213 case "SyncookiesRecv":
214 procNetstat.SyncookiesRecv = &value
215 case "SyncookiesFailed":
216 procNetstat.SyncookiesFailed = &value
217 case "EmbryonicRsts":
218 procNetstat.EmbryonicRsts = &value
219 case "PruneCalled":
220 procNetstat.PruneCalled = &value
221 case "RcvPruned":
222 procNetstat.RcvPruned = &value
223 case "OfoPruned":
224 procNetstat.OfoPruned = &value
225 case "OutOfWindowIcmps":
226 procNetstat.OutOfWindowIcmps = &value
227 case "LockDroppedIcmps":
228 procNetstat.LockDroppedIcmps = &value
229 case "ArpFilter":
230 procNetstat.ArpFilter = &value
231 case "TW":
232 procNetstat.TW = &value
233 case "TWRecycled":
234 procNetstat.TWRecycled = &value
235 case "TWKilled":
236 procNetstat.TWKilled = &value
237 case "PAWSActive":
238 procNetstat.PAWSActive = &value
239 case "PAWSEstab":
240 procNetstat.PAWSEstab = &value
241 case "DelayedACKs":
242 procNetstat.DelayedACKs = &value

Callers 1

NetstatMethod · 0.85

Calls 1

ErrMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…