All Apps and Add-ons

parsing log text to get a specific info

wxt4359
New Member

Hi I am newbie to splunk and trying to build a search query that can parse a specific text like below to get the sum of the AAA file content length but couldn't figure out on the search query for that. Any helps will be appreciated. Thanks.

AAA file content length is 67095 bytes
AAA file content length is 7095 bytes

0 Karma
1 Solution

gcusello
SplunkTrust
SplunkTrust

Hi @wxt4359,
as @martin_mueller hinted, you have to extract the filename and length fields using a rex and the sum the values of the length field for each filename using stats, something like this:

index=your_index
| rex "^(?<filename>[^ ]+).*length\s+is\s+(?<legth>\d+)\sbytes"
| stats sum(length) AS total_length BY filename

You can test your regex at https://regex101.com/r/no5Gwk/1
You can find more details baour rex and stats command at the urls indicated by martin_mueller.

Ciao.
Giuseppe

View solution in original post

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @wxt4359,
as @martin_mueller hinted, you have to extract the filename and length fields using a rex and the sum the values of the length field for each filename using stats, something like this:

index=your_index
| rex "^(?<filename>[^ ]+).*length\s+is\s+(?<legth>\d+)\sbytes"
| stats sum(length) AS total_length BY filename

You can test your regex at https://regex101.com/r/no5Gwk/1
You can find more details baour rex and stats command at the urls indicated by martin_mueller.

Ciao.
Giuseppe

0 Karma

martin_mueller
SplunkTrust
SplunkTrust
0 Karma

to4kawa
Ultra Champion
....
| rex "(?<content_length>\d+)"
| stats sum(content_length) as total_bytes
0 Karma

wxt4359
New Member

Thank you all

0 Karma
Get Updates on the Splunk Community!

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...

.conf24 | Personalize your .conf experience with Learning Paths!

Personalize your .conf24 Experience Learning paths allow you to level up your skill sets and dive deeper ...

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...