<?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: How to extract the start and end date/time from my sample data, then calculate the duration of a job? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215401#M63131</link>
    <description>&lt;PRE&gt;&lt;CODE&gt;index=aap_prod sourcetype="HDP:PROD:OOZIE" ("@:start:" OR "@end") 
 | rex field=_raw "(?&amp;lt;date&amp;gt;\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2},\d{3})\s(?&amp;lt;log_level&amp;gt;\w+)\s(?&amp;lt;unknownfield&amp;gt;\w+):(?&amp;lt;number&amp;gt;\d+)\s-\sSERVER\[(?&amp;lt;servername&amp;gt;\S+)] USER\[(?&amp;lt;username&amp;gt;\S+)]\sGROUP\[(?&amp;lt;groupname&amp;gt;\S+)]\sTOKEN\[]\sAPP\[(?&amp;lt;appname&amp;gt;\S+)]\sJOB\[(?&amp;lt;jobname&amp;gt;\S+)]\sACTION\[\S+@(?&amp;lt;action&amp;gt;.*)]\s\["
  | search action=:start:
  | stats first(_time) AS startTime by servername
  | append [ 
   search index=aap_prod sourcetype="HDP:PROD:OOZIE" ("@:start:" OR "@end") 
   | rex field=_raw "(?&amp;lt;date&amp;gt;\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2},\d{3})\s(?&amp;lt;log_level&amp;gt;\w+)\s(?&amp;lt;unknownfield&amp;gt;\w+):(?&amp;lt;number&amp;gt;\d+)\s-\sSERVER\[(?&amp;lt;servername&amp;gt;\S+)] USER\[(?&amp;lt;username&amp;gt;\S+)]\sGROUP\[(?&amp;lt;groupname&amp;gt;\S+)]\sTOKEN\[]\sAPP\[(?&amp;lt;appname&amp;gt;\S+)]\sJOB\[(?&amp;lt;jobname&amp;gt;\S+)]\sACTION\[\S+@(?&amp;lt;action&amp;gt;.*)]\s\["
   | stats first(_time) AS endTime by servername
  ]
  | chart eval(sum(endTime)-sum(startTime)) AS diffTimeInSecs by servername
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 06 Jan 2016 20:45:01 GMT</pubDate>
    <dc:creator>jkat54</dc:creator>
    <dc:date>2016-01-06T20:45:01Z</dc:date>
    <item>
      <title>How to extract the start and end date/time from my sample data, then calculate the duration of a job?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215395#M63125</link>
      <description>&lt;P&gt;Hi &lt;/P&gt;

&lt;P&gt;I have to extract start date, end date, and the duration of a job based on the following two events:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Started:
2016-01-06 07:00:10,314  INFO ActionStartXCommand:543 - SERVER[redacted.redacted.redacted.com] USER[hdfs] GROUP[-] TOKEN[] APP[BOB_CAS_WF_IM_DataStore] JOB[0018443-150810162217214-oozie-oozi-W] ACTION[0018443-150810162217214-oozie-oozi-W@:start:] [***0018443-150810162217214-oozie-oozi-W@:start:***]Action updated in DB!


End:
2016-01-06 08:10:50,301  INFO ActionStartXCommand:543 - SERVER[redacted.redacted.redacted.com] USER[hdfs] GROUP[-] TOKEN[] APP[BOB_CAS_WF_IM_DataStore] JOB[0018443-150810162217214-oozie-oozi-W] ACTION[0018443-150810162217214-oozie-oozi-W@end] [***0018443-150810162217214-oozie-oozi-W@end***]Action updated in DB!
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How do I extract the date and time and then calculate the difference.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2016 17:48:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215395#M63125</guid>
      <dc:creator>athorat</dc:creator>
      <dc:date>2016-01-06T17:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end date/time from my sample data, then calculate the duration of a job?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215396#M63126</link>
      <description>&lt;P&gt;Try something like this (untested code, assuming there are only two events per JOB)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "JOB\[?(?&amp;lt;jobid&amp;gt;[\d-]+)-" | streamstats window=2 current=f range(_time) as diff by jobid | table jobid diff | search diff=*
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jan 2016 18:47:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215396#M63126</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-01-06T18:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end date/time from my sample data, then calculate the duration of a job?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215397#M63127</link>
      <description>&lt;P&gt;In your props.conf:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[sourcetypeName]
