<?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 do I compute the range between 2 values of _time with streamstats? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-compute-the-range-between-2-values-of-time-with/m-p/421206#M121003</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;As you can see above, I did a "rename" command. Moreover, some host/sourcetype couple are well computed. But not all..&lt;/P&gt;</description>
    <pubDate>Fri, 19 Oct 2018 12:38:03 GMT</pubDate>
    <dc:creator>davietch</dc:creator>
    <dc:date>2018-10-19T12:38:03Z</dc:date>
    <item>
      <title>How do I compute the range between 2 values of _time with streamstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-compute-the-range-between-2-values-of-time-with/m-p/421203#M121000</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am trying to compute statistics about the Splunk data. To do so, I've got a datamodel with the number of events per host/sourcetype for each hour.&lt;/P&gt;

&lt;P&gt;So I can query it this way:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats  count from datamodel="Splunk_Stats" where nodename="Host.Host_Per_Hour" Host.orig_host="*" Host.orig_sourcetype="*" AND earliest=-31d latest=@h by Host.orig_host,Host.orig_sourcetype,_time span=1h
| rename Host.orig_host AS orig_host, Host.orig_sourcetype AS orig_sourcetype
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This works but then, I want to compute the range (difference between 2 successive values) of _time for each host/sourcetype.&lt;BR /&gt;
So I add:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | streamstats global=false window=2 range(_time) AS r_time by orig_host, orig_sourcetype  
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I do global=false and window=2, because, from my understanding, it will make Splunk compute the range for every two successive values for each individual host/sourcetype couple.&lt;/P&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype      _time
A                today
B                today
A                2 days ago
A                3 days ago
A                4 days ago
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So the streamstats commands adds:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype      _time            r_time
A                today           0
B                today           0
A                2 days ago      2
A                3 days ago      1
A                4 days ago      1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now, when I do this, it works if I filter down to a specific source type in my &lt;CODE&gt;tstats&lt;/CODE&gt; command. But when there are several (a lot of) source types all mixed together (because I don't filter), the &lt;CODE&gt;streamstats&lt;/CODE&gt; command does not compute the range and there is no r_time column...&lt;/P&gt;

&lt;P&gt;Any idea how to make it work?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Oct 2018 15:31:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-compute-the-range-between-2-values-of-time-with/m-p/421203#M121000</guid>
      <dc:creator>davietch</dc:creator>
      <dc:date>2018-10-09T15:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: How do I compute the range between 2 values of _time with streamstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-compute-the-range-between-2-values-of-time-with/m-p/421204#M121001</link>
      <description>&lt;P&gt;Anyone please ?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Oct 2018 08:22:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-compute-the-range-between-2-values-of-time-with/m-p/421204#M121001</guid>
      <dc:creator>davietch</dc:creator>
      <dc:date>2018-10-19T08:22:57Z</dc:date>
    </item>
    <item>
      <title>Re: How do I compute the range between 2 values of _time with streamstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-compute-the-range-between-2-values-of-time-with/m-p/421205#M121002</link>
      <description>&lt;P&gt;@davietch,&lt;BR /&gt;
It seems fieldnames are not getting recognized. can you try below-&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... | streamstats global=false window=2 range(_time) AS r_time by Host.orig_host, Host.orig_sourcetype  
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Oct 2018 10:39:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-compute-the-range-between-2-values-of-time-with/m-p/421205#M121002</guid>
      <dc:creator>493669</dc:creator>
      <dc:date>2018-10-19T10:39:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I compute the range between 2 values of _time with streamstats?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-do-I-compute-the-range-between-2-values-of-time-with/m-p/421206#M121003</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;As you can see above, I did a "rename" command. Moreover, some host/sourcetype couple are well computed. But not all..&lt;/P&gt;</description>
      <pubDate>Fri, 19 Oct 2018 12:38:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-do-I-compute-the-range-between-2-values-of-time-with/m-p/421206#M121003</guid>
      <dc:creator>davietch</dc:creator>
      <dc:date>2018-10-19T12:38:03Z</dc:date>
    </item>
  </channel>
</rss>

