MCPcopy Create free account
hub / github.com/CovenantSQL/CovenantSQL / Update

Method Update

metric/diskstats_linux.go:161–187  ·  view source on GitHub ↗
(ch chan<- prometheus.Metric)

Source from the content-addressed store, hash-verified

159}
160
161func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
162 procDiskStats := procFilePath("diskstats")
163 diskStats, err := getDiskStats()
164 if err != nil {
165 return fmt.Errorf("couldn't get diskstats: %s", err)
166 }
167
168 for dev, stats := range diskStats {
169 if c.ignoredDevicesPattern.MatchString(dev) {
170 log.Debugf("ignoring device: %s", dev)
171 continue
172 }
173
174 if len(stats) != len(c.descs) {
175 return fmt.Errorf("invalid line for %s for %s", procDiskStats, dev)
176 }
177
178 for i, value := range stats {
179 v, err := strconv.ParseFloat(value, 64)
180 if err != nil {
181 return fmt.Errorf("invalid value %s in diskstats: %s", value, err)
182 }
183 ch <- c.descs[i].mustNewConstMetric(v, dev)
184 }
185 }
186 return nil
187}
188
189func getDiskStats() (map[string]map[int]string, error) {
190 file, err := os.Open(procFilePath("diskstats"))

Callers

nothing calls this directly

Calls 5

DebugfFunction · 0.92
procFilePathFunction · 0.85
getDiskStatsFunction · 0.85
ErrorfMethod · 0.80
mustNewConstMetricMethod · 0.45

Tested by

no test coverage detected