# Custom Metric - Calculating the error %

**URL:** <https://discuss.elastic.co/t/custom-metric-calculating-the-error/88511>\
**Category:** Kibana\
**Created:** [June 7, 2017, 6:49am UTC](https://discuss.elastic.co/t/custom-metric-calculating-the-error/88511 "2017-06-07T06:49:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![josna](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@josna](https://discuss.elastic.co/u/josna)\
**Post date:** [June 7, 2017, 6:49am UTC](https://discuss.elastic.co/t/custom-metric-calculating-the-error/88511/1 "2017-06-07T06:49:28Z")

</div>

I need to calculate the error percentage based on the success and failure rate for a request. Lets say i have Login request where i have to calculate based on the code i receive (200 and 500/404). How can i achieve error percentage here? I need to achieve this as part of Data Table (Visulaize).

---

<div class="post-metadata">

**Author:** ![Marius\_Dragomir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marius_dragomir/32/42087_2.png) [@Marius\_Dragomir](https://discuss.elastic.co/u/Marius_Dragomir)\
**Post date:** [June 9, 2017, 11:55am UTC](https://discuss.elastic.co/t/custom-metric-calculating-the-error/88511/2 "2017-06-09T11:55:13Z")

</div>

Tipically people display the response codes using a bar chart, but with some wizardry we can do a success rate in the data table using scripted fields.  
I created a scripted field, called `success`, that has the following script:

> if (doc['response.raw'].value == "200") {  
> return 1;  
> }  
> return 0;

Then you set it's format to `Percentage` from that same edit page.

Now you can do an Average of the success field in the data table and this will show the percentage of successful requests.

This is how it looks on some randomly generated Apache logs (using `makelogs` from the Kibana repo):

 ![](https://us1.discourse-cdn.com/elastic/original/3X/4/a/4ab197a749ba9ddcbe9ed1f574e4047722f18607.png)

---

<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 7, 2017, 11:55am UTC](https://discuss.elastic.co/t/custom-metric-calculating-the-error/88511/3 "2017-07-07T11:55:20Z")

</div>

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