<?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: Splunk Query stats with time intervals in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684154#M233550</link>
    <description>&lt;P&gt;My three cents on general approach to such tasks.&lt;/P&gt;&lt;P&gt;Since "last 15 minutes" and "last 10 minutes" can be expressed in terms of 5-minute periods, you can simply either use a timechart with 5-minute bins or bin manually time to 5-minute buckets and do stats over the 5-minute periods. And then - when you have those 5-minute stats - you can aggregate last two or last three stats to get summarized "last 10 minutes" and "last 15 minutes" values.&lt;/P&gt;&lt;P&gt;It's often useful to see if the problem containing several "parallel" computations cannot be transformed to a single - maybe a bit more detailed - calculation and some form of aggregation after that.&lt;/P&gt;</description>
    <pubDate>Sat, 13 Apr 2024 09:30:24 GMT</pubDate>
    <dc:creator>PickleRick</dc:creator>
    <dc:date>2024-04-13T09:30:24Z</dc:date>
    <item>
      <title>Splunk Query stats with time intervals</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684118#M233542</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to build a splunk query using stats to get count of messages for last 5 min, last 10min and last 15min.Something like below. Kindly let me know how below can be achieved?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Transaction&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Last 5min Vol&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Last 10min Vol&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Last 15min Vol&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;&lt;P&gt;C&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2024 04:19:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684118#M233542</guid>
      <dc:creator>Satyapv</dc:creator>
      <dc:date>2024-04-13T04:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Query stats with time intervals</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684124#M233543</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/261738"&gt;@Satyapv&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;you can use eval to categorize your data:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;your_search&amp;gt;
| eval period=case(
   _time&amp;gt;now()-300,"Last 5min Vol",
   _time&amp;gt;now()-600,"Last 10min Vol",
   _time&amp;gt;now()-900,"Last 15min Vol")
| chart count OVER Transaction BY period&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2024 05:08:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684124#M233543</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2024-04-13T05:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Query stats with time intervals</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684132#M233544</link>
      <description>Hi&lt;BR /&gt;If query takes long, then maybe you should look if you should use time() instead of now()? 1st gives you current time and 2nd is time when query has started.&lt;BR /&gt;r. Ismo&lt;BR /&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/9.2.1/SearchReference/DateandTimeFunctions" target="_blank"&gt;http://docs.splunk.com/Documentation/Splunk/9.2.1/SearchReference/DateandTimeFunctions&lt;/A&gt;</description>
      <pubDate>Sat, 13 Apr 2024 06:28:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684132#M233544</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2024-04-13T06:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Query stats with time intervals</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684152#M233548</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;Is there way to combine this in stats instead of chart as i need extract few other fields also as par of stats?&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2024 08:27:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684152#M233548</guid>
      <dc:creator>Satyapv</dc:creator>
      <dc:date>2024-04-13T08:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Query stats with time intervals</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684153#M233549</link>
      <description>Can you give some sample events and how you would like to present results?</description>
      <pubDate>Sat, 13 Apr 2024 08:33:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684153#M233549</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2024-04-13T08:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Query stats with time intervals</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684154#M233550</link>
      <description>&lt;P&gt;My three cents on general approach to such tasks.&lt;/P&gt;&lt;P&gt;Since "last 15 minutes" and "last 10 minutes" can be expressed in terms of 5-minute periods, you can simply either use a timechart with 5-minute bins or bin manually time to 5-minute buckets and do stats over the 5-minute periods. And then - when you have those 5-minute stats - you can aggregate last two or last three stats to get summarized "last 10 minutes" and "last 15 minutes" values.&lt;/P&gt;&lt;P&gt;It's often useful to see if the problem containing several "parallel" computations cannot be transformed to a single - maybe a bit more detailed - calculation and some form of aggregation after that.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2024 09:30:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684154#M233550</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2024-04-13T09:30:24Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Query stats with time intervals</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684155#M233551</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Transaction&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Last 5min Vol&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Last 10min Vol&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Last 15min Vol Timeouts Errors&lt;/P&gt;&lt;P&gt;A&lt;/P&gt;&lt;P&gt;B&lt;/P&gt;&lt;P&gt;C&lt;/P&gt;</description>
      <pubDate>Sat, 13 Apr 2024 09:31:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684155#M233551</guid>
      <dc:creator>Satyapv</dc:creator>
      <dc:date>2024-04-13T09:31:42Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Query stats with time intervals</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684171#M233554</link>
      <description>&lt;P&gt;In addition to possible additions such as "Timeout Errors", you case requires an additional consideration. &amp;nbsp;Using &lt;FONT face="courier new,courier"&gt;case&lt;/FONT&gt; function (or use timechart command) will count each 5-minute interval separately in disagreement with the semantics of "last 10 min vol" and "last 15min vol". &amp;nbsp;These terms are cumulative. &amp;nbsp;Any event in "last 5min" must also be counted in "last 10min" and "last 15min".&lt;/P&gt;&lt;P&gt;Here is a semantic implementation;&amp;nbsp;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/MultivalueEvalFunctions#mvappend.28.26lt.3Bvalues.26gt.3B.29" target="_blank" rel="noopener"&gt;mvappend&lt;/A&gt; satisfies both considerations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| foreach 5min 10min 15min
    [eval header = mvappend(header, if(_time - relative_time(now(), "-&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;") &amp;gt; 0, "Last &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; Vol", null()))]
