Splunk Search

Regex: I want to extract two fields from a log message and visualize as a line chart

nandhiniG
Explorer

HI ,

 I have a log message like " total accounts for user is 11 retrieved in 67 milliseconds". 

How to extract 11 as totalaccounts and 67 as seconds and visualize a chart

Labels (3)
0 Karma

rnowitzki
Builder

Hi @nandhiniG ,

You could extract the values with this:

| makeresults
| eval logmessage="total accounts for user is 11 retrieved in 67 milliseconds"
| rex field=logmessage "total\saccounts\sfor\suser\sis\s(?<totalaccounts>\d+)\sretrieved\sin\s(?<ms>\d+)\smilliseconds"

 

You don't need the first 2 lines, they are just to sample the data you have already.

In the third line, you have to adjust the field=logmessage.  It depends on in which field the log message appears. Probably _raw.

You don't have to put the whole sentence as a regular expression, this would just make it 100% sure it doesn't catch the values from "similiar" messages.

Now you can work with the new fields totalaccounts and ms and put them in a chart. What do you want to visualize?

Just to give you an example, this is the avg count and ms over a span of 5 minutes:

| timechart span=5m avg(totalaccounts), avg(ms)

 
Hope it helps.
BR

Ralph

--
Karma and/or Solution tagging appreciated.
0 Karma

nandhiniG
Explorer

I want to visualize the time taken for each request with the resulting count of accounts

0 Karma
Get Updates on the Splunk Community!

.conf25 Community Recap

Hello Splunkers, And just like that, .conf25 is in the books! What an incredible few days — full of learning, ...

Splunk App Developers | .conf25 Recap & What’s Next

If you stopped by the Builder Bar at .conf25 this year, thank you! The retro tech beer garden vibes were ...

Congratulations to the 2025-2026 SplunkTrust!

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