Splunk Search

How do I extract a number from the raw message

JeffCr
Explorer

How do I extract the following which always occurs as the last part of the raw text in message e.g "Took 13983.1468ms."
I want only the number and to capture timestamp and hostname. The total message length and structure might vary slightly but the ending is the same.

Tags (1)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

I'd use rex.

index=foo | rex "Took (?<num>\d+\.?\d+)ms" | ...

If you need help extracting timestamp and hostname, please show some sample data.

---
If this reply helps you, Karma would be appreciated.

View solution in original post

twinspop
Influencer
| rex "Took (?P<dur>\d+\.?\d*)ms"

Will put the value into dur

0 Karma

richgalloway
SplunkTrust
SplunkTrust

I'd use rex.

index=foo | rex "Took (?<num>\d+\.?\d+)ms" | ...

If you need help extracting timestamp and hostname, please show some sample data.

---
If this reply helps you, Karma would be appreciated.

twinspop
Influencer

I think that regex is going to surprise in some situations. You are requiring that there be 2 digits. 1 or more digits, followed by optional decimal, followed by 1 or more digits.

0 Karma

JeffCr
Explorer

There will always be at least x.x

0 Karma

richgalloway
SplunkTrust
SplunkTrust

To alert on certain values, schedule a search for those values.

index=foo | rex "Took (?<num>\d+\.?\d+)ms" | where num > someThreshold | table _time hostname num

Have the search trigger an alert if the number of results is not zero.

---
If this reply helps you, Karma would be appreciated.
0 Karma

JeffCr
Explorer

Many thanks for the answer!

0 Karma

skoelpin
SplunkTrust
SplunkTrust

You would use a regular expression..

Try this

| rex (?P<Time>(?<=Took\s)\d+(?=ms))

twinspop
Influencer

This doesn't allow for decimals.

0 Karma

skoelpin
SplunkTrust
SplunkTrust

Sorry about that, try this

| rex (?P<Time>(?<=Took\s)\d+\.\d+(?=ms))

0 Karma

JeffCr
Explorer

Whats the easiest way to search the result set and then alert on a threshold value(s). Do I need to pass this into a command to build a table first?

0 Karma

skoelpin
SplunkTrust
SplunkTrust

No you don't need to do that, you can add a | where clause such as

... | where Time > 2

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!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...