<?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 compute _indextime-_time difference average with tstats? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-compute-indextime-time-difference-average-with-tstats/m-p/306880#M92061</link>
    <description>&lt;P&gt;The tstats command doesn't support _time aggregations except for min/max. Give this version a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count WHERE index=* OR index=_* by _time _indextime index| eval latency=abs(_indextime-_time) | stats sum(latency) as sum sum(count) as count by index| eval avg=sum/count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Update&lt;/STRONG&gt;&lt;BR /&gt;
Thanks @rjthibod for pointing the auto rounding of _time. If you've want to measure latency to rounding to 1 sec, use above version. If you want more precide, to the millisecond, use this version.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count WHERE index=* OR index=_* by _time _indextime index span=1ms | eval latency=abs(_indextime-_time) | stats sum(latency) as sum sum(count) as count by index| eval avg=sum/count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can specify Time scale in &lt;CODE&gt;microseconds (us), milliseconds (ms), centiseconds (cs), or deciseconds (ds)&lt;/CODE&gt; for more precision.&lt;/P&gt;</description>
    <pubDate>Mon, 22 May 2017 17:16:39 GMT</pubDate>
    <dc:creator>somesoni2</dc:creator>
    <dc:date>2017-05-22T17:16:39Z</dc:date>
    <item>
      <title>How to compute _indextime-_time difference average with tstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compute-indextime-time-difference-average-with-tstats/m-p/306878#M92059</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I'd like to calculate the average latency (_indextime-_time) with the tstats command, but I can not make it work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats avg(_indextime-_time) where (index=* OR index=_*) by index
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Splunk thinks "_indextime-_time" is a field name. How can I compute the difference in the tstats?&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:10:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compute-indextime-time-difference-average-with-tstats/m-p/306878#M92059</guid>
      <dc:creator>ctaf</dc:creator>
      <dc:date>2020-09-29T14:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute _indextime-_time difference average with tstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compute-indextime-time-difference-average-with-tstats/m-p/306879#M92060</link>
      <description>&lt;P&gt;You cannot do that kind of eval in &lt;CODE&gt;tstats&lt;/CODE&gt; and &lt;CODE&gt;tstats&lt;/CODE&gt; cannot be used to get the individual events out like you would need to.&lt;/P&gt;

&lt;P&gt;Instead, you have to do this without &lt;CODE&gt;tstats&lt;/CODE&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(index=* OR index=_*) 
| fields _time index _indextime 
| fields - _raw
| stats avg(eval(_indextime - _time)) as avg by index
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 May 2017 15:46:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compute-indextime-time-difference-average-with-tstats/m-p/306879#M92060</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2017-05-22T15:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute _indextime-_time difference average with tstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compute-indextime-time-difference-average-with-tstats/m-p/306880#M92061</link>
      <description>&lt;P&gt;The tstats command doesn't support _time aggregations except for min/max. Give this version a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count WHERE index=* OR index=_* by _time _indextime index| eval latency=abs(_indextime-_time) | stats sum(latency) as sum sum(count) as count by index| eval avg=sum/count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Update&lt;/STRONG&gt;&lt;BR /&gt;
Thanks @rjthibod for pointing the auto rounding of _time. If you've want to measure latency to rounding to 1 sec, use above version. If you want more precide, to the millisecond, use this version.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats count WHERE index=* OR index=_* by _time _indextime index span=1ms | eval latency=abs(_indextime-_time) | stats sum(latency) as sum sum(count) as count by index| eval avg=sum/count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can specify Time scale in &lt;CODE&gt;microseconds (us), milliseconds (ms), centiseconds (cs), or deciseconds (ds)&lt;/CODE&gt; for more precision.&lt;/P&gt;</description>
      <pubDate>Mon, 22 May 2017 17:16:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compute-indextime-time-difference-average-with-tstats/m-p/306880#M92061</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-05-22T17:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute _indextime-_time difference average with tstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compute-indextime-time-difference-average-with-tstats/m-p/306881#M92062</link>
      <description>&lt;P&gt;I think this approach will always round &lt;CODE&gt;_time&lt;/CODE&gt; to the closet second, hence throwing off the answers. Double-check by running this &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| tstats count WHERE index=* OR index=_* by _time _indextime index | rename _time as time&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 22 May 2017 17:45:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compute-indextime-time-difference-average-with-tstats/m-p/306881#M92062</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2017-05-22T17:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute _indextime-_time difference average with tstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compute-indextime-time-difference-average-with-tstats/m-p/306882#M92063</link>
      <description>&lt;P&gt;@ctaf, you might want to reconsider. As my other comment says, this approach rounds off the &lt;CODE&gt;_time&lt;/CODE&gt; field to the nearest second.&lt;/P&gt;

&lt;P&gt;Here is a quick test: run the command @somesoni2 gave and then run mine . If you get two difference answers for the average, then there is a problem. The &lt;CODE&gt;tstats&lt;/CODE&gt; approach would be faster and better if it didn't round off &lt;CODE&gt;_time&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2017 11:52:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compute-indextime-time-difference-average-with-tstats/m-p/306882#M92063</guid>
      <dc:creator>rjthibod</dc:creator>
      <dc:date>2017-05-24T11:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to compute _indextime-_time difference average with tstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-compute-indextime-time-difference-average-with-tstats/m-p/306883#M92064</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;| tstats earliest(_time) as etime where index=* by index _indextime
| eval delta=(etime-_indextime)/60 
| eval _time=_indextime  
| timechart span=10m min(delta) by index limit=0
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Nov 2018 11:15:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-compute-indextime-time-difference-average-with-tstats/m-p/306883#M92064</guid>
      <dc:creator>nunoaragao</dc:creator>
      <dc:date>2018-11-08T11:15:58Z</dc:date>
    </item>
  </channel>
</rss>

