<?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 use span with stats? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-span-with-stats/m-p/259369#M77760</link>
    <description>&lt;P&gt;What about something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=duty time_taken!=-* 
| rex field=time_taken "(?&amp;lt;H&amp;gt;\d{1,2}):(?&amp;lt;M&amp;gt;\d{2}):(?&amp;lt;S&amp;gt;\d{2})\.(?&amp;lt;uS&amp;gt;\d{6})" 
| eval transaction_time = tonumber(H)*3600 + tonumber(M)*60 + tonumber(S) + tonumber("0.".uS)
| bucket StartTime span=1d
| stats sum(transaction_time) as total_transaction_time by DutyId, StartTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=duty time_taken!=-* 
| rex field=time_taken "(?&amp;lt;H&amp;gt;\d{1,2}):(?&amp;lt;M&amp;gt;\d{2}):(?&amp;lt;S&amp;gt;\d{2})\.(?&amp;lt;uS&amp;gt;\d{6})" 
| eval transaction_time = tonumber(H)*3600 + tonumber(M)*60 + tonumber(S) + tonumber("0.".uS)
| eval StartTime = strptime(StartTime, "%Y-%m-%d %H:%M:%S.%6N")
| bucket StartTime span=1d
| eval StartTime = strftime(StartTime, "%Y-%m-%d %H:%M:%S.%6N")
| chart sum(total_transaction_time) as total_transaction_time over StartTime by DutyId
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 01 Feb 2016 11:12:22 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2016-02-01T11:12:22Z</dc:date>
    <item>
      <title>How to use span with stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-span-with-stats/m-p/259367#M77758</link>
      <description>&lt;P&gt;My query below does the following:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Ignores time_taken values which are negative&lt;/LI&gt;
&lt;LI&gt;For each event, extracts the hour, minute, seconds, microseconds from the time_taken (which is now a string) and sets this to a "transaction_time" field&lt;/LI&gt;
&lt;LI&gt;Sums the transaction_time of related events (grouped by "DutyID" and the "StartTime" of each event) and names this as total transaction time&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;I now have a list of StartTimes along the left, and durations along the right. I have thousands of events and the granularity of the time is very small (e.g. there are just seconds or milliseconds between each event).&lt;/P&gt;

&lt;P&gt;So it looks something like this (in table form):&lt;/P&gt;

&lt;P&gt;StartTime - total_transaction_time&lt;BR /&gt;
2016-01-25 10:00:00.598000 - 0.124000&lt;BR /&gt;
2016-01-25 10:00:04.342000 - 0.780000&lt;BR /&gt;
2016-01-25 10:00:05.153000 - 0.078000&lt;BR /&gt;
2016-01-25 10:00:07.275000 - 0.546000&lt;BR /&gt;
...&lt;BR /&gt;
...&lt;/P&gt;

&lt;P&gt;I now want to group these into averages over an hour, so it will look something like:&lt;/P&gt;

&lt;P&gt;2016-01-25 10:00 - 0.839100&lt;BR /&gt;
2016-01-26 11:00 - 0.590000&lt;BR /&gt;
...&lt;BR /&gt;
...&lt;/P&gt;

&lt;P&gt;Unfortunately I cannot use a "span" argument to the stats command like with a timechart. I've tried using bins/buckets but I can't find many good examples of this.&lt;/P&gt;

&lt;P&gt;If I could do this in a way which uses a timechart or another function which takes a "span" argument that would be perfect, as I want to add it to a dashboard which is using "span" on a number of other charts, so I can then control them all off the same control which currently changes the span variable in each search string.&lt;/P&gt;

&lt;P&gt;The query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=duty time_taken!=-* | rex field=time_taken "(?&amp;lt;H&amp;gt;\d{1,2}):(?&amp;lt;M&amp;gt;\d{2}):(?&amp;lt;S&amp;gt;\d{2})\.(?&amp;lt;uS&amp;gt;\d{6})" 
   | eval transaction_time = tonumber(H)*3600 + tonumber(M)*60 + tonumber(S) + tonumber("0.".uS)
   | stats sum(transaction_time) as total_transaction_time by DutyId, StartTime
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:37:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-span-with-stats/m-p/259367#M77758</guid>
      <dc:creator>jpanderson</dc:creator>
      <dc:date>2020-09-29T08:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to use span with stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-span-with-stats/m-p/259368#M77759</link>
      <description>&lt;P&gt;You could use this (if StartTime is in epochtime, otherwise you need to convert it into epochtime)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  | rename StartTime As _time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And then use the timechart command&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | timechart span=1d sum(transaction_time) as total_transaction_time by DutyId
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Feb 2016 11:08:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-span-with-stats/m-p/259368#M77759</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2016-02-01T11:08:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to use span with stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-span-with-stats/m-p/259369#M77760</link>
      <description>&lt;P&gt;What about something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=duty time_taken!=-* 
