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

Function newNetDev

net_dev.go:61–85  ·  view source on GitHub ↗

newNetDev creates a new NetDev from the contents of the given file.

(file string)

Source from the content-addressed store, hash-verified

59
60// newNetDev creates a new NetDev from the contents of the given file.
61func newNetDev(file string) (NetDev, error) {
62 f, err := os.Open(file)
63 if err != nil {
64 return NetDev{}, err
65 }
66 defer f.Close()
67
68 netDev := NetDev{}
69 s := bufio.NewScanner(f)
70 for n := 0; s.Scan(); n++ {
71 // Skip the 2 header lines.
72 if n < 2 {
73 continue
74 }
75
76 line, err := netDev.parseLine(s.Text())
77 if err != nil {
78 return netDev, err
79 }
80
81 netDev[line.Name] = *line
82 }
83
84 return netDev, s.Err()
85}
86
87// parseLine parses a single line from the /proc/net/dev file. Header lines
88// must be filtered prior to calling this method.

Callers 2

NetDevMethod · 0.85
NetDevMethod · 0.85

Calls 2

parseLineMethod · 0.95
ErrMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…