I'm trying to extract a number that may not always be formatted the same way every time.
Examples:
OK: Process matching httpd is using 0% CPU
OK: Process matching httpd is using 1.1% CPU
OK: Process matching httpd is using 24.1% CPU
It's the "0%" that is tripping me up.
This will work for numbers with a decimal but not for a percentage that is just "0".
rex "using\s(?<CPU_util_perc>\d+.\d+)\%"
Any help is greatly appreciated.
Try this regex. It accepts any combination of digits and decimals.
using\s(?<CPU_util_perc>[\d\.]+)\%
You also could use
using\s(?<CPU_util_perc>.+)\%
since there's (probably) little chance of anything other than a number being in that position.
Give this a try
| rex "using\s(?<CPU_util_perc>\d+(\.\d+)*)\%"
OR
| rex "using\s(?<CPU_util_perc>[^\%]+)\%"
This worked on the sample data you provided.
using\s(?<CPU_util_perc>[0-9\.]{1,4})%
Try this regex. It accepts any combination of digits and decimals.
using\s(?<CPU_util_perc>[\d\.]+)\%
You also could use
using\s(?<CPU_util_perc>.+)\%
since there's (probably) little chance of anything other than a number being in that position.
They both work!
Thank you
If your problem is resolved, then please click one of the "Accept as Solution" buttons to help future readers.