Splunk Search

How to extract time from the below message?

peterfox1992
Explorer

Hi Folks,

Can someone help me on the below. I have the below message in the log and need to extract the time portion alone.

[END~~Method.Search_Button] Response Time Search_Button: 00:00:00.3004626

The output I need is,

00:00:00.3004626

Also if possible, can suggest how I can get the value as millisecond? For the above message, I should get 300ms.

If the output is "00:00:01.250" then i should get as 1250ms.

Thanks.

Labels (1)
0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @peterfox1992,

after the rex command you have to use the eval command for the convertion:

| rex "Search_Button:\s+(?<hours>\d\d):/?<minutes>\d\d):(?<seconds>\d\d\)\.(?<milliseconds>\d\d\d\d\d\d)"
| eval time_milliseconds=(hours*3600+minutes*60+seconds)*1000+milliseconds

Ciao.

Giuseppe

View solution in original post

peterfox1992
Explorer

Thanks @gcusello . I have got the required result by using the rex command mentioned.

Now is there any possible to convert the time in millisecond?

If the output is "00:00:01.250" then i should get as 1250ms.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @peterfox1992,

after the rex command you have to use the eval command for the convertion:

| rex "Search_Button:\s+(?<hours>\d\d):/?<minutes>\d\d):(?<seconds>\d\d\)\.(?<milliseconds>\d\d\d\d\d\d)"
| eval time_milliseconds=(hours*3600+minutes*60+seconds)*1000+milliseconds

Ciao.

Giuseppe

peterfox1992
Explorer

Thanks @gcusello . It worked 🙂 

Cheers!

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @peterfox1992,

are you speaking of extract time as a field or as the event TimeStamp?

if as a field, you can use a regex like the following:

| rex "Search_Button:\s+(?<time>\d\d:\d\d:\d\d\.\d\d\d\d\d\d"

if as timestamp, in sourcetype (props.conf) you have to define the following parameters:

[your_sourcetype]
TIME_PREFIX = Search_Button:\s
TIME_FORMAT = %H:%M:%S.%6N

Ciao.

Giuseppe

0 Karma

peterfox1992
Explorer

Thanks @gcusello . I have got the required result by using the rex command mentioned.

Now is there any possible to convert the time in millisecond?

If the output is "00:00:01.250" then i should get as 1250ms.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...