All Apps and Add-ons

How to divide the results of two searches to get an average?

Poonsie
Explorer

I have two searches that return respectively the number total sessions and the number of device crashes. How can I divide sessions by device crashes to get an average?

0 Karma
1 Solution

sundareshr
Legend

Try this

platform=Android sourcetype="mint:Ping" | stats count as total_sessions | appendcols [ search platform=Android sourcetype="mint:error" | stats count as total_crashes ] | eval Average=Total_sessions/Total_crashes

View solution in original post

sundareshr
Legend

Try this

platform=Android sourcetype="mint:Ping" | stats count as total_sessions | appendcols [ search platform=Android sourcetype="mint:error" | stats count as total_crashes ] | eval Average=Total_sessions/Total_crashes

cb_usps
Explorer

2 searches, one division... check.
I created an example doing the math: (ignore the fields I chose, replace with your own)

index=os sourcetype=cpu CPU=ALL | stats avg(pctCPUutil) as CPU_pct | appendcols [search index=os sourcetype=who | stats dc(USERNAME) as NUM_user | fields NUM_user] | eval CPU_per_user=CPU_pct/NUM_user | table CPU_pct NUM_user CPU_per_user

Edit: I tried submitting this yesterday, but Splunk's website refused to post it. It submitted today when I was cleaning up.

Poonsie
Explorer

Thanks for the response, I ended up with a table correctly displaying total_sessions, total_crashes, and Average_crashes. Is it possible to dive deeper into this average_crashes number and divide this number up based on device? I tried the chart command but I wasn't sure how to pull in the 'Average' that I calculated.

0 Karma

somesoni2
Revered Legend

Try like this

your search1 giving field Total_Sessions | appendcols [search search2 giving field Total_Crashes ] | eval Average=Total_Sessions/Total_Crashes

Poonsie
Explorer

My query looks like this with your advice:

platform =Android sourcetype = "mint:Ping" giving field total_sessions | appendcols [search platform=Android sourcetype="mint:error" giving field total_crashes] | eval Average=Total_sessions/Total_crashes

However it is telling me that "you can only use appendcols after a reporting command such as stats, chart, or timechart"

Thanks somesoni2!

0 Karma

somesoni2
Revered Legend

My answer was sudo code assuming that you already have full query written to get you total_sessions and total_crashes from those two searches. I believe @sundareshr's answer show do the trick for you.

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

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, ...