Splunk Search

What is the most efficient way to calculate totals for variable fields?

wilcompl1334
Explorer

I have a summary indexed search that runs every 10 minutes, totaling our total unsanctioned email usage. Each unsanctioned email application is calculated and returned with the total MB in/out per application for the given 10 minute time period.

I'm now attempting to build a search that utilizes this summary report's calculated statistics. I'd like to now be able to calculate sums for each applications in/out values. Sample fields that I'd calculate off of are:

  • Total MB In: aim-mail
  • Total MB Out: aim-mail
  • Total MB In: comcast-webmail
  • Total MB Out: comcast-webmail
  • Total MB In: gmail-base
  • Total MB Out: gmail-base

In an easy world I'd just be able to run the following search:

index=myindex_summary report=unsanctioned_email | stats sum(*In: gmail-base), sum(*Out: gmail-base), sum(*In: hotmail)

However, these fields will vary as we gather new unsanctioned email applications. I've looked into utilizing the "foreach" command and looping through that way, but it doesn't seem that this will work given the usage of the "stats" command.

I'm looking for the most efficient way to handle the calculation of totals for these variable fields.

0 Karma
1 Solution

dmarling
Builder

Do your fields that you will be performing this statistical command on have some similarities in naming structure like they all contain ": " somewhere in them? If so you can just do this

index=myindex_summary report=unsanctioned_email
| stats sum("*In: *") as "*In: *", sum("*Out: *") as "*Out: *"
If this comment/answer was helpful, please up vote it. Thank you.

View solution in original post

0 Karma

dmarling
Builder

Do your fields that you will be performing this statistical command on have some similarities in naming structure like they all contain ": " somewhere in them? If so you can just do this

index=myindex_summary report=unsanctioned_email
| stats sum("*In: *") as "*In: *", sum("*Out: *") as "*Out: *"
If this comment/answer was helpful, please up vote it. Thank you.
0 Karma

wilcompl1334
Explorer

Quotes allow for wildcarding in stats sum, of course it's that easy.

Thank you @dmarling, worked perfectly!

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...