Splunk Search

How to write a search to combine the sum of three metric name into one count?

soulmaker
Explorer

Hello, 

I have three search query below that I want to combine the three metric name sum into one total count. Can someone able to assist how I can write my query?

First Query:
| mstats sum(vault.token.creation.nonprod) as count where index=vault_metrics span=1h
| timechart sum(count) as count span=1h
| fillnull value=0
| eventstats perc90(count) perc50(count)

Second Query:
| mstats sum(vault.token.creation.dev) as count where index=vault_metrics span=1h
| timechart sum(count) as count span=1h
| fillnull value=0
| eventstats perc90(count) perc50(count)

Third Query:
| mstats sum(vault.token.creation.nonprod_preprod) as count where index=vault_metrics span=1h
| timechart sum(count) as count span=1h
| fillnull value=0
| eventstats perc90(count) perc50(count)

Labels (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

You are collecting from the same index, so just put all 3 counts in the same mstats

| mstats sum(vault.token.creation.nonprod) as count_nonprod
         sum(vault.token.creation.dev) as count_dev
         sum(vault.token.creation.nonprod_preprod) as count_nonprod_preprod
  where index=vault_metrics span=1h
| addtotals
| timechart sum(Total) as Total span=1h
| fillnull value=0
| eventstats perc90(Total) as p90_Total perc50(Total) as p50_Total

The addtotals gives you a sume of all the count_* fields into a single new field Total, so then just use that new field total to calculate the percentiles

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

You are collecting from the same index, so just put all 3 counts in the same mstats

| mstats sum(vault.token.creation.nonprod) as count_nonprod
         sum(vault.token.creation.dev) as count_dev
         sum(vault.token.creation.nonprod_preprod) as count_nonprod_preprod
  where index=vault_metrics span=1h
| addtotals
| timechart sum(Total) as Total span=1h
| fillnull value=0
| eventstats perc90(Total) as p90_Total perc50(Total) as p50_Total

The addtotals gives you a sume of all the count_* fields into a single new field Total, so then just use that new field total to calculate the percentiles

soulmaker
Explorer

Thanks @bowesmana , you're a legend!

0 Karma
Get Updates on the Splunk Community!

Building Reliable Asset and Identity Frameworks in Splunk ES

 Accurate asset and identity resolution is the backbone of security operations. Without it, alerts are ...

Cloud Monitoring Console - Unlocking Greater Visibility in SVC Usage Reporting

For Splunk Cloud customers, understanding and optimizing Splunk Virtual Compute (SVC) usage and resource ...

Automatic Discovery Part 3: Practical Use Cases

If you’ve enabled Automatic Discovery in your install of the Splunk Distribution of the OpenTelemetry ...