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!

Observability Simplified: Combining User Experience, Application Performance & ...

Tech Talk Observability Simplified: Combining User Experience, Application Performance & Network ...

Event Series May & June: From Network Visibility to Service Intelligence

Unifying the Network: Moving from Alert Noise to Service Intelligence with Splunk ITSI In today’s hybrid ...

Global Splunk User Group Events: May + June 2026

Your Splunk Community Awaits: Discover Upcoming User Group Events Worldwide    Staying ahead in the fast-paced ...