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!

What the End of Support for Splunk Add-on Builder Means for You

Hello Splunk Community! We want to share an important update regarding the future of the Splunk Add-on Builder ...

Solve, Learn, Repeat: New Puzzle Channel Now Live

Welcome to the Splunk Puzzle PlaygroundIf you are anything like me, you love to solve problems, and what ...

Building Reliable Asset and Identity Frameworks in Splunk ES

 Accurate asset and identity resolution is the backbone of security operations. Without it, alerts are ...