<?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 Accessing fields from specific events in a transaction in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Accessing-fields-from-specific-events-in-a-transaction/m-p/247643#M73868</link>
    <description>&lt;P&gt;I have logs which contain a value, time_taken. I want to work out the latency of entire transactions by summing the time_taken from each. I'm using transaction to pull these related events into one event. I cannot use the "duration" field generated by the transaction command, as this is generated from the time difference of the events, I want to sum the time_taken values from each event so the time taken of the second event is not ignored.&lt;/P&gt;

&lt;P&gt;A single now look like this (they are in json format):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"field1": "1", "field2": "2", ...... ,"time_taken":"0:00:01.404100"}
{"field1": "5", "field2": "2", ...... ,"time_taken":"0:00:00.663664"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The "time_taken" fields are both being picked up, so I have multiple time_taken fields for each event.&lt;/P&gt;

&lt;P&gt;Is there a simple way to access fields from each event, specifically, I want to create a new field, summing the time_taken fields, for each event (note that some of the events have 1 event and some have more than 2). Is this possible?&lt;/P&gt;

&lt;P&gt;Many thanks.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 08:33:12 GMT</pubDate>
    <dc:creator>jpanderson</dc:creator>
    <dc:date>2020-09-29T08:33:12Z</dc:date>
    <item>
      <title>Accessing fields from specific events in a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Accessing-fields-from-specific-events-in-a-transaction/m-p/247643#M73868</link>
      <description>&lt;P&gt;I have logs which contain a value, time_taken. I want to work out the latency of entire transactions by summing the time_taken from each. I'm using transaction to pull these related events into one event. I cannot use the "duration" field generated by the transaction command, as this is generated from the time difference of the events, I want to sum the time_taken values from each event so the time taken of the second event is not ignored.&lt;/P&gt;

&lt;P&gt;A single now look like this (they are in json format):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;{"field1": "1", "field2": "2", ...... ,"time_taken":"0:00:01.404100"}
{"field1": "5", "field2": "2", ...... ,"time_taken":"0:00:00.663664"}
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The "time_taken" fields are both being picked up, so I have multiple time_taken fields for each event.&lt;/P&gt;

&lt;P&gt;Is there a simple way to access fields from each event, specifically, I want to create a new field, summing the time_taken fields, for each event (note that some of the events have 1 event and some have more than 2). Is this possible?&lt;/P&gt;

&lt;P&gt;Many thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:33:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Accessing-fields-from-specific-events-in-a-transaction/m-p/247643#M73868</guid>
      <dc:creator>jpanderson</dc:creator>
      <dc:date>2020-09-29T08:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing fields from specific events in a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Accessing-fields-from-specific-events-in-a-transaction/m-p/247644#M73869</link>
      <description>&lt;P&gt;hi jpanderson,&lt;/P&gt;

&lt;P&gt;try like this:&lt;/P&gt;

&lt;P&gt;uses the regular expression to extract the values that appear in your time_taken events and saves them in a new field. After, you can now work with the new field that will contain all values of time_taken.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:33:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Accessing-fields-from-specific-events-in-a-transaction/m-p/247644#M73869</guid>
      <dc:creator>gyslainlatsa</dc:creator>
      <dc:date>2020-09-29T08:33:15Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing fields from specific events in a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Accessing-fields-from-specific-events-in-a-transaction/m-p/247645#M73870</link>
      <description>&lt;P&gt;Just to know, do you really need transaction to collect these events together and then sum the values? If you have a common field (you must be using it for transaction to correlate events - assume it's  field1), then simple stats should work for you&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search + field extractions from json| stats sum(time_taken) by field1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you still want to use transaction use streamstats to create unique ids and then sum it,&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;transaction field1 and other options| streamstats count AS event_id| stats sum(time_taken) by event_id
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This should create unique id for your each transaction and then sum the values based on this unique id&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 11:32:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Accessing-fields-from-specific-events-in-a-transaction/m-p/247645#M73870</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2016-01-26T11:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing fields from specific events in a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Accessing-fields-from-specific-events-in-a-transaction/m-p/247646#M73871</link>
      <description>&lt;P&gt;You need to convert your time_taken field to seconds and then use "stats sum(time_taken), list(field1) as field1, ..., list(fieldN) as fieldN by YOUR_TRANSACTION_UNIQUE_ID"&lt;/P&gt;

&lt;P&gt;Note there's a dur2sec function but it won't work in your case as you also have microseconds.&lt;/P&gt;

&lt;P&gt;In summary, something like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| yourtransactionhere
| rex field=time_taken "(?&amp;lt;H&amp;gt;\d{1,2}):(?&amp;lt;M&amp;gt;\d{2}):(?&amp;lt;S&amp;gt;\d{2})\.(?&amp;lt;uS&amp;gt;\d{6})"
| eval time_taken_seconds = 
    tonumber(H)*3600 + 
    tonumber(M)*60 + 
    tonumber(S) + 
    tonumber("0.".uS)
| stats sum(time_taken_seconds) as total_time_taken_seconds, 
    list(field1) as field1, ..., 
    list(fieldN) as fieldN 
    by YOUR_TRANSACTION_UNIQUE_ID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know if that helps.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:33:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Accessing-fields-from-specific-events-in-a-transaction/m-p/247646#M73871</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2020-09-29T08:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing fields from specific events in a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Accessing-fields-from-specific-events-in-a-transaction/m-p/247647#M73872</link>
      <description>&lt;P&gt;I've got the following code&lt;/P&gt;

&lt;P&gt;mysearch...&lt;BR /&gt;
   | rex field=time_taken "(?\d{1,2}):(?\d{2}):(?\d{2}).(?\d{6})" &lt;BR /&gt;
   | eval transaction_time = tonumber(H)*3600 + tonumber(M)*60 + tonumber(S) + tonumber("0.".uS)&lt;BR /&gt;
   | stats sum(transaction_time) by DutyId&lt;/P&gt;

&lt;P&gt;It's correctly parsing the H, M, S, uS fields, however the eval command is creating only one time value, wierdly!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:33:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Accessing-fields-from-specific-events-in-a-transaction/m-p/247647#M73872</guid>
      <dc:creator>jpanderson</dc:creator>
      <dc:date>2020-09-29T08:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing fields from specific events in a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Accessing-fields-from-specific-events-in-a-transaction/m-p/247648#M73873</link>
      <description>&lt;P&gt;Try using &lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/mvexpand"&gt;mvexpand&lt;/A&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;mysearch...
| mvexpand time_taken
| rex field=time_taken "(?&amp;lt;H&amp;gt;\d{1,2}):(?&amp;lt;M&amp;gt;\d{2}):(?&amp;lt;S&amp;gt;\d{2})\.(?&amp;lt;uS&amp;gt;\d{6})"
| eval transaction_time = tonumber(H)*3600 + tonumber(M)*60 + tonumber(S) + tonumber("0.".uS)
| stats sum(transaction_time) by DutyId
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Jan 2016 12:02:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Accessing-fields-from-specific-events-in-a-transaction/m-p/247648#M73873</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-01-26T12:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: Accessing fields from specific events in a transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Accessing-fields-from-specific-events-in-a-transaction/m-p/247649#M73874</link>
      <description>&lt;P&gt;Ok I got it working, I had to use the rex command before running the transaction.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Jan 2016 12:05:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Accessing-fields-from-specific-events-in-a-transaction/m-p/247649#M73874</guid>
      <dc:creator>jpanderson</dc:creator>
      <dc:date>2016-01-26T12:05:12Z</dc:date>
    </item>
  </channel>
</rss>

