Splunk Search

timechart vs. streamstats

mctester
Communicator

If I do this:

index="foo" sourcetype="bar" | sort _time | streamstats dc(userid) as dcusers | delta dcusers as deltadcusers

This gives me a 0 on the event if the user has been seen before, or 1 if the user is a new user.

But then if I:

| timechart sum(deltadcusers)

It starts out looking right, then progressively collects backwards until there is only one data point at the start containing the same value as stats dc(userid) for the whole time window.

If I leave out the sort _time, then the streamstats command gives values backwards from what I want - it streams backwards in time, I want it streamed forwards from the start of the day.

This doesn't seem right at all, how do I/can I get streamstats and timechart to interact in a sane way in this sort of scenario?

Tags (2)

blilburne
Explorer

Yes, I want to see how many "not seen before on this day" user IDs are coming online on an hourly basis through the day.

Without the sort, it appears to work correctly but the graph is backwards - i.e, the highest count for streamstats is at the start, which means all the deltas/dc values are backwards.

If I sort it, it appears to truncate the results - i.e, I will only see values for a fraction of the time span, and this does not make sense as there are events across the whole timespan, all have userids.

Basically I want streamstats to run forward in time the same way it does for an rtsearch.

blilburne
Explorer

This appears to do what I want:

... | dedup userid sortby +_time | timechart count

This does not:

... | sort +_time | dedup userid | timechart count

Streamstats doesn't have a sortby so it appears not to be possible to do the same with streamstats (change the direction in which they are streamed).

0 Karma

steveyz
Splunk Employee
Splunk Employee

so what does the output of

index="foo" sourcetype="bar" | sort _time | streamstats dc(userid) as dcusers | delta dcusers as deltadcusers | timechart sum(deltadcusers)

look like?

Seems like you want to get a chart of how many new users you are getting for each time span?

Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2026-2027 SplunkTrust is officially open. If ...

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...