MCPcopy
hub / github.com/influxdata/telegraf / readUdevData

Function readUdevData

plugins/inputs/diskio/diskio_linux.go:91–130  ·  view source on GitHub ↗
(path string)

Source from the content-addressed store, hash-verified

89}
90
91func readUdevData(path string) (map[string]string, error) {
92 // Final open of the confirmed (or the previously detected/used) udev file
93 f, err := os.Open(path)
94 if err != nil {
95 return nil, err
96 }
97 defer f.Close()
98
99 info := make(map[string]string)
100 scnr := bufio.NewScanner(f)
101 var devlinks bytes.Buffer
102 for scnr.Scan() {
103 l := scnr.Text()
104 if len(l) < 4 {
105 continue
106 }
107 if l[:2] == "S:" {
108 if devlinks.Len() > 0 {
109 devlinks.WriteString(" ")
110 }
111 devlinks.WriteString("/dev/")
112 devlinks.WriteString(l[2:])
113 continue
114 }
115 if l[:2] != "E:" {
116 continue
117 }
118 kv := strings.SplitN(l[2:], "=", 2)
119 if len(kv) < 2 {
120 continue
121 }
122 info[kv[0]] = kv[1]
123 }
124
125 if devlinks.Len() > 0 {
126 info["DEVLINKS"] = devlinks.String()
127 }
128
129 return info, nil
130}
131
132func readDevData(path, sysPath string) (map[string]string, error) {
133 // Open the file and read line-wise

Callers 1

diskInfoMethod · 0.85

Calls 4

LenMethod · 0.95
CloseMethod · 0.65
ScanMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…