<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Transaction with Multiple events in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173014#M49606</link>
    <description>&lt;P&gt;I am using the transaction command to group transactions on the field tx_id.  Each successful transaction will begin with the field tx_state=FPA and end with tx_state=FUS.  Each transaction will have any number of values for tx_state until the transation is completed.  Is there a way to track the time it took to go from one event to the next within a transaction based on how long it took to go from tx_state to the next tx_state?  Currently my search is as follows.&lt;/P&gt;

&lt;P&gt;** host=dtsever01 source=/tmp/messages.log sourcetype=messages tx_id=* | transaction tx_id startswith="FPA" endswith="FUS"&lt;/P&gt;

&lt;P&gt;I have found that the following search will produce the time differentials between events, but only if there are exactly these 4 events in a transaction:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; host=dtsever01 source=/tmp/messages.log sourcetype=messages tx_id=*
 | eval FPA=if(tx_state="FPA",_time,null()) 
 | eval MLS=if(tx_state="MLS",_time,null()) 
 | eval DSS=if(tx_state="DSS",_time,null()) 
 | eval FUS=if(tx_state="FUS",_time,null()) 
 | transaction tx_id startswith="FPA" endswith="FUS"| search credit_bureau
 |eval MLS_Completion=MLS-FPA
 | eval DSS_Completion=DSS-MLS
 | eval FUS_Completion=FUS-DSS
 | eval Total_Time=FUS-FPA
 | stats avg(MLS_Completion) as MLS_AVG, avg(DSS_Completion) as DSS_AVG, avg(FUS_Completion) as FUS_AVG, avg(Total_Time) as Total_Time by tx_id ""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My goal is to get a timechart that shows the time it took between the tx_state's by tx_id.&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 19:45:12 GMT</pubDate>
    <dc:creator>JoeSco27</dc:creator>
    <dc:date>2020-09-28T19:45:12Z</dc:date>
    <item>
      <title>Transaction with Multiple events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173014#M49606</link>
      <description>&lt;P&gt;I am using the transaction command to group transactions on the field tx_id.  Each successful transaction will begin with the field tx_state=FPA and end with tx_state=FUS.  Each transaction will have any number of values for tx_state until the transation is completed.  Is there a way to track the time it took to go from one event to the next within a transaction based on how long it took to go from tx_state to the next tx_state?  Currently my search is as follows.&lt;/P&gt;

&lt;P&gt;** host=dtsever01 source=/tmp/messages.log sourcetype=messages tx_id=* | transaction tx_id startswith="FPA" endswith="FUS"&lt;/P&gt;

