Splunk Search

help on basic eval

jip31
Motivator

hi

why "MemoryUsage" doenst return any results?

 eval FreeMemory = round(Value, 0). " MB" 
| eval TotalMemory = round((TotalPhysicalMemory / 1024 / 1024), 0). " MB" 
| eval MemoryUsage = (TotalMemory - FreeMemory) / TotalMemory
| stats last(FreeMemory) as "Free Memory", last(TotalMemory) as "Total memory", values(MemoryUsage) as "Memory Usage" by host

Is anybody can help me??

Tags (1)
0 Karma
1 Solution

nickhills
Ultra Champion

Because you have added MB to FreeMemory and TotalMemory in your early evals they are no longer numeric, so you cant do maths on them any more.

remove the ."MB" from the earlier evals, and add it to them at the end:

| eval Free Memory='Free Memory'."MB", Total memory='Total memory'."MB", Memory Usage='Memory Usage'."MB"

thus:

| eval FreeMemory = round(Value, 0)
 | eval TotalMemory = round((TotalPhysicalMemory / 1024 / 1024), 0)
 | eval MemoryUsage = (TotalMemory - FreeMemory) / TotalMemory
 | stats last(FreeMemory) as "Free Memory", last(TotalMemory) as "Total memory", values(MemoryUsage) as "Memory Usage" by host
 | eval Free Memory='Free Memory'."MB", Total memory='Total memory'."MB", Memory Usage='Memory Usage'."MB"
If my comment helps, please give it a thumbs up!

View solution in original post

0 Karma

nickhills
Ultra Champion

Because you have added MB to FreeMemory and TotalMemory in your early evals they are no longer numeric, so you cant do maths on them any more.

remove the ."MB" from the earlier evals, and add it to them at the end:

| eval Free Memory='Free Memory'."MB", Total memory='Total memory'."MB", Memory Usage='Memory Usage'."MB"

thus:

| eval FreeMemory = round(Value, 0)
 | eval TotalMemory = round((TotalPhysicalMemory / 1024 / 1024), 0)
 | eval MemoryUsage = (TotalMemory - FreeMemory) / TotalMemory
 | stats last(FreeMemory) as "Free Memory", last(TotalMemory) as "Total memory", values(MemoryUsage) as "Memory Usage" by host
 | eval Free Memory='Free Memory'."MB", Total memory='Total memory'."MB", Memory Usage='Memory Usage'."MB"
If my comment helps, please give it a thumbs up!
0 Karma
Get Updates on the Splunk Community!

Built-in Service Level Objectives Management to Bridge the Gap Between Service & ...

Wednesday, May 29, 2024  |  11AM PST / 2PM ESTRegister now and join us to learn more about how you can ...

Get Your Exclusive Splunk Certified Cybersecurity Defense Engineer Certification at ...

We’re excited to announce a new Splunk certification exam being released at .conf24! If you’re headed to Vegas ...

Share Your Ideas & Meet the Lantern team at .Conf! Plus All of This Month’s New ...

Splunk Lantern is Splunk’s customer success center that provides advice from Splunk experts on valuable data ...