<?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: Graphing Elapsed Time in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Graphing-Elapsed-Time/m-p/685653#M233948</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;Lastly I will figure out how to organize this by Day in desc order; right now it is sorting the results by another column...&amp;nbsp;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Yes, Splunk has some weird obsession with alphabetic/ASCII ordering unless you tell it otherwise. (It kind of surprises me when the "natural" sorting order is already set in groupby (numeric on original value of "day") but Splunk changes it after adding character string "day -".) &amp;nbsp;All you need to do is to insert sort after stats and before that string conversion.&lt;/P&gt;&lt;P&gt;When you say in desc order, I imagine that you want the reverse numeric order. &amp;nbsp;Is this correct?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=*app_pcf cf_app_name="mddr-batch-integration-flow" "posbatch04" earliest=-14d@d latest=-0d@d
| eval dayback = mvrange(0, 14)
| eval day = mvmap(dayback, if(_time &amp;lt; relative_time(now(), "-" . dayback . "d@day") AND relative_time(now(), "-" . tostring(dayback + 1) . "d@day") &amp;lt; _time, dayback, null()))
| stats min(_time) as Earliest max(_time) as Latest by day
| sort - day
| fieldformat Earliest = strftime(Earliest, "%F %T")
| fieldformat Latest = strftime(Latest, "%F %T")
| eval day = "day -" . tostring(day + 1)
| eval Elapsed_Time=Latest-Earliest, Start_Time_Std=strftime(Earliest,"%H:%M:%S:%Y-%m-%d"), End_Time_Std=strftime(Latest,"%H:%M:%S:%Y-%m-%d")
| eval Elapsed_Time=Elapsed_Time/60&lt;/LI-CODE&gt;&lt;P&gt;If you want to last day first, just &amp;nbsp;&lt;FONT face="courier new,courier"&gt;| sort day&lt;/FONT&gt;.&lt;/P&gt;</description>
    <pubDate>Fri, 26 Apr 2024 16:25:41 GMT</pubDate>
    <dc:creator>yuanliu</dc:creator>
    <dc:date>2024-04-26T16:25:41Z</dc:date>
    <item>
      <title>Graphing Elapsed Time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Graphing-Elapsed-Time/m-p/685361#M233854</link>
      <description>&lt;P&gt;Hi all -&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am a Splunk Novice, especially when it comes to writing my own queries.&amp;nbsp; I have created a Splunk Query that serves my first goal:&amp;nbsp; calculate elapsed time between 2 events.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Now, goal #2 is to graph that over a time period (i.e. 7 days).&amp;nbsp; What is stalling my brain is that these events happen&amp;nbsp;&lt;EM&gt;every day&lt;/EM&gt; - in fact, they are batches that run on a cron schedule, so they better be happening every day!&amp;nbsp; So I am unable to just change the time preset and graph this, because I am using earliest and latest events to calculate beginning and end.&amp;nbsp; Here is my query to calculate duration:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=*XYZ" "Batchname1"
| stats earliest(_time) AS Earliest, latest(_time) AS Latest
| eval Elapsed_Time=Latest-Earliest, Start_Time_Std=strftime(Earliest,"%H:%M:%S:%Y-%m-%d"), End_Time_Std=strftime(Latest,"%H:%M:%S:%Y-%m-%d")
| eval Elapsed_Time=Elapsed_Time/60
| table Start_Time_Std, End_Time_Std, Elapsed_Time&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Any ideas on how to graph this duration over time so I can develop trend lines, etc?&amp;nbsp; Thanks all for the help!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Apr 2024 18:04:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Graphing-Elapsed-Time/m-p/685361#M233854</guid>
      <dc:creator>Memphis</dc:creator>
      <dc:date>2024-04-24T18:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: Graphing Elapsed Time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Graphing-Elapsed-Time/m-p/685378#M233856</link>
      <description>&lt;P&gt;First, on thought process. &amp;nbsp;Splunk allows you to create additional field in event stream. &amp;nbsp;If you mark each day as "day -1", "day -2", etc., you can group earliest and latest by day.&lt;/P&gt;&lt;P&gt;This is how to do that in Splunk&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=*XYZ" "Batchname1" earliest=-7d@d latest=-0d@d