&lt;P&gt;I have found that the following search will produce the time differentials between events, but only if there are exactly these 4 events in a transaction:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; host=dtsever01 source=/tmp/messages.log sourcetype=messages tx_id=*
 | eval FPA=if(tx_state="FPA",_time,null()) 
 | eval MLS=if(tx_state="MLS",_time,null()) 
 | eval DSS=if(tx_state="DSS",_time,null()) 
 | eval FUS=if(tx_state="FUS",_time,null()) 
 | transaction tx_id startswith="FPA" endswith="FUS"| search credit_bureau
 |eval MLS_Completion=MLS-FPA
 | eval DSS_Completion=DSS-MLS
 | eval FUS_Completion=FUS-DSS
 | eval Total_Time=FUS-FPA
 | stats avg(MLS_Completion) as MLS_AVG, avg(DSS_Completion) as DSS_AVG, avg(FUS_Completion) as FUS_AVG, avg(Total_Time) as Total_Time by tx_id ""
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My goal is to get a timechart that shows the time it took between the tx_state's by tx_id.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:45:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173014#M49606</guid>
      <dc:creator>JoeSco27</dc:creator>
      <dc:date>2020-09-28T19:45:12Z</dc:date>
    </item>
    <item>
      <title>Re: Transaction with Multiple events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173015#M49607</link>
      <description>&lt;P&gt;Currently, the visualization this search returns is a line chart with the x-axis being the different tx_ids the y-axis being the value (time) and each line represents MLS_AVG, DSS_AVG, FUS_AVG, and Total_Time.  I would like each line to be tx_id and the x-axis being the differnet events in the transaction (MLS_AVG, DSS_AVG, FUS_AVG)&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:45:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173015#M49607</guid>
      <dc:creator>JoeSco27</dc:creator>
      <dc:date>2020-09-28T19:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: Transaction with Multiple events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173016#M49608</link>
      <description>&lt;P&gt;You can do this using &lt;CODE&gt;mvlist&lt;/CODE&gt;, &lt;CODE&gt;mvexpand&lt;/CODE&gt; and &lt;CODE&gt;streamstats&lt;/CODE&gt;.  Here is the full search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=dtsever01 source=/tmp/messages.log sourcetype=messages tx_id=* | eval phaseTime=mvzip(tx_state,_time) | transaction tx_id startswith="FPA" endswith="FUS" mvlist=phaseTime | search credit_bureau | mvexpand phaseTime  | rex field=phaseTime "(?&amp;amp;lt;tx_phase&amp;amp;gt;.*),(?&amp;amp;lt;tx_phase_time&amp;amp;gt;.*)" | streamstats current=f window=1 last(tx_phase_time) as prevTime by tx_id | eval elapsedTime=if(isnull(prevTime),null(),tx_phase_time - prevTime) | chart avg(elapsedTime) avg(duration) by tx_id tx_phase
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And here is the search broken down by each step explaining what's happening.  First create a field that contains the phase of the transaction and the time so that we can work with this later:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=dtsever01 source=/tmp/messages.log sourcetype=messages tx_id=* | eval phaseTime=mvzip(tx_state,_time)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Next, create your transaction, being sure to set the &lt;CODE&gt;mvlist&lt;/CODE&gt; option for the field we just created.  This will keep &lt;CODE&gt;phaseTime&lt;/CODE&gt; in the correct order:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | transaction tx_id startswith="FPA" endswith="FUS" mvlist=phaseTime | search credit_bureau ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now expand your transaction based on the &lt;CODE&gt;phaseTime&lt;/CODE&gt;.  This creates a new event for every distinct value of phaseTime: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | mvexpand phaseTime ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Next extract &lt;CODE&gt;phaseTime&lt;/CODE&gt; into &lt;CODE&gt;phase&lt;/CODE&gt; and &lt;CODE&gt;time&lt;/CODE&gt; for each of the new events:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex field=phaseTime "(?&amp;amp;lt;tx_phase&amp;amp;gt;.*),(?&amp;amp;lt;tx_phase_time&amp;amp;gt;.*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now use streamstats to pull in the previous event's time by transaction id:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | streamstats current=f window=1 last(tx_phase_time) as prevTime by tx_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Lastly, use &lt;CODE&gt;eval&lt;/CODE&gt; to figure the time elapsed during each step of the transaction:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval elapsedTime=if(isnull(prevTime),null(),tx_phase_time - prevTime)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and compute your statistics:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | chart avg(elapsedTime) avg(duration) by tx_id tx_phase
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 May 2015 17:54:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173016#M49608</guid>
      <dc:creator>wpreston</dc:creator>
      <dc:date>2015-05-06T17:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Transaction with Multiple events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173017#M49609</link>
      <description>&lt;P&gt;something is happening with formatting on some of the characters.  Splunk Answers is not handling greater than and less than characters in code blocks.  Substitute in the symbols when you perform your search.  &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;greater than = &amp;amp;gt;
less than = &amp;amp;lt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 May 2015 17:56:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173017#M49609</guid>
      <dc:creator>wpreston</dc:creator>
      <dc:date>2015-05-06T17:56:49Z</dc:date>
    </item>
    <item>
      <title>Re: Transaction with Multiple events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173018#M49610</link>
      <description>&lt;P&gt;Thank you so much for the help.  I am getting negative numbers for duration because it is taking the tx_state in alphaNumerical order and not in order that they appear.   Is there a way to fix that?&lt;/P&gt;</description>
      <pubDate>Wed, 06 May 2015 18:17:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173018#M49610</guid>
      <dc:creator>JoeSco27</dc:creator>
      <dc:date>2015-05-06T18:17:26Z</dc:date>
    </item>
    <item>
      <title>Re: Transaction with Multiple events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173019#M49611</link>
      <description>&lt;P&gt;I also should have added, each step in the process has its own timestamp tx_ts.  I am providing an example transaction for better understanding.&lt;/P&gt;

