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!

Splunk Observability for AI

Don’t miss out on an exciting Tech Talk on Splunk Observability for AI! Discover how Splunk’s agentic AI ...

[Puzzles] Solve, Learn, Repeat: Dereferencing XML to Fixed-length events

This challenge was first posted on Slack #puzzles channelFor a previous puzzle, I needed a set of fixed-length ...

Stay Connected: Your Guide to December Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...