# Using rate() function in Kibana Lenses

**URL:** <https://discuss.elastic.co/t/using-rate-function-in-kibana-lenses/271790>\
**Category:** Kibana\
**Created:** [April 30, 2021, 1:56pm UTC](https://discuss.elastic.co/t/using-rate-function-in-kibana-lenses/271790 "2021-04-30T13:56:11Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ronaldo\_Lanhellas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ronaldo_lanhellas/32/88020_2.png) [@Ronaldo\_Lanhellas](https://discuss.elastic.co/u/Ronaldo_Lanhellas)\
**Post date:** [April 30, 2021, 1:56pm UTC](https://discuss.elastic.co/t/using-rate-function-in-kibana-lenses/271790/1 "2021-04-30T13:56:11Z")

</div>

I'm collecting metrics from kubernetes nodes using this api:

```auto
kubectl get --raw /api/v1/nodes/$1/proxy/metrics/cadvisor

```

And this returns the metrics in Prometheus format. So, I'm sending this to Logstash and making some transformations, see:

```auto
filter{
    mutate {
      remove_field => ["host"]
    }

     ruby{
        code => "
        if (event.get('[container_cpu_usage_seconds_total_container_cpu_id_image_name_namespace_pod][container_cpu_usage_seconds_total]')!=nil)
         event.set('container_cpu_usage_percent', (event.get('[container_cpu_usage_seconds_total_container_cpu_id_image_name_namespace_pod][container_cpu_usage_seconds_total]') / (event.get('machine_cpu_cores') * 100)).ceil(2))
        end
        "
    }

}

```

As you can see I'm trying to calculate CPU Usage % using the following formula:

```auto
container_cpu_usage_seconds_total/ (machine_cpu_cores*100)

```

Trying to reproduce same formula as prometheus:

```auto
rate(container_cpu_user_seconds_total[30s]) * 100

```

But didn't works, because I need to use something like "Serial Diff" and I tried but without success:

![Captura de tela 2021-04-30 105753](https://us1.discourse-cdn.com/elastic/original/3X/c/0/c0f96063f0fef60ad6251cb6aea594e283699e66.png)

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [April 30, 2021, 2:11pm UTC](https://discuss.elastic.co/t/using-rate-function-in-kibana-lenses/271790/2 "2021-04-30T14:11:58Z")

</div>

@Ronaldo_Lanhellas I am one of the Lens developers, and we recently added support for functions that are similar to what Prometheus offers in 7.11. You're showing a screenshot that isn't from Lens, by the way.

We have the `Differences` function with an advanced setting for `Normalize time unit` to 1 second or 1 minute.

If you need to multiply by 100, you can use a Runtime field or Scripted field from your Kibana index pattern which does the math for you. These fields will appear in the field list.

---

<div class="post-metadata">

**Author:** ![Ronaldo\_Lanhellas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ronaldo_lanhellas/32/88020_2.png) [@Ronaldo\_Lanhellas](https://discuss.elastic.co/u/Ronaldo_Lanhellas)\
**Post date:** [April 30, 2021, 2:31pm UTC](https://discuss.elastic.co/t/using-rate-function-in-kibana-lenses/271790/3 "2021-04-30T14:31:49Z")

</div>

@wylie

> [@wylie](#):
>
> `Differences`

I made a mistake, in fact, I'm using a normal graph from kibana, not Lens, can you send a print screen where can I use "Differences" in Lens ? I didn't found it.

In Lens I just have it:

 ![Captura de tela 2021-04-30 113433](https://us1.discourse-cdn.com/elastic/original/3X/7/d/7d61928292ab673eda3b0610879c7804417d6f60.png)

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [April 30, 2021, 3:02pm UTC](https://discuss.elastic.co/t/using-rate-function-in-kibana-lenses/271790/4 "2021-04-30T15:02:40Z")

</div>

Sorry, I thought we released these in 7.11 but they are released in 7.12: [What’s new in 7.12 | Kibana Guide [7.12] | Elastic](https://www.elastic.co/guide/en/kibana/current/whats-new.html#lens-7-12)

---

<div class="post-metadata">

**Author:** ![Ronaldo\_Lanhellas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ronaldo_lanhellas/32/88020_2.png) [@Ronaldo\_Lanhellas](https://discuss.elastic.co/u/Ronaldo_Lanhellas)\
**Post date:** [April 30, 2021, 3:04pm UTC](https://discuss.elastic.co/t/using-rate-function-in-kibana-lenses/271790/5 "2021-04-30T15:04:50Z")

</div>

Thanks, I will update to 7.12 and give it a try.

---

<div class="post-metadata">

**Author:** ![Ronaldo\_Lanhellas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ronaldo_lanhellas/32/88020_2.png) [@Ronaldo\_Lanhellas](https://discuss.elastic.co/u/Ronaldo_Lanhellas)\
**Post date:** [April 30, 2021, 7:42pm UTC](https://discuss.elastic.co/t/using-rate-function-in-kibana-lenses/271790/6 "2021-04-30T19:42:44Z")

</div>

@wylie , I updated and now I can use the "Difference" function, but how can I express percent(%) difference between two values?

For example, I have the following range:  
1, 4, 10, 20

The difference function gives me:  
3, 6, 10

but I need percent difference between values, to see how much grows up.

---

<div class="post-metadata">

**Author:** ![wylie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wylie/32/81794_2.png) [@wylie](https://discuss.elastic.co/u/wylie)\
**Post date:** [April 30, 2021, 7:54pm UTC](https://discuss.elastic.co/t/using-rate-function-in-kibana-lenses/271790/7 "2021-04-30T19:54:39Z")

</div>

I see, that's not supported yet. You can do this using TSVB though: [Visualizing observability with Kibana: Event rates and rate of change in TSVB | Elastic Blog](https://www.elastic.co/blog/visualizing-observability-with-kibana-event-rates-and-rate-of-change-in-tsvb)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 28, 2021, 7:55pm UTC](https://discuss.elastic.co/t/using-rate-function-in-kibana-lenses/271790/8 "2021-05-28T19:55:13Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
