Skip to content

Conversation

@AndersonQ
Copy link
Member

@AndersonQ AndersonQ commented Jan 13, 2026

Proposed commit message

[elastic_agent] Fix Agent Metrics "[Elastic Agent] CPU Usage" chart


Fix the "[Elastic Agent] CPU Usage" dashboard panel to correctly calculate
CPU percentage regardless of the selected time window.

## Problem

The CPU usage formula used `interval()` to determine the time divisor when
calculating CPU percentage from cumulative CPU time:

    differences(max(system.process.cpu.total.time.ms)) / interval()

`interval()` returns the Kibana bucket interval (time window ÷ number of buckets),
not the actual time between consecutive data points. Since metrics are collected
at fixed intervals (e.g., every 60 seconds), but bucket intervals vary with the
selected time window, this caused:

- Correct values at small time windows (when bucket interval ≈ collection interval)
- Artificially low values at large time windows (when bucket interval > collection interval)

## Solution

Replace `interval()` with `counter_rate(max(@timestamp))` to calculate the actual
elapsed time between consecutive data points:

    counter_rate(max(system.process.cpu.total.time.ms)) / counter_rate(max(@timestamp))

`counter_rate()` instead of `differences()` as it automatically handles counter resets.

Checklist

  • [ ] I have reviewed tips for building integrations and this pull request is aligned with them.
  • [ ] I have verified that all data streams collect metrics or logs.
  • I have added an entry to my package's changelog.yml file.
  • [ ] I have verified that Kibana version constraints are current according to guidelines.
  • [ ] I have verified that any added dashboard complies with Kibana's Dashboard good practices

Author's Checklist

  • [ ]

How to test this PR locally

  • have a elastic stack deployed
  • download this:
    scripts.tar.gz. It's a script to load mock data to ES
  • configure the following env vars:
Variable Description
ELASTIC_PACKAGE_ELASTICSEARCH_HOST Elasticsearch URL (required)
ELASTIC_PACKAGE_ELASTICSEARCH_USERNAME Username (optional)
ELASTIC_PACKAGE_ELASTICSEARCH_PASSWORD Password (optional)
  • extract it
  • run import_index.sh
  • build and install the elastic_agent integration from this PR:
cd packages/elastic_agent
elastic-package build -v
elastic-package install -v
  • navigate to the "[Elastic Agent] Agent metrics" dashboard

  • set the time to Jan 11, 2026 @ 23:00:00.000 -> Jan 13, 2026 @ 06:00:00.000

  • select the mokona-elastic-mock agent

  • play with the time range

  • regardless of the chosen time range the CPU usage should stay constant

  • the data on Jan 12 is a constant: All 4 components run at constant 10% CPU usage. Total: 40%

  • the data for Jan 13 is variable:

    • Components elastic-agent and filebeat-default: 5% baseline, spike to 35% for 5 minutes every 30 minutes
    • Components metricbeat-default and fleet-server-default: 10% constant
    • Baseline total: 30% (5+5+10+10)
    • Spike total: 90% (35+35+10+10)

Related issues

Screenshots

Screenshot from 2026-01-13 18-02-51 Screenshot from 2026-01-13 18-02-40 Screenshot from 2026-01-13 18-02-19 Screenshot from 2026-01-13 18-02-04 Screenshot from 2026-01-13 18-01-50

@AndersonQ AndersonQ self-assigned this Jan 13, 2026
@AndersonQ AndersonQ added the Integration:elastic_agent Elastic Agent label Jan 13, 2026
@AndersonQ AndersonQ force-pushed the 13321-fix-agent-cpu-chart branch 2 times, most recently from e63bdf1 to 796267f Compare January 13, 2026 16:59
@andrewkroh andrewkroh added the dashboard Relates to a Kibana dashboard bug, enhancement, or modification. label Jan 13, 2026
@AndersonQ AndersonQ changed the title WIP mock data generator [elastic_agent] Fix Agent Metrics "[Elastic Agent] CPU Usage" chart Jan 13, 2026
@AndersonQ AndersonQ marked this pull request as ready for review January 13, 2026 17:10
@AndersonQ AndersonQ requested a review from a team as a code owner January 13, 2026 17:10
@andrewkroh andrewkroh added the Team:Elastic-Agent Platform - Ingest - Agent [elastic/elastic-agent] label Jan 13, 2026
@elasticmachine
Copy link

Pinging @elastic/elastic-agent (Team:Elastic-Agent)

Fix the "[Elastic Agent] CPU Usage" dashboard panel to correctly calculate
CPU percentage regardless of the selected time window.

## Problem

The CPU usage formula used `interval()` to determine the time divisor when
calculating CPU percentage from cumulative CPU time:

    differences(max(system.process.cpu.total.time.ms)) / interval()

`interval()` returns the Kibana bucket interval (time window ÷ number of buckets),
not the actual time between consecutive data points. Since metrics are collected
at fixed intervals (e.g., every 60 seconds), but bucket intervals vary with the
selected time window, this caused:

- Correct values at small time windows (when bucket interval ≈ collection interval)
- Artificially low values at large time windows (when bucket interval > collection interval)

## Solution

Replace `interval()` with `counter_rate(max(@timestamp))` to calculate the actual
elapsed time between consecutive data points:

    counter_rate(max(system.process.cpu.total.time.ms)) / counter_rate(max(@timestamp))

`counter_rate()` instead of `differences()` as it automatically handles counter resets.
@AndersonQ AndersonQ force-pushed the 13321-fix-agent-cpu-chart branch from 5f13eb7 to 9de7d47 Compare January 14, 2026 07:03
@elastic-vault-github-plugin-prod

🚀 Benchmarks report

To see the full report comment with /test benchmark fullreport

@elasticmachine
Copy link

💚 Build Succeeded

History

cc @AndersonQ

@pierrehilbert pierrehilbert added the Team:Elastic-Agent-Data-Plane Agent Data Plane team [elastic/elastic-agent-data-plane] label Jan 14, 2026
@elasticmachine
Copy link

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

Copy link
Contributor

@belimawr belimawr left a comment

Choose a reason for hiding this comment

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

It works, however when testing on an existing cluster (I installed the integration using Elastic-Package), the "Agent hostname" filter stopped working

Image

Clicking on "View more" shows nothing.

I also managed to reproduce it with Elastic-Package and a 9.2.3 stack:

  • Start Elastic-Package
  • Create a policy and add an Elastic Agent
  • Update the Elastic Agent integration
  • Go to the dashboard
Image

Could you take a look at it @AndersonQ? Maybe there was some small change in the filter that is incompatible with 9.2?

@AndersonQ
Copy link
Member Author

It works, however when testing on an existing cluster (I installed the integration using Elastic-Package), the "Agent hostname" filter stopped working

Image Clicking on "View more" shows nothing.

I also managed to reproduce it with Elastic-Package and a 9.2.3 stack:

  • Start Elastic-Package
  • Create a policy and add an Elastic Agent
  • Update the Elastic Agent integration
  • Go to the dashboard
Image Could you take a look at it @AndersonQ? Maybe there was some small change in the filter that is incompatible with 9.2?

Interesting, I'll investigate. Thanks for catching that!

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

Labels

dashboard Relates to a Kibana dashboard bug, enhancement, or modification. Integration:elastic_agent Elastic Agent Team:Elastic-Agent Platform - Ingest - Agent [elastic/elastic-agent] Team:Elastic-Agent-Data-Plane Agent Data Plane team [elastic/elastic-agent-data-plane]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[elastic_agent]: CPU Usage Inconsistency Based on Kibana Time Picker Selection

6 participants