&lt;P&gt;i|1430867532|55494e4ce4b0fea9d18164d3|2015-05-05 23:12:12.949000||FPA|0|extmule_bureau_credco|CRD|none&lt;BR /&gt;
u|1430867543|55494e4ce4b0fea9d18164d3|2015-05-05 23:12:23.514000||MLR|1|||&lt;BR /&gt;
u|1430867553|55494e4ce4b0fea9d18164d3|2015-05-05 23:12:33.958000|||2|||&lt;BR /&gt;
u|1430867563|55494e4ce4b0fea9d18164d3|2015-05-05 23:12:43.220000||MLS|3|dtservice_bureau_save||&lt;BR /&gt;
u|1430867563|55494e4ce4b0fea9d18164d3|2015-05-05 23:12:43.812000||DSS||||&lt;BR /&gt;
u|1430867567|55494e4ce4b0fea9d18164d3|2015-05-05 23:12:47.423000|||4|||&lt;BR /&gt;
u|1430867568|55494e4ce4b0fea9d18164d3|2015-05-05 23:12:48.614000||FUS||||&lt;/P&gt;

&lt;P&gt;The third field is the transaction ID (tx_id), next is timestamp (tx_ts), the next field that matters is the tx_state (FPA, MLR, MLS, DSS, FUS).  Even though there are multiple i just want to know the time it took to get from FPA to MLS, MLS to DSS, &amp;amp; DSS to FUS for each tx_id&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 19:45:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173019#M49611</guid>
      <dc:creator>JoeSco27</dc:creator>
      <dc:date>2020-09-28T19:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: Transaction with Multiple events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173020#M49612</link>
      <description>&lt;P&gt;I'm assuming that the timestamp is what you're using at index time as each event's time?  Here, try this search instead.  It only creates a &lt;CODE&gt;phaseTime&lt;/CODE&gt; field if the &lt;CODE&gt;tx_state&lt;/CODE&gt; is one of the values that you care about (FPA, MLS, DSS, FUS).  It should also take care of the ordering problem with &lt;CODE&gt;tx_state&lt;/CODE&gt;.  The &lt;CODE&gt;mvlist&lt;/CODE&gt; option in transaction makes sure that the field indicated is stored in arrival order instead of transaction's default behavior (storing all mv fields lexigraphically).  Try this and let me know how it works.  Don't forget to put in the Greater Than and Less Than symbols in the &lt;CODE&gt;rex&lt;/CODE&gt; command.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host=dtsever01 source=/tmp/messages.log sourcetype=messages tx_id=* | eval phaseTime=if(tx_state="FPA" OR tx_state="MLS" OR tx_state="DSS" OR tx_state="FUS",mvzip(tx_state,_time),null()) | transaction tx_id startswith="FPA" endswith="FUS" mvlist=phaseTime | search credit_bureau | mvexpand phaseTime  | rex field=phaseTime "(?&amp;amp;lt;tx_state&amp;amp;gt;.*),(?&amp;amp;lt;tx_state_time&amp;amp;gt;.*)" | streamstats current=f window=1 last(tx_state_time) as prevTime by tx_id | eval elapsedTime=if(isnull(prevTime),null(),tx_state_time - prevTime) | chart avg(elapsedTime) avg(duration) by tx_id tx_state
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 May 2015 12:29:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173020#M49612</guid>
      <dc:creator>wpreston</dc:creator>
      <dc:date>2015-05-07T12:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Transaction with Multiple events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173021#M49613</link>
      <description>&lt;P&gt;I still see negative numbers for FPA when looking at that data:&lt;/P&gt;

&lt;P&gt;tx_id                                                   DSS                     FPA                FUS               MLS&lt;BR /&gt;
554a6ed6e4b0fea9d1816525    1.254500    -20.044000  16.710500   2.079000&lt;BR /&gt;
554a6fcbe4b0fea9d1816526    0.222000    -1.704000   1.159500    0.322500&lt;BR /&gt;
554a6fcbe4b0fea9d1816527    0.196500    -6.602000   3.988500    2.417000&lt;/P&gt;

&lt;P&gt;Whereas the order should be FPA, MLS, DSS, FUS&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 15:00:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173021#M49613</guid>
      <dc:creator>JoeSco27</dc:creator>
      <dc:date>2015-05-07T15:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: Transaction with Multiple events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173022#M49614</link>
      <description>&lt;P&gt;what additional search commands are you running?  Can you post the full search string that gave you these negative numbers?&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2015 15:32:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Transaction-with-Multiple-events/m-p/173022#M49614</guid>
      <dc:creator>wpreston</dc:creator>
      <dc:date>2015-05-07T15:32:58Z</dc:date>
    </item>
  </channel>
</rss>

