Splunk Search

How to Add multiple field values for the matching value of another field

Edwin1471
Path Finder

I want to create a query, that  would combine all the duration values into one by adding them for each Time Date. 

Edwin1471_0-1657620145156.png

The result should look something like this : 

Duration      |    TimeDate

03:59:18      |    2022-07-31

.........                 |    2022-06-30

........                  |    2022-05-30 

and so on

 

Labels (3)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try this

| eval finish_time_epoch = strptime(FINISH_TIME, "%Y-%m-%d %H:%M:%S")
| eval start_time_epoch = strptime(START_TIME, "%Y-%m-%d %H:%M:%S")
| eval duration = finish_time_epoch - start_time_epoch
| stats sum(duration) as duration by finish_time_epoch
| sort - finish_time_epoch
| eval TimeDate=strftime(finish_time_epoch, "%Y-%m-%d %H:%M:%S")
| eval duration=tostring(duration,"duration")
| table duration TimeDate

View solution in original post

ITWhisperer
SplunkTrust
SplunkTrust

Were the durations originally in seconds as this would make it easier

| stats sum(duration_in_seconds) as duration_in_seconds by TimeDate
| fieldformat duration_in_seconds=tostring(duration_in_seconds,"duration")
0 Karma

Edwin1471
Path Finder

No 

The initial query 

| eval finish_time_epoch = strptime(FINISH_TIME, "%Y-%m-%d %H:%M:%S")
| eval start_time_epoch = strptime(START_TIME, "%Y-%m-%d %H:%M:%S")
| eval duration = tostring((finish_time_epoch - start_time_epoch), "duration")
| rex field="duration" mode=sed "s/\..*$//"
| sort -FINISH_TIME
| table duration, timeDate

 

 

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try this

| eval finish_time_epoch = strptime(FINISH_TIME, "%Y-%m-%d %H:%M:%S")
| eval start_time_epoch = strptime(START_TIME, "%Y-%m-%d %H:%M:%S")
| eval duration = finish_time_epoch - start_time_epoch
| stats sum(duration) as duration by finish_time_epoch
| sort - finish_time_epoch
| eval TimeDate=strftime(finish_time_epoch, "%Y-%m-%d %H:%M:%S")
| eval duration=tostring(duration,"duration")
| table duration TimeDate
Get Updates on the Splunk Community!

Introducing the Splunk Community Dashboard Challenge!

Welcome to Splunk Community Dashboard Challenge! This is your chance to showcase your skills in creating ...

Get the T-shirt to Prove You Survived Splunk University Bootcamp

As if Splunk University, in Las Vegas, in-person, with three days of bootcamps and labs weren’t enough, now ...

Wondering How to Build Resiliency in the Cloud?

IT leaders are choosing Splunk Cloud as an ideal cloud transformation platform to drive business resilience,  ...