Skip to content

feat(host_metrics): expose number of oom_kill events#25802

Open
simonhammes wants to merge 2 commits into
vectordotdev:masterfrom
simonhammes:expose-oom-kill-events
Open

feat(host_metrics): expose number of oom_kill events#25802
simonhammes wants to merge 2 commits into
vectordotdev:masterfrom
simonhammes:expose-oom-kill-events

Conversation

@simonhammes

Copy link
Copy Markdown
Contributor

Summary

This PR adds the oom_kill metric to the host_metrics source.
The metric is read from procfs, which is already a dependency.

Vector configuration

Config

sources:
  host_metrics:
    type: host_metrics
    collectors:
      - memory

transforms:
  filter_oom_kill:
    type: filter
    inputs:
      - host_metrics
    condition: '.name == "oom_kill"'

sinks:
  console:
    inputs:
      - filter_oom_kill
    type: console
    encoding:
      codec: text

How did you test this PR?

Manual test with the configuration outlined above.

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.

@simonhammes simonhammes requested review from a team as code owners July 10, 2026 21:15
@github-actions github-actions Bot added docs review on hold The documentation team reviews PRs only after a PR is approved by the COSE team. domain: sources Anything related to the Vector's sources domain: external docs Anything related to Vector's external, public documentation labels Jul 10, 2026
@simonhammes simonhammes force-pushed the expose-oom-kill-events branch from 776a10b to 39584c3 Compare July 10, 2026 21:16
use crate::internal_events::HostMetricsScrapeDetailError;

#[cfg(target_os = "linux")]
const OOM_KILL: &str = "oom_kill";

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was a bit unsure regarding the naming of this metric.

Should this be called memory_oom_kill_events? Or oom_kill_events?

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 776a10b2ec

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

output.name = "memory";

// Spawn blocking task to avoid blocking the async runtime with synchronous I/O
let result = tokio::task::spawn_blocking(procfs::vmstat)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Honor PROCFS_ROOT for vmstat

When host_metrics is run with the documented PROCFS_ROOT override (for example a container mounting the host proc tree under /host/proc or tests using a fixture), this calls procfs::vmstat, which reads the process' default /proc/vmstat; init_roots only configures heim, so the new memory metric ignores the configured proc root while the existing memory metrics honor it. This can report OOM kills from the wrong proc tree or fail even though the configured proc root is valid, so read vmstat through the configured procfs root instead of the crate default.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As far as I'm aware, /proc/vmstat is not cgroup-aware and therefore returns the values from the host.

In addition, the procfs crate does not support customization of the procfs root iirc.

match result {
Ok(stats) => {
if let Some(&oom_kill) = stats.get("oom_kill") {
output.counter(OOM_KILL, oom_kill as f64, MetricTags::default());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Use a total-suffixed counter name

This emits a public counter named oom_kill, but Vector's metric naming spec requires counters to end in _total, and the other host memory counters follow that pattern (memory_swapped_in_bytes_total, memory_swapped_out_bytes_total). Shipping the new metric without the suffix makes the API non-compliant and any later rename would be breaking for users, so use a total-suffixed counter name and update the docs/tests together.

Useful? React with 👍 / 👎.

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

Labels

docs review on hold The documentation team reviews PRs only after a PR is approved by the COSE team. domain: external docs Anything related to Vector's external, public documentation domain: sources Anything related to the Vector's sources

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant