Skip to content

feat(metrics): Add per-component CPU usage metric#25185

Draft
gwenaskell wants to merge 13 commits intomasterfrom
yoenn.burban/OPA-5012-add-per-component-cpu-metric
Draft

feat(metrics): Add per-component CPU usage metric#25185
gwenaskell wants to merge 13 commits intomasterfrom
yoenn.burban/OPA-5012-add-per-component-cpu-metric

Conversation

@gwenaskell
Copy link
Copy Markdown
Contributor

@gwenaskell gwenaskell commented Apr 14, 2026

Summary

This PR adds a new metric reporting the CPU time consumed by sync/function transforms, to get a better measurement of their CPU usage.

See the RFC for more details.

Vector configuration

How did you test this PR?

Change Type

  • Bug fix
  • New feature
  • Dependencies
  • Non-functional (chore, refactoring, docs)
  • Performance

Is this a breaking change?

  • Yes
  • No

Does this PR include user facing changes?

  • Yes. Please add a changelog fragment based on our guidelines.
  • No. A maintainer will apply the no-changelog label to this PR.

References

  • Closes: OPA-5012

Notes

  • Please read our Vector contributor resources.
  • Do not hesitate to use @vectordotdev/vector to reach out to us regarding this PR.
  • Some CI checks run only after we manually approve them.
    • We recommend adding a pre-push hook, please see this template.
    • Alternatively, we recommend running the following locally before pushing to the remote branch:
      • make fmt
      • make check-clippy (if there are failures it's possible some of them can be fixed with make clippy-fix)
      • make test
  • After a review is requested, please avoid force pushes to help us review incrementally.
    • Feel free to push as many commits as you want. They will be squashed into one before merging.
    • For example, you can run git merge origin master and git push.
  • If this PR introduces changes Vector dependencies (modifies Cargo.lock), please
    run make build-licenses to regenerate the license inventory and commit the changes (if any). More details on the dd-rust-license-tool.

@github-actions github-actions bot added domain: topology Anything related to Vector's topology code domain: rfc labels Apr 14, 2026
Comment thread rfcs/2026-04-13-component-cpu-metric.md Fixed
Comment thread rfcs/2026-04-13-component-cpu-metric.md Fixed
Comment thread rfcs/2026-04-13-component-cpu-metric.md Fixed
Comment thread rfcs/2026-04-13-component-cpu-metric.md Fixed
Comment thread rfcs/2026-04-13-component-cpu-metric.md Fixed
Comment thread rfcs/2026-04-13-component-cpu-metric.md Fixed
Comment thread rfcs/2026-04-13-component-cpu-metric.md Fixed
Comment thread rfcs/2026-04-13-component-cpu-metric.md Fixed
@github-actions github-actions bot added the domain: external docs Anything related to Vector's external, public documentation label Apr 15, 2026
The value is cumulative CPU nanoseconds consumed by the component. Operators
use it to compute CPU core utilization:

```promql
Comment thread rfcs/2026-04-13-component-cpu-metric.md Fixed
Comment thread rfcs/2026-04-13-component-cpu-metric.md Fixed
Comment thread rfcs/2026-04-13-component-cpu-metric.md Fixed
Comment thread rfcs/2026-04-13-component-cpu-metric.md Fixed
Comment thread rfcs/2026-04-13-component-cpu-metric.md Outdated
poll, the delta between two calls around `transform_all` gives exact CPU time
consumed by that transform invocation.

**Overhead:** On Linux, `clock_gettime(CLOCK_THREAD_CPUTIME_ID)` is
Comment thread rfcs/2026-04-13-component-cpu-metric.md Fixed
Comment thread rfcs/2026-04-13-component-cpu-metric.md Fixed
far cheaper. Per-event latency can be derived from the counter and
`events_sent_total` if needed (`cpu_ns / events = avg cpu ns per event`).

### `getrusage(RUSAGE_THREAD)` instead of `clock_gettime`
On Linux, `getrusage(RUSAGE_THREAD)` also provides per-thread CPU time (as
`ru_utime` + `ru_stime`).

**Not preferred because:** `clock_gettime(CLOCK_THREAD_CPUTIME_ID)` has
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: external docs Anything related to Vector's external, public documentation domain: rfc domain: topology Anything related to Vector's topology code work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants