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 timechart span=5m dc(clientip)
but that's not quite the same thing, as I would like a bar per minute that represents the previous 5 minutes.
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:
Just to step through what it does...
I think you'll be much happier using streamstats
with it's window
argument.
index=httpd sourcetype=httpd-access | timechart dc(clientip) as dc span=1m | streamstats avg(dc) as rollingAvg window=5
http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/streamstats
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.
I wonder if this would be more efficient...
index=httpd sourcetype=httpd-access
| timechart span=1m values(clientip) as ips
| streamstats dc(ips) as dc window=5
| fields - ips