Skip to content

Metricbeat: store only top N processes by CPU / memory #4126

@tsg

Description

@tsg

Part of #4112, we want to add a feature where only top N by CPU and/or memory are included in the reports created by the Metricbeat system module. Optionally, for the processes that drop out of top N, we could reduce their polling interval instead of just completely dropping them.

My current plan is to implement this as a feature of the system.process metricset. I considered doing this as a processor but a processor would need to collect all processes from an interval in order to sort & compute the "top". This seems to me like a lot of state to put in a processor, plus it's hard for a processor to know when the list is "done".

Configuration wise, I'm thinking:

  process.include_top:
    enabled: true
    cpu.total.pct: 5         # include top 5 by CPU
    memory.rss.bytes: 5      # include top 5 by memory

Explanations:

  • include_top because we use include to mean "filter everything but these" in other places in Beats
  • enabled: true to have an easy and clear way to opt in / opt out of this feature.
  • cpu.total.pct: 5 means "record top 5 processes by the cpu.total.pct field.
  • memory.rss.bytes: 5 means "record top 5 processes by memory.rss.bytes field.
  • If any of cpu.total or memory.rss are set to 0, it means "match no processes". So cpu.total: 5 memory.rss: 0 will only look at CPU.

Do we want to support sorting by other fields than the two? Make it generic? That would require a more generic (and more CPU intensive) implementation.

In the above, events for processes below the threshold are dropped. If the user wants to store them, just at a reduced resolution, the following config could be added:

  process.include_top:
    enabled: true
    cpu.total.pct: 5
    memory.rss.bytes: 5
    period_multiplier: 3    # downsample for processes not in top

Here, period_multiplier: 3 means that we will only publish one in 3 events for the processes out of the top. Since we report counters and not rates, that should work fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions