# How to collect a custom metric using metricbeat

**URL:** <https://discuss.elastic.co/t/how-to-collect-a-custom-metric-using-metricbeat/172250>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [March 14, 2019, 5:40am UTC](https://discuss.elastic.co/t/how-to-collect-a-custom-metric-using-metricbeat/172250 "2019-03-14T05:40:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![msk\_76](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@msk\_76](https://discuss.elastic.co/u/msk_76)\
**Post date:** [March 14, 2019, 5:40am UTC](https://discuss.elastic.co/t/how-to-collect-a-custom-metric-using-metricbeat/172250/1 "2019-03-14T05:40:44Z")

</div>

I have to create a sampled time series data by running a command( by application on RH 7 Linux) at interval of 5minutes that will generate a output. Now i want to tag this time ( of fixed interval of 5 mins) to the data. For example 2019-03-14 09:00:00 cmd\_output\_data1, 2019-03-14 09:05:00 cmd\_output\_data2... like that..  
In logstash, I have to calculate the difference in time between two successive data to know the number of samples. So my requirement is to insert the very accurate time\_stamp i.e with precision of 00 seconds like 09:00:00, 09:05:00, 09:10:00.. so that if i calculate the samples it will be diff( 09:10:00 - 09:00:00 ) = 15/5 = 3 samples..

I understand that metricbeat should be used for collecting a time sample data but it works only with available module embedded in it. My requirement is for custom application metric collection as explained above. Am I missing something?

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [March 14, 2019, 7:46am UTC](https://discuss.elastic.co/t/how-to-collect-a-custom-metric-using-metricbeat/172250/2 "2019-03-14T07:46:11Z")

</div>

Welcome @msk_76

Can you share a bit more about the command / script that is run to create the metrics output? Metricbeat has some more generic modules / inputs like http which you can point at any endpoint. Perhaps we can do something similar here.

---

<div class="post-metadata">

**Author:** ![msk\_76](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@msk\_76](https://discuss.elastic.co/u/msk_76)\
**Post date:** [March 14, 2019, 8:14am UTC](https://discuss.elastic.co/t/how-to-collect-a-custom-metric-using-metricbeat/172250/3 "2019-03-14T08:14:06Z")

</div>

The output of command will be six space seperated columns :  
col1 col2 col3 col4 col5 col6 and the additional col7 for time of run of command like 2019-03-14 09:00:00.

Col1 is username ( string), col2 is feature\_name(string) and col5 is numeric value of usage of feature by username and col6 is also numeric which is total number of feature\_name available.  
During transformation i have to add another column say col8 having sum of usage(by all users) of given feature at a given timestamp in front of each row of data.

Hope I am able to explain the context.

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [March 15, 2019, 11:45am UTC](https://discuss.elastic.co/t/how-to-collect-a-custom-metric-using-metricbeat/172250/4 "2019-03-15T11:45:58Z")

</div>

An alternative idea to make this happen would be writing this data to a log file, then read this log file with Filebeat and use dissect to split up the values. If you have all the raw values, I assume you can do all the calculations in real time on the Elasticsearch side.

---

<div class="post-metadata">

**Author:** ![msk\_76](https://avatars.discourse-cdn.com/v4/letter/m/dbc845/32.png) [@msk\_76](https://discuss.elastic.co/u/msk_76)\
**Post date:** [March 15, 2019, 12:15pm UTC](https://discuss.elastic.co/t/how-to-collect-a-custom-metric-using-metricbeat/172250/5 "2019-03-15T12:15:55Z")

</div>

I tried writing to log file but the issue is that if I keep the time\_stamp of running command for datacollection, it doesn’t maintain equal interval. For example  
in one case it keep 09:00:00 and in next sample of 5 mins it records 09:05:02 and third 09:10:01. So there is difference of few seconds gets recorded in log file and I don’t get a equal difference in time.

---

<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:** [April 12, 2019, 12:15pm UTC](https://discuss.elastic.co/t/how-to-collect-a-custom-metric-using-metricbeat/172250/6 "2019-04-12T12:15:58Z")

</div>

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