# Using aggregate filter to measure response time

**URL:** <https://discuss.elastic.co/t/using-aggregate-filter-to-measure-response-time/188312>\
**Category:** Logstash\
**Created:** [July 1, 2019, 12:30pm UTC](https://discuss.elastic.co/t/using-aggregate-filter-to-measure-response-time/188312 "2019-07-01T12:30:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![BartR](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@BartR](https://discuss.elastic.co/u/BartR)\
**Post date:** [July 1, 2019, 12:30pm UTC](https://discuss.elastic.co/t/using-aggregate-filter-to-measure-response-time/188312/1 "2019-07-01T12:30:01Z")

</div>

Hi ,  
i have been attempting to create an additional field into my logging which keeps the responsetime of tsa requests to a service .

after looking though some stuff i found that it looked like it would be possible with an aggregate filter in logstash so i tried to implement it but i keep getting errors about the formatting of the filter clause

below is the filter part of the pipeline im creating

the idea behind it is to subtract the 2 timestamps between the request received and request finnished logs  
any help on this topic or any other way to achieve the result with elastic stack would be greatly appreciated

filter {  
if [message] =~ "RECEIVED TSA REQUEST" {  
aggregate {  
task\_id =\> "test"  
code =\> "map['timestamp'] = %{@timestamp}  
map\_action =\> "create"  
}  
}  
if [message] =~ "FINISHED TSA REQUEST" {  
aggregate {  
task\_id =\> "test"  
code =\> "event.set(map['timestamp'] - '@timestamp')"  
map\_action =\> "update"  
end\_of\_task =\> true  
timeout =\> 120  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [July 1, 2019, 1:14pm UTC](https://discuss.elastic.co/t/using-aggregate-filter-to-measure-response-time/188312/2 "2019-07-01T13:14:11Z")

</div>

task\_id has to be a sprintf reference, and you need to convert [@timestamp] to a numeric value

```
            task_id => "%{test}"
            code => "map['timestamp'] = event.get('@timestamp').to_f"

```

would work in the first aggregate. For the second one, event.set takes two arguments, so

```
code => "event.set('someField', map['timestamp'] - event.get('@timestamp').to_f)"

```

might work. I would definitely consider changing the to\_f to to\_f \* 1000).to\_i so that you are working with integer numbers of milliseconds.

---

<div class="post-metadata">

**Author:** ![BartR](https://avatars.discourse-cdn.com/v4/letter/b/ac8455/32.png) [@BartR](https://discuss.elastic.co/u/BartR)\
**Post date:** [July 1, 2019, 1:40pm UTC](https://discuss.elastic.co/t/using-aggregate-filter-to-measure-response-time/188312/3 "2019-07-01T13:40:13Z")

</div>

thnx for the help , i have tried this now, it solved the errors popping up , but it still does not add any fields with the response time info

---

<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 29, 2019, 1:40pm UTC](https://discuss.elastic.co/t/using-aggregate-filter-to-measure-response-time/188312/4 "2019-07-29T13:40:18Z")

</div>

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