Splunk Search

top reports values in both MB & KB: How to convert each to GB

mxanareckless
Path Finder

As you can see, top reports most values in megabytes, but a few are in kilobytes.

splunk1.PNG

I am working on a timechart that will show memory consumption in gigbytes over a day's time.

I need to convert all of the VIRT values containing the letter "K" to megabytes, leave the VIRT values containing the letter "M" untouched, before finally converting all of the VIRT values into gigabytes.

This is my query so far:

index=os_evt_prd sourcetype=top host=kdcprd-db00
| rename COMMAND as Program
| regex Program="(\w+[[:lower:]])"
| replace *oracle WITH oracle
| convert rmunit(VIRT)
| eval "Used GB Mem."=floor(VIRT*0.0009765625)
| timechart avg("Used GB Mem.") BY Program

However, the values don't appear to be calculated properly due to the existence of VIRT values in both MB & KB. How can I get around this?

splunk2.PNG

 

 

Labels (1)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

@mxanareckless 

Test if your VIRT contains the K and then do a division of VIRT after the rmunit(), e.g.

 

your search...
| eval isK=if(match(VIRT,"K"),1,0)
| convert rmunit(VIRT)
| eval VIRT=if(isK=1,VIRT/1024,VIRT)
...

 

Alternatively

your search...
| eval isK=if(match(VIRT,"K"),1,0)
| convert rmunit(VIRT)
| eval "Used GB Mem."=floor(if(isK=1,VIRT/1048576,VIRT/1024))
...

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

@mxanareckless 

Test if your VIRT contains the K and then do a division of VIRT after the rmunit(), e.g.

 

your search...
| eval isK=if(match(VIRT,"K"),1,0)
| convert rmunit(VIRT)
| eval VIRT=if(isK=1,VIRT/1024,VIRT)
...

 

Alternatively

your search...
| eval isK=if(match(VIRT,"K"),1,0)
| convert rmunit(VIRT)
| eval "Used GB Mem."=floor(if(isK=1,VIRT/1048576,VIRT/1024))
...
Get Updates on the Splunk Community!

Index This | What’s a riddle wrapped in an enigma?

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

BORE at .conf25

Boss Of Regular Expression (BORE) was an interactive session run again this year at .conf25 by the brilliant ...

OpenTelemetry for Legacy Apps? Yes, You Can!

This article is a follow-up to my previous article posted on the OpenTelemetry Blog, "Your Critical Legacy App ...