Splunk Search

Use a count from one index to help the calculation in another

mtmoore
Explorer

I have been racking my brains over this for most of the day so i'm hoping someone will put me out of my misery!

I want to calculate the average amount of messages per user per day. The number of users is contained in one index, the amount of messages per day in another.

How can I use the count of users to divide into the number of messages per day to get average per user?

This is what I have so far

One solution (doesn't work)

index="msexchange" eventtype=storedriver-mail | bucket _time span=1d | stats dc(message_id) as test by _time | append[search index="msexchange" sourcetype="msexchange:2010:mailbox-usage"  | dedup UserPrincipalName | eventstats count as test2] |eval test3 = test/test2

Another solution (as soon as you put by _time in there after stats dc(message_id) it complains):

index="msexchange" sourcetype="msexchange:2010:mailbox-usage"  | dedup UserPrincipalName | eventstats count as Total | eval cur=[search index="msexchange" eventtype=storedriver-mail | bucket _time span=1d | stats dc(message_id) as cur| rename cur as query] |eval finalanswer = cur / Total |table finalanswer

Help! 🙂

Tags (2)
0 Karma

somesoni2
Revered Legend

And your index/sourcetype containing messages don't have reference to user (UserPrincipalName)? (in the same event)

0 Karma

kristian_kolb
Ultra Champion

Would something like this work?

index=msexchange eventtype=storedriver-mail OR sourcetype=msexchange:2010:mailbox-usage
| timechart span=1d dc(UserPrincipalName) as users dc(message_id) as msgs 
| eval ratio = msgs/users

/K

mtmoore
Explorer

Awesome Kristian, did the job perfectly, thankyou!

0 Karma
Get Updates on the Splunk Community!

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...