Skip to content

[receiver/hostmetrics] Add system.network.bandwidth.limit metric#49361

Open
emmayusufu wants to merge 2 commits into
open-telemetry:mainfrom
emmayusufu:hostmetrics-network-bandwidth-limit
Open

[receiver/hostmetrics] Add system.network.bandwidth.limit metric#49361
emmayusufu wants to merge 2 commits into
open-telemetry:mainfrom
emmayusufu:hostmetrics-network-bandwidth-limit

Conversation

@emmayusufu

Copy link
Copy Markdown

Description

The network scraper exposes byte, packet, error, dropped, connection, and conntrack metrics, but nothing for link capacity. Consumers can derive byte rates from system.network.io but can't compute interface saturation without the NIC link speed.

This adds an optional, disabled-by-default system.network.bandwidth.limit gauge (unit By/s, attribute device). On Linux it reads the interface link speed from /sys/class/net/<device>/speed (honoring HOST_SYS) and converts Mbit/s to bytes/s. It's a no-op on other platforms, and interfaces that report -1 (virtual or down links) are skipped.

I scoped this to the bandwidth limit only. The utilization metric from the issue can follow once the limit lands, since it needs prev-sample delta tracking.

Link to tracking issue

Part of #49169

Testing

Added a unit test for the sysfs speed read (valid speed, -1, unparseable, missing interface). Regenerated with mdatagen; go test ./... and GOOS=linux go vet ./... pass.

Documentation

Regenerated documentation.md via mdatagen and added a changelog entry.

The network scraper exposed byte, packet, error, and conntrack metrics but nothing for link capacity, so consumers could not compute interface saturation. This adds an optional, disabled-by-default system.network.bandwidth.limit gauge that reads the NIC link speed from sysfs on Linux and reports it in bytes/s.

Signed-off-by: Emmanuel Yusufu Kimaswa <kimaswaemma36@gmail.com>
@emmayusufu emmayusufu requested review from a team, braydonk and dmitryax as code owners June 29, 2026 19:54
@github-actions github-actions Bot added the first-time contributor PRs made by new contributors label Jun 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Welcome, contributor! Thank you for your contribution to opentelemetry-collector-contrib.

Important reminders:

  • Read our Contributing Guidelines.
  • Sign the CLA if you haven't already.
  • First-time contributors should have at most one PR not marked as draft until their first PR is merged.
  • If your change isn't one of our priority components, reviews may take more time.
  • Give reviewers at least a few days before pinging them for feedback.
  • If you need help or struggle to move your PR forward:

stability: development
gauge:
value_type: int
attributes: [device]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be using network.interface.name & network.io.direction attributes.

@emmayusufu

Copy link
Copy Markdown
Author

Thanks for the review.

For the interface attribute, I used device to match the rest of this scraper. Every metric in the network scraper, and the wider hostmetrics receiver, uses device, and there's no network.interface.name or migration gate in the receiver today, so putting semconv attributes on just this metric would leave it inconsistent with system.network.io, system.network.packets, and the others. Moving to network.interface.name looks like a receiver-wide migration with a feature gate for backward compatibility, rather than something to start on a single new metric. I can switch this one if you'd rather, but I leaned toward consistency.

On network.io.direction: system.network.bandwidth.limit is the interface's link capacity, which isn't directional. The directional metrics (io, packets, errors) carry direction, but link speed is the same for receive and transmit on a full-duplex link, so adding it would just duplicate the value. I left it off for that reason. If you have a per-direction capacity in mind, let me know and I'll add it.

@thompson-tomo

Copy link
Copy Markdown
Contributor

Actually the guidance in the developers docs is to use the semconv and that is what alot of other scrapers/receivers do.

In relation to limit, the use cases is as described in https://opentelemetry.io/docs/specs/semconv/general/naming/#instrument-naming which is the limit metric pairs with usage metric to give utilization.

Switch to network.interface.name and network.io.direction per review. The limit is emitted per direction since a full-duplex link carries the capacity each way, which pairs with system.network.io for utilization.

Signed-off-by: Emmanuel Yusufu Kimaswa <kimaswaemma36@gmail.com>
@emmayusufu

Copy link
Copy Markdown
Author

Fair enough, you're right. nfsscraper already uses network.io.direction and ciscoos uses network.interface.name, so I've switched this metric to both to match the semconv guidance. Since link bandwidth on a full-duplex interface applies per direction, I emit it for transmit and receive, which also lets it pair cleanly with system.network.io for utilization. Pushed the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants