Splunk Search

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

Path Finder

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

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?

Labels (1)
• ### timechart

1 Solution
SplunkTrust

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

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

Alternatively

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

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

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

Alternatively

| 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!

#### Maximize the Value from Microsoft Defender with Splunk

Watch NowJoin Splunk and Sens Consulting for this Security Edition Tech TalkWho should attend:  Security ...

#### This Week's Community Digest - Splunk Community Happenings [6.27.22]

Get the latest news and updates from the Splunk Community here! News From Splunk Answers ✍️ Splunk Answers is ...

#### Reminder! Splunk Love Promo: \$25 Visa Gift Card for Your Honest SOAR Review With ...

We recently launched our first Splunk Love Special, and it's gone phenomenally well, so we're doing it again, ...