# Logstash duration quastion

**URL:** <https://discuss.elastic.co/t/logstash-duration-quastion/102049>\
**Category:** Logstash\
**Created:** [September 28, 2017, 2:00am UTC](https://discuss.elastic.co/t/logstash-duration-quastion/102049 "2017-09-28T02:00:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiwi0217](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@kiwi0217](https://discuss.elastic.co/u/kiwi0217)\
**Post date:** [September 28, 2017, 2:00am UTC](https://discuss.elastic.co/t/logstash-duration-quastion/102049/1 "2017-09-28T02:00:59Z")

</div>

I write some logstash filter the count the user online period.  
but i got something wrong in my filter. And i don't know how to filter this by different users.  
log format is  
"|2017-09-28-09:49:18|INFO|JupyterHub|User logged in: jupyter|  
......  
|2017-09-28-09:49:24|INFO|JupyterHub|User logged out: jupyter|"

i write the filter like:  
date {  
match =\> ["[action\_start\_time]", "yyyy-MM-dd-HH:mm:ss"]  
target =\> "[action\_start\_timed]"  
}  
date {  
match =\> ["[action\_end\_time]", "yyyy-MM-dd-HH:mm:ss"]  
target =\> "[action\_end\_timed]"  
}  
ruby {  
code =\> "event['action\_duration'] = (event['action\_end\_timed'] - event['action\_start\_timed'])"  
}

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [September 28, 2017, 3:35am UTC](https://discuss.elastic.co/t/logstash-duration-quastion/102049/2 "2017-09-28T03:35:00Z")

</div>

Logstash acts on one event at a time so you will never have one event with both `action_start_time` and `action_end_time`. Perhaps the aggregate filter can help in this case.

---

<div class="post-metadata">

**Author:** ![kiwi0217](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@kiwi0217](https://discuss.elastic.co/u/kiwi0217)\
**Post date:** [September 28, 2017, 12:24pm UTC](https://discuss.elastic.co/t/logstash-duration-quastion/102049/3 "2017-09-28T12:24:29Z")

</div>

So , how can i count about user log in times like this?  
|2017-09-28-09:49:18|INFO|JupyterHub|User logged in: user1|  
|2017-09-28-09:49:24|INFO|JupyterHub|User logged out: user1|  
|2017-09-28-09:49:42|INFO|JupyterHub|User logged in: user2|  
|2017-09-28-09:49:55|INFO|JupyterHub|User logged out: user2|

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [September 28, 2017, 1:07pm UTC](https://discuss.elastic.co/t/logstash-duration-quastion/102049/4 "2017-09-28T13:07:05Z")

</div>

As I said, perhaps the aggregate filter can help in this case.

---

<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:** [October 26, 2017, 1:07pm UTC](https://discuss.elastic.co/t/logstash-duration-quastion/102049/5 "2017-10-26T13:07:19Z")

</div>

Closed on October 26, 2017, 1:07pm UTC

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