SHOULD_LINEMERGE = false
BREAK_ONLY_BEFORE = \d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\,\d{3}
TIME_FORMAT = %Y-%m-%d %H:%M:%S,%3N
MAX_TIMESTAMP_LOOKAHEAD = 24
EXTRACT-myfields = (?&amp;lt;date&amp;gt;\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2},\d{3})\s(?&amp;lt;log_level&amp;gt;\w+)\s(?&amp;lt;unknownfield&amp;gt;\w+):(?&amp;lt;number&amp;gt;\d+)\s-\sSERVER\[(?&amp;lt;servername&amp;gt;\S+)] USER\[(?&amp;lt;username&amp;gt;\S+)]\sGROUP\[(?&amp;lt;groupname&amp;gt;\S+)]\sTOKEN\[]\sAPP\[(?&amp;lt;appname&amp;gt;\S+)]\sJOB\[(?&amp;lt;jobname&amp;gt;\S+)]\sACTION\[\S+@(?&amp;lt;action&amp;gt;.*)]\s\[
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Your search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index="foo" servername="server.acme.com" action=:start: 
| stats first(_time) AS startTime BY servername 
| append [
   search index="foo" sourcetype="testing" servername="server.acme.com" action=end 
   | stats first(_time) AS endTime BY servername 
] | chart eval(sum(endTime)-sum(startTime)) AS diffTimeInSecs by servername
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jan 2016 19:01:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215397#M63127</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-01-06T19:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end date/time from my sample data, then calculate the duration of a job?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215398#M63128</link>
      <description>&lt;P&gt;thanks for the reply @jka154 @sundareshr &lt;/P&gt;

&lt;P&gt;I am using the following query to extract job name and Action=:start: or Action=@end&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=aap_prod sourcetype="HDP:PROD:OOZIE"  ("@:start:" OR "@end")  | rex "TOKEN\[\] APP\[(?[^\]]*)"    | rex "ACTION\[[^\@]*(?[^\d\]]*)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If I append  &lt;CODE&gt;rex "JOB\[?(?[\d-]+)-" | streamstats window=2 current=f range(_time) as diff by jobid | table jobid diff&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I get the table but there are jobid's with the same id with value = 0 and then there is one value with the actual duration.&lt;BR /&gt;
How do we filter only the values with actual duration. &lt;BR /&gt;
tried using | stats values(jobid) which does not work.&lt;/P&gt;

&lt;P&gt;Thanks for looking into this.&lt;/P&gt;

&lt;P&gt;Anil.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2016 19:26:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215398#M63128</guid>
      <dc:creator>athorat</dc:creator>
      <dc:date>2016-01-06T19:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end date/time from my sample data, then calculate the duration of a job?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215399#M63129</link>
      <description>&lt;P&gt;Updated my answer above to show how you can filter out where diff is not calculated.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2016 20:31:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215399#M63129</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-01-06T20:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end date/time from my sample data, then calculate the duration of a job?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215400#M63130</link>
      <description>&lt;P&gt;@sundareshr&lt;/P&gt;

&lt;P&gt;I tired |  search diff!=0.0 and it worked.&lt;BR /&gt;
How can I add the Start and the end dates, can you throw some light on it ?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2016 20:43:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215400#M63130</guid>
      <dc:creator>athorat</dc:creator>
      <dc:date>2016-01-06T20:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end date/time from my sample data, then calculate the duration of a job?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215401#M63131</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;index=aap_prod sourcetype="HDP:PROD:OOZIE" ("@:start:" OR "@end") 
 | rex field=_raw "(?&amp;lt;date&amp;gt;\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2},\d{3})\s(?&amp;lt;log_level&amp;gt;\w+)\s(?&amp;lt;unknownfield&amp;gt;\w+):(?&amp;lt;number&amp;gt;\d+)\s-\sSERVER\[(?&amp;lt;servername&amp;gt;\S+)] USER\[(?&amp;lt;username&amp;gt;\S+)]\sGROUP\[(?&amp;lt;groupname&amp;gt;\S+)]\sTOKEN\[]\sAPP\[(?&amp;lt;appname&amp;gt;\S+)]\sJOB\[(?&amp;lt;jobname&amp;gt;\S+)]\sACTION\[\S+@(?&amp;lt;action&amp;gt;.*)]\s\["
  | search action=:start:
  | stats first(_time) AS startTime by servername
  | append [ 
   search index=aap_prod sourcetype="HDP:PROD:OOZIE" ("@:start:" OR "@end") 
   | rex field=_raw "(?&amp;lt;date&amp;gt;\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2},\d{3})\s(?&amp;lt;log_level&amp;gt;\w+)\s(?&amp;lt;unknownfield&amp;gt;\w+):(?&amp;lt;number&amp;gt;\d+)\s-\sSERVER\[(?&amp;lt;servername&amp;gt;\S+)] USER\[(?&amp;lt;username&amp;gt;\S+)]\sGROUP\[(?&amp;lt;groupname&amp;gt;\S+)]\sTOKEN\[]\sAPP\[(?&amp;lt;appname&amp;gt;\S+)]\sJOB\[(?&amp;lt;jobname&amp;gt;\S+)]\sACTION\[\S+@(?&amp;lt;action&amp;gt;.*)]\s\["
   | stats first(_time) AS endTime by servername
  ]
  | chart eval(sum(endTime)-sum(startTime)) AS diffTimeInSecs by servername
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jan 2016 20:45:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215401#M63131</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-01-06T20:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end date/time from my sample data, then calculate the duration of a job?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215402#M63132</link>
      <description>&lt;P&gt;What happens if there are more than 2 events per job?&lt;/P&gt;

&lt;P&gt;I like how you simplified by jobid and used streamstats... pretty cool.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2016 20:49:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215402#M63132</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-01-06T20:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end date/time from my sample data, then calculate the duration of a job?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215403#M63133</link>
      <description>&lt;P&gt;@sundareshr&lt;/P&gt;

&lt;P&gt;I tired | search diff!=0.0 and it worked.&lt;BR /&gt;
How can I add the Start and the end dates, can you throw some light on it ?&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jan 2016 21:02:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215403#M63133</guid>
      <dc:creator>athorat</dc:creator>
      <dc:date>2016-01-06T21:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end date/time from my sample data, then calculate the duration of a job?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215404#M63134</link>
      <description>&lt;P&gt;Use this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;.... | streamstats current=f window=2 range(_time) as diff latest(_time) as end earliest(_time) as start| table jobid, diff, start, end | eval start=strftime(start, "%c") | search diff=*
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Jan 2016 21:15:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215404#M63134</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-01-06T21:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end date/time from my sample data, then calculate the duration of a job?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215405#M63135</link>
      <description>&lt;P&gt;My search works fine with the sample data you provided.  It's not as efficient as sundareshr's search but i believe it handles more scenarios / possibilities.  If you want to still see start/end, and diff, and servername...&lt;/P&gt;

&lt;P&gt;Edit my chart command at the end of my search on the bottom of my reply&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;...| chart startTime endTime eval(sum(endTime)-sum(startTime)) AS diffTimeInSecs  by servername&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2016 14:00:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215405#M63135</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-01-07T14:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end date/time from my sample data, then calculate the duration of a job?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215406#M63136</link>
      <description>&lt;P&gt;only issue is the time's will be in epoch...&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2016 14:02:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215406#M63136</guid>
      <dc:creator>jkat54</dc:creator>
      <dc:date>2016-01-07T14:02:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end date/time from my sample data, then calculate the duration of a job?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215407#M63137</link>
      <description>&lt;P&gt;@sundareshr  is there a way we can we convert the range-&amp;gt; diff to seconds or minutes?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jan 2016 19:01:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215407#M63137</guid>
      <dc:creator>athorat</dc:creator>
      <dc:date>2016-01-07T19:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract the start and end date/time from my sample data, then calculate the duration of a job?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215408#M63138</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| eval diff=tostring(diff, "duration")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jan 2016 19:06:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-extract-the-start-and-end-date-time-from-my-sample-data/m-p/215408#M63138</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-01-07T19:06:55Z</dc:date>
    </item>
  </channel>
</rss>

