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 | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...