Splunk Search

Calculate delta for corresponding fields base on time grouped events

noveix
Explorer

Need ideas on how to do field calculations based on 2 sets of transactions. Data file is as follows :

Timestamp_1 field_1 field_2 field_3 field_4 id_1

Timestamp_1 field_1 field_2 field_3 field_4 id_2

Timestamp_1 field_1 field_2 field_3 field_4 id_3

Timestamp_1 field_1 field_2 field_3 field_4 id_4

Timestamp_2 field_1 field_2 field_3 field_4 id_1

Timestamp_2 field_1 field_2 field_3 field_4 id_2

Timestamp_2 field_1 field_2 field_3 field_4 id_3

Timestamp_2 field_1 field_2 field_3 field_4 id_4

Timestamp_3 field_1 field_2 field_3 field_4 id_1

Timestamp_3 field_1 field_2 field_3 field_4 id_2

Timestamp_3 field_1 field_2 field_3 field_4 id_3

Timestamp_3 field_1 field_2 field_3 field_4 id_4

Multiple events have same timestamp (Timestamp_1, Timestamp_2...) at regular intervals. Field_1 .. to Field_4 are cumulative from previous identical timestamped fields.

First part:

Need to calculate DELTA by comparing previous event for the same id_1, id_2 ..etc
Eg. need to calculate Delta as follows :

Timestamp2 Field_1 - Timestamp_1 field_1

Timestamp3 Field_1 - Timestamp_2 field_1

Second part:

Add the DELTAs for field_1, field_2... per time interval, so

Timestamp_2 field-delta_1 field-delta_2 field-delta_3 field_4 id_1

Timestamp_2 field-delta_1 field-delta_2 field-delta_3 field_4 id_2

Timestamp_2 field-delta_1 field-delta_2 field-delta_3 field_4 id_3

Timestamp_2 field-delta_1 field-delta_2 field-delta_3 field_4 id_4

Sum of field-delta_1 for all id_?s

Appreciate any help/pointers with this !!

Tags (1)
0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

For calculating deltas split by a field you can use streamstats:

... | streamstats current=f window=1 last(field) as last_field by split_field | eval delta_field = field - last_field

Not sure what you mean by the second part, could you elaborate?

View solution in original post

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

For calculating deltas split by a field you can use streamstats:

... | streamstats current=f window=1 last(field) as last_field by split_field | eval delta_field = field - last_field

Not sure what you mean by the second part, could you elaborate?

0 Karma

noveix
Explorer

great work ... works nicely !!

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Ah. Append this:

... | eventstats sum(delta_field_1) by _time
0 Karma

noveix
Explorer

I want to sum up delta of field_1 for all events that have the same timestamp regardless of the id_#

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Do you want to sum up several fields in one event or sum up one field over several events - or both?

0 Karma

noveix
Explorer

Thanks Martin, that works, for the second part .. I need to sum the deltas for all of the id_# for the same timestamp .. using my example data above, deltas for the 4 events which has identical timestamp.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...