# Calculate Error Budget Metric

**URL:** https://discuss.elastic.co/t/calculate-error-budget-metric/307507
**Category:** Kibana
**Created:** [June 17, 2022, 11:51am UTC](https://discuss.elastic.co/t/calculate-error-budget-metric/307507 "2022-06-17T11:51:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![EllBil](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@EllBil](https://discuss.elastic.co/u/EllBil)
#### Post date: [June 17, 2022, 11:51am UTC](https://discuss.elastic.co/t/calculate-error-budget-metric/307507/1 "2022-06-17T11:51:38Z")

</div>

Hello Elastic team,

I'm actually working on SLI/SLO visualization on Kibana.  
My request is a bit complexe :  
I need to visualize the remaining error budget using this formula :  
EB = 436 minutes  
IF (not status = "500" or latency \< 2) / (status : \*) \< 0.98 :  
THEN Remaining EB = EB - 1  
And I need to Show the value on a Metric.  
Is there a way to do so ?

---

<div class="post-metadata">

### Author: ![EllBil](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@EllBil](https://discuss.elastic.co/u/EllBil)
#### Post date: [June 17, 2022, 3:02pm UTC](https://discuss.elastic.co/t/calculate-error-budget-metric/307507/2 "2022-06-17T15:02:29Z")

</div>

I'll give more details in this comment.  
So basically I have a huge amount of logs on my elastic,  
In a first step I calculate the ratio (number of requests not 500 and number of requests \< specified latency) / total number of requests which I define as availability ratio.  
In a next step we define a remaining error budget = 436 minutes.  
Last step : If availability ratio (during 1 minute time-window) \< 0.98 we consider this minute as burned or HS so we do error budget = error budget - 1

My main objective is to keep track of this remaining error budget

---

<div class="post-metadata">

### Author: ![bhavyarm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bhavyarm/32/22392_2.png) [@bhavyarm](https://discuss.elastic.co/u/bhavyarm)
#### Post date: [June 17, 2022, 7:17pm UTC](https://discuss.elastic.co/t/calculate-error-budget-metric/307507/3 "2022-06-17T19:17:45Z")

</div>

@Marius_Dragomir want to take a look at this? Thanks!

---

<div class="post-metadata">

### Author: ![EllBil](https://avatars.discourse-cdn.com/v4/letter/e/9e8a1a/32.png) [@EllBil](https://discuss.elastic.co/u/EllBil)
#### Post date: [June 22, 2022, 8:07am UTC](https://discuss.elastic.co/t/calculate-error-budget-metric/307507/4 "2022-06-22T08:07:57Z")

</div>

Hello Again Elastic community,  
So basically I found a solution. Yet, I'm not sure if it's the best solution.

- Going through a transformation

> value={  
> "id": "13",  
> "version": "7.16.2",  
> "create\_time": 1655827411304,  
> "source": {  
> "index": [  
> "logs-github-unicorn\*"  
> ],  
> "query": {  
> "match\_all": {}  
> }  
> },  
> "dest": {  
> "index": "transformed-unicorn"  
> },  
> "frequency": "1m",  
> "pivot": {  
> "group\_by": {  
> "@timestamp": {  
> "date\_histogram": {  
> "field": "@timestamp",  
> "calendar\_interval": "1m"  
> }  
> }  
> },  
> "aggregations": {  
> "Total\_request": {  
> "value\_count": {  
> "field": "status"  
> }  
> },  
> "failed\_req": {  
> "filter": {  
> "term": {  
> "status": "500"  
> }  
> }  
> },  
> "latency\_err": {  
> "filter": {  
> "range": {  
> "latency": {  
> "gt": 4  
> }  
> }  
> }  
> }  
> }  
> },  
> "settings": {  
> "max\_page\_search\_size": 500  
> }  
> }

- In a second step I add painless scripted field (Field name : SLI)

> emit ((doc['latency.filter'].value + doc['500'].value)/doc['now.value\_count'].value)

Finally I create a metric with a formula ( 436 - count () ) While filtering on SLI \> 2%

---

<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: [July 20, 2022, 8:08am UTC](https://discuss.elastic.co/t/calculate-error-budget-metric/307507/5 "2022-07-20T08:08:10Z")

</div>

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