How to convert kubernetes cpu usage and memory usage of metricbeat fields to percentage IN METRICBEAT index elasticsearch

Hello, how can i get the percentage of Kubernetes node CPU usage and Kubernetes node memory usage from metricbeat, as i am making a custom plugin where I wanted to show it in percentage. moreover i'm making Elasticsearch queries which gives buckets of every 1 minute of usage of CPU and memory, but fields are not exactly giving it in percentages. kindly help with this and write fields name and how do I convert them to percentage

Hi @Jay_Gajjar,

If I understand correctly, you are writing a custom plugin that queries for data from metricbeat. How is the memory usage stored? Is it two separate fields (free and total) and you want to calculate the percentage based on this?

Assuming the above is accurate (if it is not, it would be great to provide a data sample!), you can achieve this in two ways:

  1. Since you are writing a custom plugin, I assume you are performing queries and have access to the search results before displaying them in your plugin? You could postprocess the results in your plugin code to calculate the percentage for each document returned.
  2. You can add a runtime field that calculates this percentage for you. Here is the documentation for runtime fields: Runtime fields | Elasticsearch Guide [7.15] | Elastic. You can add runtime fields to the index mapping or add them at query time. Then when you perform your query, the percentage field will be pre-calculated.

Let me know if this answers your question!