| rex field=time_taken "(?&amp;lt;H&amp;gt;\d{1,2}):(?&amp;lt;M&amp;gt;\d{2}):(?&amp;lt;S&amp;gt;\d{2})\.(?&amp;lt;uS&amp;gt;\d{6})" 
| eval transaction_time = tonumber(H)*3600 + tonumber(M)*60 + tonumber(S) + tonumber("0.".uS)
| bucket StartTime span=1d
| stats sum(transaction_time) as total_transaction_time by DutyId, StartTime
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Or this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=duty time_taken!=-* 
| rex field=time_taken "(?&amp;lt;H&amp;gt;\d{1,2}):(?&amp;lt;M&amp;gt;\d{2}):(?&amp;lt;S&amp;gt;\d{2})\.(?&amp;lt;uS&amp;gt;\d{6})" 
| eval transaction_time = tonumber(H)*3600 + tonumber(M)*60 + tonumber(S) + tonumber("0.".uS)
| eval StartTime = strptime(StartTime, "%Y-%m-%d %H:%M:%S.%6N")
| bucket StartTime span=1d
| eval StartTime = strftime(StartTime, "%Y-%m-%d %H:%M:%S.%6N")
| chart sum(total_transaction_time) as total_transaction_time over StartTime by DutyId
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Feb 2016 11:12:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-span-with-stats/m-p/259369#M77760</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-02-01T11:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to use span with stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-span-with-stats/m-p/259370#M77761</link>
      <description>&lt;P&gt;Nevermind, sorted it now...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=duty time_taken!=-* | rex field=time_taken "(?\d{1,2}):(?\d{2}):(?\d{2})\.(?\d{6})" |  bin  _time  AS "TIME" span=1h | convert ctime(TIME)   | eval transaction_time = tonumber(H)*3600 + tonumber(M)*60 + tonumber(S) + tonumber("0.".uS)  | stats avg(transaction_time) as total_transaction_time_h  by  TIME
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I think perhaps StartTime wasn't an actual time value so I was having trouble sorting it. I've put the bucket at the start instead, and used the _time values of the events (which we configured to be the same as the StartTime anyway).&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2016 11:16:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-span-with-stats/m-p/259370#M77761</guid>
      <dc:creator>jpanderson</dc:creator>
      <dc:date>2016-02-01T11:16:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to use span with stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-span-with-stats/m-p/259371#M77762</link>
      <description>&lt;P&gt;Sorry I just solved it. Thanks for your answer though. &lt;BR /&gt;
I think perhaps StartTime wasn't an actual time value so I was having trouble sorting it, I've put the bucket at the start instead, and used the _time values of the events (which we configured to be the same as the StartTime anyway).&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2016 11:17:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-span-with-stats/m-p/259371#M77762</guid>
      <dc:creator>jpanderson</dc:creator>
      <dc:date>2016-02-01T11:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to use span with stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-span-with-stats/m-p/259372#M77763</link>
      <description>&lt;P&gt;Sorry I just solved it. Thanks for your answer though. &lt;BR /&gt;
I think perhaps StartTime wasn't an actual time value so I was having trouble sorting it, I've put the bucket at the start instead, and used the _time values of the events (which we configured to be the same as the StartTime anyway).&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2016 11:17:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-span-with-stats/m-p/259372#M77763</guid>
      <dc:creator>jpanderson</dc:creator>
      <dc:date>2016-02-01T11:17:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to use span with stats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-use-span-with-stats/m-p/612014#M212798</link>
      <description>&lt;P&gt;Please, send the solution, please&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 02:55:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-use-span-with-stats/m-p/612014#M212798</guid>
      <dc:creator>m0rt1f4g0</dc:creator>
      <dc:date>2022-09-06T02:55:03Z</dc:date>
    </item>
  </channel>
</rss>

