Splunk Search

How to extract fields with a value greater than 3 seconds?

sp_lunky
New Member

First sorry for my english. I'm testing Splunk at the moment, and i have a task to extract a field from *.log files.

Raw value is :

..xxxxxxxxxxxxxxx Duration: 1 s. 466 ms....
..xxxxxxxxxxxxxxx Duration: 4 s. 066 ms...
..xxxxxxxxxxxxxxx Duration: 12 s. 300 ms...

I want to to make an alert when the Duration is greater than 3 s

for a Report I filtered with search command, but it won't show the value like: "11", "12"

host=NAME | search (duration:"4" OR "5" OR "6" OR "7" OR "8" OR "9" ) 

Any help please!?

0 Karma
1 Solution

paulstout
Path Finder

Could you try this search?

host=name | rex field=_raw "Duration\:\s(?<duration_s>\d+)\ss\.\s+(?<duration_ms>\d+)\sms" | eval duration=duration_s+(duration_ms/1000) | search duration_s="*"?

This would give you a float with the actual duration in duration and separate fields for the second and millisecond component to use your original filtering.

View solution in original post

sp_lunky
New Member

Thank you very much! Both are good and working. But I accepted paulstout answer because it satisfy both my needs.
Thank you again!

0 Karma

DalJeanis
Legend

I believe you can accept more than one answer, if they both helped.

0 Karma

sp_lunky
New Member

Sorry, i didn't now that

0 Karma

paulstout
Path Finder

Could you try this search?

host=name | rex field=_raw "Duration\:\s(?<duration_s>\d+)\ss\.\s+(?<duration_ms>\d+)\sms" | eval duration=duration_s+(duration_ms/1000) | search duration_s="*"?

This would give you a float with the actual duration in duration and separate fields for the second and millisecond component to use your original filtering.

paulstout
Path Finder

To meet the original 3 second requirement, | where duration_s>3 or | search duration_s>3 should suffice.

0 Karma

vasanthmss
Motivator

try this,

your base search | rex "Duration:\s+(?<duration>\d+)" | where duration>3

Hope this will help you.

V

somesoni2
Revered Legend

The threshold sp_lunky looking for is 3 sec. You may want to correct it.

0 Karma

vasanthmss
Motivator

updated the answer.

V
0 Karma
Get Updates on the Splunk Community!

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...