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?
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))
...
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))
...