Skip to content

Invalid node_network_speed_bytes value -125000 for disconnected or virtualized NICs #1967

@svalouch

Description

@svalouch

After upgrading to version 1.1.0 from 0.18.x or older in an oVirt / KVM virtual environment, we noticed that the metric node_network_speed_bytes is reported as -125000 when the file /sys/class/net/<nic>/speed contains the value -1, while previously the metric returned 0. The same behavior can be observed on physical wired connections when there is no cable plugged in, as I've just verified with my Arch Linux laptop.

I'd understand if it returned -1 since that's whats in the file to indicate that this interface "has no speed" (essentially a sentinel value) because it is either a complicated implementation of memcpy (VM), or has no connection (physical interface w/o cable) and this indicates the absence of information about the speed of the interface.

I've bisected this to commit 3ddc82c in PR #1580, included from version 1.0.0-rc.0 onward. I'm not fluent in golang, but judging from the commit message, it seems that the early division caused it to essentially become 0 due to loss of precision, and thus it stayed at 0 when the multiplications were applied. After the PR was applied, the -1 is brought to a high negative number before the division and so stays distinctly different from the raw input value or the value of 0 returned in previous versions.

IMHO, the value 0 before #1580 was merged was not entirely correct, but nevertheless adequate to indicate "no speed information for whatever reason". The new value of -125000 most certainly is not correct, as it is neither a well-known sentinel value like -1 nor an accurate indication of the speed of any network interface.

Thus, I propose special-casing the value of -1 to return either:

  • -1 (absence of information) or
  • 0 to reinstate the previous behavior.

Host operating system: output of uname -a

Linux hostname 4.18.0-240.10.1.el8_3.x86_64 #1 SMP Mon Jan 18 17:05:51 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
CentOS 8.3 running in oVirt (KVM), also observed on Debian Buster on the same hypervisor

node_exporter version: output of node_exporter --version

node_exporter, version 1.1.0 (branch: tarball, revision: 1.1.0)
  build user:       someone@builder
  build date:       20210206-20:29:17
  go version:       go1.15.8
  platform:         linux/amd64

node_exporter command line flags

None

Are you running node_exporter in Docker?

No

What did you do that produced an error?

Update to 1.1.0 from 0.18.3

What did you expect to see?

Either the value returned by 0.18.3:

$ url -s localhost:9100/metrics | grep -E '^node_network_speed_bytes'
node_network_speed_bytes{device="ens3"} 0

Or ideally the raw value to indicate the absence of information, which would be:

node_network_speed_bytes{device="ens3"} -1

What did you see instead?

$ curl -s localhost:9100/metrics | grep -E '^node_network_speed_bytes'
node_network_speed_bytes{device="ens3"} -125000

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions