<?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: dc rolling over time in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/dc-rolling-over-time/m-p/27794#M5434</link>
    <description>&lt;P&gt;I think you'll be much happier using &lt;CODE&gt;streamstats&lt;/CODE&gt; with it's &lt;CODE&gt;window&lt;/CODE&gt; argument. &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=httpd sourcetype=httpd-access | timechart dc(clientip) as dc span=1m | streamstats avg(dc) as rollingAvg window=5&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/streamstats"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/streamstats&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Apr 2012 06:28:44 GMT</pubDate>
    <dc:creator>sideview</dc:creator>
    <dc:date>2012-04-19T06:28:44Z</dc:date>
    <item>
      <title>dc rolling over time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/dc-rolling-over-time/m-p/27793#M5433</link>
      <description>&lt;P&gt;Looking at the results from a popular web analytic site, their definition of "current visitors" seems to be "distinct count over rolling five minutes". I'd like to replicate that in Splunk, but I couldn't find an elegant way to keep a rolling dc for five minute blocks without starting over. You could simply say &lt;CODE&gt;timechart span=5m dc(clientip)&lt;/CODE&gt; but that's not quite the same thing, as I would like a bar per minute that represents the previous 5 minutes.&lt;/P&gt;

&lt;P&gt;I've come up with a query that works, but I'm hoping someone more clever than I can shorten this query a bit. Maybe there's a timechart function I'm missing, or a range function of some sort that would shorten the eval, or a weird use of streamstats:&lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;index=httpd sourcetype=httpd-access &lt;/LI&gt;
&lt;LI&gt;  | bucket span=1m _time &lt;/LI&gt;
&lt;LI&gt;  | eval t=split( _time + "," + tostring(_time+60) + "," + tostring(_time+120) + "," + tostring(_time+180) + "," + tostring(_time+240) , "," ) &lt;/LI&gt;
&lt;LI&gt;  | stats dc(clientip) as dc by t &lt;/LI&gt;
&lt;LI&gt;  | where t&amp;lt;now() &lt;/LI&gt;
&lt;LI&gt;  | eval _time=t &lt;/LI&gt;
&lt;LI&gt;  | timechart span=1m max(dc) as dc&lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;Just to step through what it does... &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;Find the events.&lt;/LI&gt;
&lt;LI&gt;Floor _time of each event to the minute. &lt;/LI&gt;
&lt;LI&gt;Make a multivalued field t with _time and the next four minutes. &lt;/LI&gt;
&lt;LI&gt;Calculate the dc per minute. Since t is multivalued, each event will count towards its minute and the four minutes after it. &lt;/LI&gt;
&lt;LI&gt;Throw away the future minutes created on events in the last minute. &lt;/LI&gt;
&lt;LI&gt;Reset _time to t for the timechart. &lt;/LI&gt;
&lt;LI&gt;Chart it.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Mon, 16 Apr 2012 20:11:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/dc-rolling-over-time/m-p/27793#M5433</guid>
      <dc:creator>vbumgarn</dc:creator>
      <dc:date>2012-04-16T20:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: dc rolling over time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/dc-rolling-over-time/m-p/27794#M5434</link>
      <description>&lt;P&gt;I think you'll be much happier using &lt;CODE&gt;streamstats&lt;/CODE&gt; with it's &lt;CODE&gt;window&lt;/CODE&gt; argument. &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;index=httpd sourcetype=httpd-access | timechart dc(clientip) as dc span=1m | streamstats avg(dc) as rollingAvg window=5&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/streamstats"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/streamstats&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Apr 2012 06:28:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/dc-rolling-over-time/m-p/27794#M5434</guid>
      <dc:creator>sideview</dc:creator>
      <dc:date>2012-04-19T06:28:44Z</dc:date>
    </item>
    <item>
      <title>Re: dc rolling over time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/dc-rolling-over-time/m-p/27795#M5435</link>
      <description>&lt;P&gt;I don't think that will give the same answer. After the timechart, you have a dc per minute, but you've lost what the dc for groupings of five minutes would have been.&lt;/P&gt;

&lt;P&gt;I wonder if this would be more efficient...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=httpd sourcetype=httpd-access
| timechart span=1m values(clientip) as ips 
| streamstats dc(ips) as dc window=5
| fields - ips
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 20 Apr 2012 02:25:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/dc-rolling-over-time/m-p/27795#M5435</guid>
      <dc:creator>vbumgarn</dc:creator>
      <dc:date>2012-04-20T02:25:09Z</dc:date>
    </item>
  </channel>
</rss>

