<?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 Re: Calculating times between segments/steps in a conversation/transaction in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Calculating-times-between-segments-steps-in-a-conversation/m-p/52410#M12734</link>
    <description>&lt;P&gt;hey, your sample log didn't show up in the question...&lt;/P&gt;</description>
    <pubDate>Fri, 17 Sep 2010 01:49:41 GMT</pubDate>
    <dc:creator>ftk</dc:creator>
    <dc:date>2010-09-17T01:49:41Z</dc:date>
    <item>
      <title>Calculating times between segments/steps in a conversation/transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-times-between-segments-steps-in-a-conversation/m-p/52409#M12733</link>
      <description>&lt;P&gt;Is it possible to dynamically calculate the RHS of a search comparison?&lt;/P&gt;

&lt;P&gt;I'm looking to use Splunk to do latency measurements across various segments of a processing pipeline, e.g.:&lt;/P&gt;

&lt;P&gt;A -&amp;gt; B -&amp;gt; C&lt;/P&gt;

&lt;P&gt;I have a log that looks like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;conversationId&amp;gt; &amp;lt;timestamp&amp;gt; &amp;lt;segment (e.g. A, B or C)&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Where conversationId is used to correlate messages related to a single 'conversation' as they flow through the pipeline.&lt;/P&gt;

&lt;P&gt;I can calculate end-to-end latency like so:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="source" segment="C" |
eval endTime=timestamp |
fields conversationId, endTime |
join type=outer conversationId [
  search sourcetype="source" segment="A" |
  eval startTime=timestamp |
  fields conversationId, startTime
] |
eval latency=(endTime-startTime) |
fields conversationId, latency
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;which works, but I need to explicitly identify the start and end segments. I'd like to be able to generalize this so that I can calc latency across each of the subsegments without having to name each of them (this becomes a pain as the number of segments increases or changes).&lt;/P&gt;

&lt;P&gt;My idea was to include info about the previous segment in the log messages:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  &amp;lt;conversationId&amp;gt; &amp;lt;timestamp&amp;gt; &amp;lt;segment (e.g. A, B or C)&amp;gt; &amp;lt;previousSegment)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And then have a search like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="source" |
eval prev=previousSegment |
eval endTime=timestamp |
fields conversationId, previousSegment, endTime |
join type=outer conversationId [
  search sourcetype="source" segment=***prev*** |
  eval startTime=timestamp |
  fields conversationId, startTime
] |
eval latency=(endTime-startTime) |
fields conversationId, latency
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I can't get this to work however. Is there some way to be able to use a calculated field in the RHS of a search comparison?&lt;/P&gt;

&lt;P&gt;Thanks,
Edwin&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2010 00:39:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-times-between-segments-steps-in-a-conversation/m-p/52409#M12733</guid>
      <dc:creator>esp</dc:creator>
      <dc:date>2010-09-17T00:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating times between segments/steps in a conversation/transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-times-between-segments-steps-in-a-conversation/m-p/52410#M12734</link>
      <description>&lt;P&gt;hey, your sample log didn't show up in the question...&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2010 01:49:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-times-between-segments-steps-in-a-conversation/m-p/52410#M12734</guid>
      <dc:creator>ftk</dc:creator>
      <dc:date>2010-09-17T01:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating times between segments/steps in a conversation/transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-times-between-segments-steps-in-a-conversation/m-p/52411#M12735</link>
      <description>&lt;P&gt;Hello esp, have you considered using the &lt;CODE&gt;transaction&lt;/CODE&gt; command to accomplish this?  It will automatically group events across segments (A-&amp;gt;B-&amp;gt;C) whose conversationid field have the same value.  As a bonus, you also get the latency calculated between the earliest event and latest event in the same transaction.  This latency is computed as the &lt;CODE&gt;duration&lt;/CODE&gt; field.&lt;/P&gt;

&lt;P&gt;Since the sample data didn't come through, I'll just sketch the search:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;sourcetype=source segment=A OR segment=B OR segment=C | transaction conversationid&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;There are lots of options to defining transactions, including how far apart the events are in relation to each other, what is the maximum time range for a group of events, what event marks the start/end of the transaction, etc.  Details on the &lt;CODE&gt;transaction&lt;/CODE&gt; command are in the &lt;A href="http://www.splunk.com/base/Documentation/latest/SearchReference/Transaction" rel="nofollow"&gt;Command Reference&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2010 02:07:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-times-between-segments-steps-in-a-conversation/m-p/52411#M12735</guid>
      <dc:creator>hulahoop</dc:creator>
      <dc:date>2010-09-17T02:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating times between segments/steps in a conversation/transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-times-between-segments-steps-in-a-conversation/m-p/52412#M12736</link>
      <description>&lt;P&gt;I don't think you need to (nor should you) do what you seem to be trying.&lt;/P&gt;

&lt;P&gt;Seems this search could much more easily and efficiently be done with:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=source 
| stats 
    first(_time) as latest
    last(_time) as earliest
  by conversationId
| eval latency = latest-earliest
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Alternatively, if for some reason &lt;CODE&gt;_time&lt;/CODE&gt; isn't the same as &lt;CODE&gt;timestamp&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=source 
| stats 
    max(timestamp) as latest
    min(timestamp) as earliest
  by conversationId
| eval latency = latest-earliest
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;/P&gt;

&lt;P&gt;Update: Oh I see, you want the diffs between each stage. Then you'd need:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source=sourcetype
| streamstats global=f window=2 current=t
    max(_time) as currenttime
    min(_time) as prevtime
  by
    conversationId
| eval latency=later-earlier
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I think. I may have it off-by-one, so the latency is for the &lt;EM&gt;next&lt;/EM&gt; stage instead of the &lt;EM&gt;previous&lt;/EM&gt; stage.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2010 06:39:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-times-between-segments-steps-in-a-conversation/m-p/52412#M12736</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2010-09-17T06:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating times between segments/steps in a conversation/transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-times-between-segments-steps-in-a-conversation/m-p/52413#M12737</link>
      <description>&lt;P&gt;I believe that your approach is more complicated and less efficient than necessary. Instead of your specific question about variable substitution, I have answered with what I think is a better way to get the results you seem to be asking for.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2010 10:38:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-times-between-segments-steps-in-a-conversation/m-p/52413#M12737</guid>
      <dc:creator>gkanapathy</dc:creator>
      <dc:date>2010-09-17T10:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating times between segments/steps in a conversation/transaction</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Calculating-times-between-segments-steps-in-a-conversation/m-p/52414#M12738</link>
      <description>&lt;P&gt;This is something we've built a search command to do in the &lt;A href="http://splunk-base.splunk.com/apps/29011/splunk-app-for-transaction-profiling"&gt;Splunk App for Transaction Profiling&lt;/A&gt;. Look in the menu for Samples -&amp;gt; Steps. The current version on Splunkbase, Preview 2, still requires you to identify each segment; but we're looking at ways to more generally define when a new segment starts. &lt;/P&gt;

&lt;P&gt;Esp, the product team would like to engage with you offline. Can you please email &lt;A href="mailto:transactionprofiling@splunk.com"&gt;transactionprofiling@splunk.com&lt;/A&gt;?&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2011 21:10:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Calculating-times-between-segments-steps-in-a-conversation/m-p/52414#M12738</guid>
      <dc:creator>splunksolutions</dc:creator>
      <dc:date>2011-10-11T21:10:12Z</dc:date>
    </item>
  </channel>
</rss>

