# Add a custom metric to Kibana (4.1)

**URL:** https://discuss.elastic.co/t/add-a-custom-metric-to-kibana-4-1/44539
**Category:** Kibana
**Created:** [March 16, 2016, 10:09am UTC](https://discuss.elastic.co/t/add-a-custom-metric-to-kibana-4-1/44539 "2016-03-16T10:09:13Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dapicard](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@dapicard](https://discuss.elastic.co/u/dapicard)
#### Post date: [March 16, 2016, 10:09am UTC](https://discuss.elastic.co/t/add-a-custom-metric-to-kibana-4-1/44539/1 "2016-03-16T10:09:13Z")

</div>

Hi,

Using scripted metrics aggregation in ElasticSearch, I created a metric that returns the "duration" between the oldest and the newest document in a bucket, given a date field (useful to know, for example, a session duration from logs).

These scripts work well, and I get a result very similar to the "standard" aggregation like sum, min, max etc. :  
"aggregations": {"sessionid\_terms": {  
"doc\_count\_error\_upper\_bound": 0,  
"sum\_other\_doc\_count": 4,  
"buckets": [  
{  
"key": "41249bb5fe7d32078145f06a675d0fe5",  
"doc\_count": 64,  
"duration": {"value": 6395711}  
},  
{  
"key": "34ac96dcf0a8a59325788bda593c23f9",  
"doc\_count": 59,  
"duration": {"value": 4298000}  
},...

Now, I would like to offer the possibility to my end-users to use this metric the same way the others metrics (sum, min, max, etc.) in Kibana.  
So I take a look at the Kibana 4.1 source code from github, but I'm not sure the way I have to do that ; especially I don't find a "plugin" way to add this metric.

What is your advice to achieve it ?

Thank you.

---

<div class="post-metadata">

### Author: ![tbragin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tbragin/32/45166_2.png) [@tbragin](https://discuss.elastic.co/u/tbragin)
#### Post date: [March 18, 2016, 2:09pm UTC](https://discuss.elastic.co/t/add-a-custom-metric-to-kibana-4-1/44539/2 "2016-03-18T14:09:30Z")

</div>

Kibana does not support creating fields using scripted metric aggregations:

> <https://github.com/elastic/kibana/issues/2646>

You might be able to use JSON input in aggregations to do something fancy like that -- see one example here: [Display concurrency in data on Kibana](https://discuss.elastic.co/t/display-concurrency-in-data-on-kibana/26006/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 6, 2017, 1:58pm UTC](https://discuss.elastic.co/t/add-a-custom-metric-to-kibana-4-1/44539/3 "2017-07-06T13:58:35Z")

</div>


