Splunk Search

RegEx for the free -m command - Linux

aferone
Builder

I have a script that runs the "free -m" command, and I am only pulling (grepping) the lines like the following:

-/+ buffers/cache:        219       1789
-/+ buffers/cache:       1469      10557

The first value is used memory, and the second value is free memory.

The RegEx for free memory works for all of the logs:

(?i)^[^:]*:\s+\d+\s+(?P<FreeMemory>.+)

However, for used memory, the following RegEx only works for the 2nd log line above, because of the amount of spaces between "cache:" and the value.

(?i)/cache:       (?P<UsedMemory>[^ ]+)

How do I get the RegEx to work, regardless of how many spaces are in between?

Thanks!

Tags (3)
1 Solution

gfuente
Motivator

Hello

Use this regex to extract both values at the same time:

... | rex "\:\s+(?<usedmemory>\d+)\s+(?<freememory>\d+)" | ...

Regards

View solution in original post

gfuente
Motivator

Hello

Use this regex to extract both values at the same time:

... | rex "\:\s+(?<usedmemory>\d+)\s+(?<freememory>\d+)" | ...

Regards

aferone
Builder

Perfect!! Thank you!

0 Karma
Get Updates on the Splunk Community!

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...