<?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 Find Time-Range for Most Recent event. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Find-Time-Range-for-Most-Recent-event/m-p/299928#M90337</link>
    <description>&lt;P&gt;So I have splunk events and I want to display information as a time range. For example:&lt;BR /&gt;
event type1: Started proc1 id=123&lt;BR /&gt;
event type2:  Stoped proc1 id=123&lt;BR /&gt;
(Assume id 123 is associated with proc1)&lt;BR /&gt;
So I want to display the time duration for which proc1 ran most recently.  I have following splunk query:&lt;BR /&gt;
index | search "started" OR  "Stopped" | where id=123 | sort - _time | head 2&lt;/P&gt;

&lt;P&gt;This gives me the 2 events which I'am interested in. But how can I extract the _time from both events?&lt;/P&gt;</description>
    <pubDate>Sun, 02 Apr 2017 05:53:11 GMT</pubDate>
    <dc:creator>njwrk</dc:creator>
    <dc:date>2017-04-02T05:53:11Z</dc:date>
    <item>
      <title>Find Time-Range for Most Recent event.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-Time-Range-for-Most-Recent-event/m-p/299928#M90337</link>
      <description>&lt;P&gt;So I have splunk events and I want to display information as a time range. For example:&lt;BR /&gt;
event type1: Started proc1 id=123&lt;BR /&gt;
event type2:  Stoped proc1 id=123&lt;BR /&gt;
(Assume id 123 is associated with proc1)&lt;BR /&gt;
So I want to display the time duration for which proc1 ran most recently.  I have following splunk query:&lt;BR /&gt;
index | search "started" OR  "Stopped" | where id=123 | sort - _time | head 2&lt;/P&gt;

&lt;P&gt;This gives me the 2 events which I'am interested in. But how can I extract the _time from both events?&lt;/P&gt;</description>
      <pubDate>Sun, 02 Apr 2017 05:53:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-Time-Range-for-Most-Recent-event/m-p/299928#M90337</guid>
      <dc:creator>njwrk</dc:creator>
      <dc:date>2017-04-02T05:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: Find Time-Range for Most Recent event.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-Time-Range-for-Most-Recent-event/m-p/299929#M90338</link>
      <description>&lt;P&gt;You can easily create a transaction with id as if transaction id and startswith and endswith criteria as *Started* and *Stopped* respectively. Transaction command automatically generates the correlated &lt;STRONG&gt;eventcount&lt;/STRONG&gt; and &lt;STRONG&gt;duration&lt;/STRONG&gt; between the events. However, stats will be faster and better alternative in this scenario. Please give following a try:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=&amp;lt;YourIndexName&amp;gt; "Started" OR "Stopped" id=*
| eval Status=if(searchmatch("Started"),"Started","Stopped")
| stats count as eventcount values(Status) as Status min(_time) as MinTime max(_time) as MaxTime by id
| search eventcount&amp;gt;1 Status="Started" Statsus="Stopped"
| eval duration=MaxTime-MinTime
| eval _time=MinTime
| fieldformat MinTime=strftime(MinTIme,"%c")
| fieldformat MaxTime=strftime(MaxTIme,"%c")
| table _time Status id duration MinTime MaxTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to find transactions which have started but not stopped you can change the search criteria accordingly.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Apr 2017 13:16:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-Time-Range-for-Most-Recent-event/m-p/299929#M90338</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-04-02T13:16:37Z</dc:date>
    </item>
    <item>
      <title>Re: Find Time-Range for Most Recent event.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-Time-Range-for-Most-Recent-event/m-p/299930#M90339</link>
      <description>&lt;P&gt;@njwrk Please accept the answer if this has helped.&lt;/P&gt;</description>
      <pubDate>Sun, 02 Apr 2017 20:21:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-Time-Range-for-Most-Recent-event/m-p/299930#M90339</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-04-02T20:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: Find Time-Range for Most Recent event.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Find-Time-Range-for-Most-Recent-event/m-p/299931#M90340</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=YourIndexHere sourcetype=YourSourcetypeHere started OR stopped | stats range(_time) AS duration BY id
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Apr 2017 04:39:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Find-Time-Range-for-Most-Recent-event/m-p/299931#M90340</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-04-03T04:39:20Z</dc:date>
    </item>
  </channel>
</rss>

