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!

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...