Splunk Search

How to calculate the difference between 2 different events with the same field and group them by another field that they have in common?

kar1na
New Member

So lets say I have 4 events,
name="karina" age="23"
name="Karina" age = "67"
name="George" age="45"
name="George" age ="12"

I want to be able to get the difference and group these events by the name field (or whatever field that they have in common) to be able to get something like,
name="Karina" calc_age="44"
name="George" calc_age = "33"

I tried using delta, but I always get negative numbers and I don't know how to incorporate the group by in there.

0 Karma

sundareshr
Legend

You will need eventstats OR streamstats. Try this

 |  eventstats max(age) as max min(age) as min by name | eval diff=max-min | dedup name | table name max min diff
0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...