MCPcopy
hub / github.com/prometheus/node_exporter / Update

Method Update

collector/ethtool_linux.go:373–499  ·  view source on GitHub ↗
(ch chan<- prometheus.Metric)

Source from the content-addressed store, hash-verified

371}
372
373func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error {
374 netClass, err := c.fs.NetClassDevices()
375 if err != nil {
376 if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) {
377 c.logger.Debug("Could not read netclass file", "err", err)
378 return ErrNoData
379 }
380 return fmt.Errorf("could not get net class info: %w", err)
381 }
382
383 if len(netClass) == 0 {
384 return fmt.Errorf("no network devices found")
385 }
386
387 for _, device := range netClass {
388 var stats map[string]uint64
389 var err error
390
391 if c.deviceFilter.ignored(device) {
392 continue
393 }
394
395 linkInfo, err := c.ethtool.LinkInfo(device)
396 if err == nil {
397 c.updateSpeeds(ch, "supported", device, linkInfo.Supported)
398 c.updatePortInfo(ch, device, linkInfo.Supported)
399 c.updatePortCapabilities(ch, "supported", device, linkInfo.Supported)
400 c.updateSpeeds(ch, "advertised", device, linkInfo.Advertising)
401 c.updatePortCapabilities(ch, "advertised", device, linkInfo.Advertising)
402 ch <- prometheus.MustNewConstMetric(c.entry("autonegotiate"), prometheus.GaugeValue, float64(linkInfo.Autoneg), device)
403 } else {
404 if errno, ok := err.(syscall.Errno); ok {
405 if err == unix.EOPNOTSUPP {
406 c.logger.Debug("ethtool link info error", "err", err, "device", device, "errno", uint(errno))
407 } else if errno != 0 {
408 c.logger.Error("ethtool link info error", "err", err, "device", device, "errno", uint(errno))
409 }
410 } else {
411 c.logger.Error("ethtool link info error", "err", err, "device", device)
412 }
413 }
414
415 drvInfo, err := c.ethtool.DriverInfo(device)
416
417 if err == nil {
418 ch <- prometheus.MustNewConstMetric(c.infoDesc, prometheus.GaugeValue, 1.0,
419 drvInfo.BusInfo, device, drvInfo.Driver, drvInfo.EromVersion, drvInfo.FwVersion, drvInfo.Version)
420 } else {
421 if errno, ok := err.(syscall.Errno); ok {
422 if err == unix.EOPNOTSUPP {
423 c.logger.Debug("ethtool driver info error", "err", err, "device", device, "errno", uint(errno))
424 } else if errno != 0 {
425 c.logger.Error("ethtool driver info error", "err", err, "device", device, "errno", uint(errno))
426 }
427 } else {
428 c.logger.Error("ethtool driver info error", "err", err, "device", device)
429 }
430 }

Callers

nothing calls this directly

Calls 11

updateSpeedsMethod · 0.95
updatePortInfoMethod · 0.95
entryMethod · 0.95
entryWithCreateMethod · 0.95
SanitizeMetricNameFunction · 0.85
buildEthtoolFQNameFunction · 0.85
ignoredMethod · 0.80
LinkInfoMethod · 0.65
DriverInfoMethod · 0.65
StatsMethod · 0.65

Tested by

no test coverage detected