| eval header = mvappend(header, if(log_level == "ERROR", "Timeout Errors", null()),
``` This is error emulation.  Use real condition(s) ```
  if(someother &amp;gt; 0, "Some other count", null()))
| chart count OVER Transaction BY header
| table Transaction "Last 5min Vol" "Last 10min Vol" "Last 15min Vol" "Timeout Errors"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note the last mvappend evaluation is emulation. &amp;nbsp;Use your real condition. &amp;nbsp;Here is a data emulation I use to test the above code; one emulated error condition gives non-zero output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=_internal earliest=-15m
| rename sourcetype AS Transaction
``` data emulation above; some events have leg_level "ERROR" ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This emulation gives the counts like the following:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Transaction&lt;/TD&gt;&lt;TD&gt;Last 5min Vol&lt;/TD&gt;&lt;TD&gt;Last 10min Vol&lt;/TD&gt;&lt;TD&gt;Last 15min Vol&lt;/TD&gt;&lt;TD&gt;Timeout Errors&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;dbx_health_metrics&lt;/TD&gt;&lt;TD&gt;1370&lt;/TD&gt;&lt;TD&gt;2055&lt;/TD&gt;&lt;TD&gt;2740&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;dbx_server&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;splunk_python&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;splunk_search_messages&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;splunkd&lt;/TD&gt;&lt;TD&gt;4736&lt;/TD&gt;&lt;TD&gt;7390&lt;/TD&gt;&lt;TD&gt;9833&lt;/TD&gt;&lt;TD&gt;2779&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;splunkd_access&lt;/TD&gt;&lt;TD&gt;388&lt;/TD&gt;&lt;TD&gt;600&lt;/TD&gt;&lt;TD&gt;787&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;splunkd_ui_access&lt;/TD&gt;&lt;TD&gt;244&lt;/TD&gt;&lt;TD&gt;134&lt;/TD&gt;&lt;TD&gt;148&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sun, 14 Apr 2024 00:13:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684171#M233554</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-04-14T00:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk Query stats with time intervals</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684175#M233556</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/261738"&gt;@Satyapv&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Here's another alternative. We'll use internal splunkd components to simulation a field named Transaction.&lt;/P&gt;&lt;P&gt;To see event counts over [-300,0], [-600,0], and [-900,0] seconds:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;index=_internal sourcetype=splunkd component=* earliest=-15m latest=now
| rename component as Transaction 
| addinfo ``` assumes a valid latest value ```
| stats
    count(eval(_time&amp;gt;=info_max_time-300)) as "Last 5min Vol"
    count(eval(_time&amp;gt;=info_max_time-600)) as "Last 10min Vol"
    count as "Last 15min Vol"
    by Transaction&lt;/LI-CODE&gt;&lt;P&gt;To see event counts over [-300,0], [-600,300), and [-900,600) seconds:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;index=_internal sourcetype=splunkd component=* earliest=-15m latest=now
| rename component as Transaction 
| addinfo ``` assumes a valid latest value ```
| stats
    count(eval(_time&amp;gt;=info_max_time-300)) as "Last 5min Vol"
    count(eval(_time&amp;gt;=info_max_time-600 AND _time&amp;lt;info_max_time-300)) as "Last 10min Vol"
    count(eval(_time&amp;lt;info_max_time-600)) as "Last 15min Vol"
    by Transaction&lt;/LI-CODE&gt;&lt;P&gt;You can adjust earliest and latest as needed, but note that the last count will always be inclusive of earliest, i.e. the last 15 minutes for -15m. You adjust the count aggregates to disallow counting events more than 900 seconds (15 minutes) prior to latest:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;count(eval(_time&amp;gt;=info_max_time-900)) as "Last 15min Vol"&lt;/LI-CODE&gt;&lt;P&gt;or&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;count(eval(_time&amp;gt;=info_max_time-900 AND _time&amp;lt;info_max_time-600)) as "Last 15min Vol"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Apr 2024 00:59:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-Query-stats-with-time-intervals/m-p/684175#M233556</guid>
      <dc:creator>tscroggins</dc:creator>
      <dc:date>2024-04-14T00:59:56Z</dc:date>
    </item>
  </channel>
</rss>

