Splunk Search

Distinct counts on only those fields that begin with a particular string

deton0
Explorer

Hi

I'm searching on an internet usage index for events that contain a particular word somewhere in the domain. For example the word could be "edublogs".

From the result, I need to sum the total of bytes downloaded for all events returned. The problem I'm having is needing to calculate a distinct count of centers and a distinct count of userids where the domain name only begins with "edublogs", e.g. "edublogs.com" and not when it doesn't, e.g.  "accountsedublogs.com".

I know this example is wrong but can someone please help me with how I would change it to achieve the outcome below?

index=searchdata domain="*edublogs*"
| stats count dc(centre) AS distinctCenters
| stats count dc(userid) AS distinctUserids
| stats sum(bytes) AS totalBytes by domain
| table domain totalBytes, distinctCenters, distinctUserids

My desired results would look something like...
domain totalBytes distinctCenters distinctUserids
Senior 50000 15 321

Many thanks

Labels (2)
Tags (1)
0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@deton0 

Can you please try this?

index=searchdata domain="*edublogs*"
| stats count dc(centre) AS distinctCenters, dc(userid) AS distinctUserids, sum(bytes) AS totalBytes by domain
| table domain totalBytes, distinctCenters, distinctUserids

 

KV 

View solution in original post

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@deton0 

Can you please try this?

index=searchdata domain="*edublogs*"
| stats count dc(centre) AS distinctCenters, dc(userid) AS distinctUserids, sum(bytes) AS totalBytes by domain
| table domain totalBytes, distinctCenters, distinctUserids

 

KV 

0 Karma

deton0
Explorer

Hi KV

Thanks for this. It's wasn't quite what I needed but got me on the right path to working it out. This is how I changed it and it appears to be working how I need with my original data. 

index=searchdata domain="*edublogs*"
| eval distinctCenters=Case(Like(domain,"edublogs%"), centre)
| eval distinctUserids=Case(Like(domain,"edublogs%"), userid)
| eventstats dc(distinctCenters) as distinctCenters, dc(distinctUserids) as distinctUserids by domain
| stats count, sum(bytes) AS totalBytes by domain, distinctCenters, distinctUserids
| table domain totalBytes, distinctCenters, distinctUserids

deton0

0 Karma
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!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...