# Calculate Elapsed time in logstash pipe

**URL:** https://discuss.elastic.co/t/calculate-elapsed-time-in-logstash-pipe/97648
**Category:** Logstash
**Created:** [August 19, 2017, 5:22am UTC](https://discuss.elastic.co/t/calculate-elapsed-time-in-logstash-pipe/97648 "2017-08-19T05:22:45Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![arunvijayam](https://avatars.discourse-cdn.com/v4/letter/a/ba9def/32.png) [@arunvijayam](https://discuss.elastic.co/u/arunvijayam)
#### Post date: [August 19, 2017, 5:22am UTC](https://discuss.elastic.co/t/calculate-elapsed-time-in-logstash-pipe/97648/1 "2017-08-19T05:22:45Z")

</div>

Hi All,

Please help me out to find the elapsed time from pipe started between pipe ended and its status whether it is completed or not.

my code is as below,

input {  
jdbc {  
jdbc\_connection\_string =\> "jdbc:oracle:thin:@01hw791865.India.TCS.com:1521/XE"  
jdbc\_user =\> "SYSTEM"  
jdbc\_password =\> "Vijaya"  
jdbc\_driver\_library =\> "C:\Users\915360.m2\repository\oracle\ojdbc6\11.2.0.3\ojdbc6-11.2.0.3.jar"  
jdbc\_driver\_class =\> "Java::oracle.jdbc.driver.OracleDriver"  
statement =\> "SELECT to\_char(sysdate,'YYYYMMDDHH') as batchid, CUSTOMER.CUSTOMERID,CUSTOMER.FIRSTNAME,CUSTOMER.LASTNAME,CUSTOMER.DOB,' ['||LISTAGG('{ '||chr(34)||'agentid'||chr(34)||' : '||nvl(AGENTDETAILS.AGENTID,-1)||', '||chr(34)||'agentfn'||chr(34)||' : '||chr(34)||nvl(AGENTDETAILS.FIRSTNAME,'-1')||chr(34)||', '||chr(34)||'agentln'||chr(34)||' : '||chr(34)||nvl(AGENTDETAILS.LASTNAME,'-1')||chr(34)||', '||chr(34)||'agencyname'||chr(34)||' : '||chr(34)||nvl(AGENTDETAILS.AGENCYNAME,'-1')||chr(34)||'}' ,',') within group (order by agentdetails.agentid) || '] ' as agents\_unparsed,replace(' ['||RTRIM(REGEXP\_REPLACE(LISTAGG('{ '||chr(34)||'policyno'||chr(34)||' : '||chr(34)||policydetails.policyno||chr(34)||', '||chr(34)||'policytype'||chr(34)||' : '||chr(34)||policydetails.policytype||chr(34)||' }' ,';') within group (order by policydetails.policyno),'([^;]\*)(;\1)+($|;)','\1\3'),';') || ' ] ',';',',') as policy\_unparsed FROM MV\_PROMPT\_LTAM.CUSTOMER LEFT OUTER JOIN MV\_PROMPT\_LTAM.CUSTOMERAGENT ON CUSTOMERAGENT.CUSTOMERID = CUSTOMER.CUSTOMERID LEFT OUTER JOIN MV\_PROMPT\_LTAM.AGENTDETAILS ON CUSTOMERAGENT.AGENTID = AGENTDETAILS.AGENTID LEFT OUTER JOIN MV\_PROMPT\_LTAM.CUSTOMERPOLICY ON CUSTOMER.CUSTOMERID = CUSTOMERPOLICY.CUSTOMERID LEFT OUTER JOIN MV\_PROMPT\_LTAM.POLICYDETAILS ON CUSTOMERPOLICY.POLICYNO = POLICYDETAILS.POLICYNO GROUP BY CUSTOMER.CUSTOMERID,CUSTOMER.FIRSTNAME,CUSTOMER.LASTNAME,CUSTOMER.DOB"  
}  
}  
filter {  
json {  
source =\> "agents\_unparsed"  
target =\> "agents"  
}  
json {  
source =\> "policy\_unparsed"  
target =\> "policy"  
}  
mutate{  
remove\_field =\> ["agents\_unparsed","policy\_unparsed"]  
}

# Measures the execution time of system1

elapsed {  
unique\_id\_field =\> "batchid"  
start\_tag =\> "system1Enter"  
end\_tag =\> "system1Exit"  
new\_event\_on\_match =\> true  
add\_tag =\> ["in1"]  
}

# Measures the time between system1 and system2

# elapsed {

# unique\_id\_field =\> "batchid"

# start\_tag =\> "system1Exit"

# end\_tag =\> "system2Enter"

# new\_event\_on\_match =\> true

# add\_tag =\> ["1-\>2"]

# }

# # Measures the execution time of system2

# elapsed {

# unique\_id\_field =\> "batchid"

# start\_tag =\> "system2Enter"

# end\_tag =\> "system2Exit"

# new\_event\_on\_match =\> true

# add\_tag =\> ["in2"]

# }

# Records the execution time of system1

if "in1" in [tags] and "elapsed" in [tags] {  
aggregate {  
task\_id =\> "%{batchid}"  
code =\> "map['report'] = (event.get('elapsed\_time')\*1000).to\_i"  
map\_action =\> "create"  
}  
}

# Records the time between system1 and system2

# if "1-\>2" in [tags] and "elapsed" in [tags] {

# aggregate {

# task\_id =\> "%{batchid}"

# code =\> "map['report'] \<\< (event.get('elapsed\_time')\*1000).to\_i"

# map\_action =\> "update"

# }

# }

# # Records the execution time of system2

# if "in2" in [tags] and "elapsed" in [tags] {

# aggregate {

# task\_id =\> "%{batchid}"

# code =\> "map['report'] \<\< (event.get('elapsed\_time')\*1000).to\_i"

# map\_action =\> "update"

# end\_of\_task =\> true

# }

# }

}  
#if [performance][event\_type] == "enter" {

# mutate { add\_tag =\> ["taskstarted"] }

#} else if [performance][event\_type] == "exit" {

# mutate { add\_tag =\> ["taskterminated"] }

#}  
#elapsed {

# start\_tag =\> "taskstarted"

# end\_tag =\> "taskterminated"

# unique\_id\_field =\> "batchid"

## timeout =\> 10000

# new\_event\_on\_match =\> false

#}

# elapsed {

# start\_tag =\> "taskStarted"

# end\_tag =\> "taskTerminated"

# unique\_id\_field =\> "batchid"

# }

# elapsed {

# start\_tag =\> "taskstarted"

# end\_tag =\> "taskended"

# unique\_id\_field =\> "batchid"

## timeout =\> seconds

# new\_event\_on\_match =\> true

# }

#}  
#filter {  
#ruby {  
#code =\> "  
#require 'json'  
#agents\_value = JSON.parse(event.get('agents').to\_s)  
#event.set('agents',agents\_value)  
#"  
#}  
#}  
output {  
mongodb {  
uri =\> "mongodb://localhost:27017/"  
database =\> "customer"  
collection =\> "customer\_nested"  
isodate =\> true  
}  
}

---

<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: [September 16, 2017, 5:22am UTC](https://discuss.elastic.co/t/calculate-elapsed-time-in-logstash-pipe/97648/2 "2017-09-16T05:22:46Z")

</div>

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