| eval dayback = mvrange(0, 7)
| eval day = mvmap(dayback, if(_time &amp;lt; relative_time(now(), "-" . dayback . "d@day") AND relative_time(now(), "-" . tostring(dayback + 1) . "d@day") &amp;lt; _time, dayback, null()))
| stats min(_time) as Earliest max(_time) as Latest by day
| fieldformat Earliest = strftime(Earliest, "%F %T")
| fieldformat Latest = strftime(Latest, "%F %T")
| eval day = "day -" . tostring(day + 1)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output looks like&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;day&lt;/TD&gt;&lt;TD&gt;Earliest&lt;/TD&gt;&lt;TD&gt;Latest&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;day -1&lt;/TD&gt;&lt;TD&gt;2024-04-23 00:01:00&lt;/TD&gt;&lt;TD&gt;2024-04-23 23:53:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;day -2&lt;/TD&gt;&lt;TD&gt;2024-04-22 09:29:00&lt;/TD&gt;&lt;TD&gt;2024-04-22 23:31:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;day -3&lt;/TD&gt;&lt;TD&gt;2024-04-21 14:29:00&lt;/TD&gt;&lt;TD&gt;2024-04-21 14:29:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;day -4&lt;/TD&gt;&lt;TD&gt;2024-04-20 00:01:00&lt;/TD&gt;&lt;TD&gt;2024-04-20 19:14:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;day -5&lt;/TD&gt;&lt;TD&gt;2024-04-19 01:13:00&lt;/TD&gt;&lt;TD&gt;2024-04-19 23:47:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;day -6&lt;/TD&gt;&lt;TD&gt;2024-04-18 00:01:00&lt;/TD&gt;&lt;TD&gt;2024-04-18 23:28:00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;day -7&lt;/TD&gt;&lt;TD&gt;2024-04-17 00:01:00&lt;/TD&gt;&lt;TD&gt;2024-04-17 23:14:00&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Two pointers:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;It doesn't seem to make sense to search in current day. &amp;nbsp;So I shifted search period to &lt;A href="mailto:-0day@day" target="_blank" rel="noopener"&gt;-0day@day&lt;/A&gt;. &amp;nbsp;If your requirement includes current day, you need to change latest as well as tweak the definition of day a little.&lt;/LI&gt;&lt;LI&gt;Do not use earliest(_time); min(_time) is cheaper.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;The following is the emulation I use to test the above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index = _audit earliest=-7d@d latest=-0d@d action=validate_token
| timechart span=1m count
| where count &amp;gt; 0
``` emulation of
index=*XYZ" "Batchname1" earliest=-7d@d latest=-0d@d
```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 00:13:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Graphing-Elapsed-Time/m-p/685378#M233856</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-04-25T00:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: Graphing Elapsed Time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Graphing-Elapsed-Time/m-p/685630#M233946</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;! This worked really well.&amp;nbsp; I added my eval commands to it as well and was able to produce the table that I was seeking, with your great query as a guide.&amp;nbsp; &amp;nbsp;I've expanded the time range to 14 days bc I realized 7 days was a little pointless since most of my batches only run M-F.&amp;nbsp; My final query ended up being:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=*app_pcf cf_app_name="mddr-batch-integration-flow" "posbatch04" earliest=-14d@d latest=-0d@d
| eval dayback = mvrange(0, 14)
| eval day = mvmap(dayback, if(_time &amp;lt; relative_time(now(), "-" . dayback . "d@day") AND relative_time(now(), "-" . tostring(dayback + 1) . "d@day") &amp;lt; _time, dayback, null()))
| stats min(_time) as Earliest max(_time) as Latest by day
| fieldformat Earliest = strftime(Earliest, "%F %T")
| fieldformat Latest = strftime(Latest, "%F %T")
| eval day = "day -" . tostring(day + 1)
| eval Elapsed_Time=Latest-Earliest, Start_Time_Std=strftime(Earliest,"%H:%M:%S:%Y-%m-%d"), End_Time_Std=strftime(Latest,"%H:%M:%S:%Y-%m-%d")
| eval Elapsed_Time=Elapsed_Time/60
&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;Lastly I will figure out how to organize this by Day in desc order; right now it is sorting the results by another column...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Much appreciated for the help and the fast response, I would have never figured this out &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 16:02:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Graphing-Elapsed-Time/m-p/685630#M233946</guid>
      <dc:creator>Memphis</dc:creator>
      <dc:date>2024-04-26T16:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Graphing Elapsed Time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Graphing-Elapsed-Time/m-p/685653#M233948</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;Lastly I will figure out how to organize this by Day in desc order; right now it is sorting the results by another column...&amp;nbsp;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Yes, Splunk has some weird obsession with alphabetic/ASCII ordering unless you tell it otherwise. (It kind of surprises me when the "natural" sorting order is already set in groupby (numeric on original value of "day") but Splunk changes it after adding character string "day -".) &amp;nbsp;All you need to do is to insert sort after stats and before that string conversion.&lt;/P&gt;&lt;P&gt;When you say in desc order, I imagine that you want the reverse numeric order. &amp;nbsp;Is this correct?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=*app_pcf cf_app_name="mddr-batch-integration-flow" "posbatch04" earliest=-14d@d latest=-0d@d
| eval dayback = mvrange(0, 14)
| eval day = mvmap(dayback, if(_time &amp;lt; relative_time(now(), "-" . dayback . "d@day") AND relative_time(now(), "-" . tostring(dayback + 1) . "d@day") &amp;lt; _time, dayback, null()))
| stats min(_time) as Earliest max(_time) as Latest by day
| sort - day
| fieldformat Earliest = strftime(Earliest, "%F %T")
| fieldformat Latest = strftime(Latest, "%F %T")
| eval day = "day -" . tostring(day + 1)
| eval Elapsed_Time=Latest-Earliest, Start_Time_Std=strftime(Earliest,"%H:%M:%S:%Y-%m-%d"), End_Time_Std=strftime(Latest,"%H:%M:%S:%Y-%m-%d")
| eval Elapsed_Time=Elapsed_Time/60&lt;/LI-CODE&gt;&lt;P&gt;If you want to last day first, just &amp;nbsp;&lt;FONT face="courier new,courier"&gt;| sort day&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 16:25:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Graphing-Elapsed-Time/m-p/685653#M233948</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-04-26T16:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Graphing Elapsed Time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Graphing-Elapsed-Time/m-p/685656#M233949</link>
      <description>&lt;P&gt;Aren't you overcomplicating it a bit?&lt;/P&gt;&lt;P&gt;Just render the date to a field&lt;/P&gt;&lt;PRE&gt;| eval day=strftime(_time,"%F")&lt;/PRE&gt;&lt;P&gt;and you're ready to go&lt;/P&gt;&lt;PRE&gt;| stats min(_time) as earliest max(_time) as latest by day&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Apr 2024 16:38:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Graphing-Elapsed-Time/m-p/685656#M233949</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-04-26T16:38:35Z</dc:date>
    </item>
  </channel>
</rss>

