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!

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

🍂 Fall into November with a fresh lineup of Community Office Hours, Tech Talks, and Webinars we’ve ...

Transform your security operations with Splunk Enterprise Security

Hi Splunk Community, Splunk Platform has set a great foundation for your security operations. With the ...

Splunk Admins and App Developers | Earn a $35 gift card!

Splunk, in collaboration with ESG (Enterprise Strategy Group) by TechTarget, is excited to announce a ...