Logstash Metricbeat field calculation

I'm implementing ruby code through logstash pipeline,Unable to get desired fields created in kibana,what would be right approach to code in order to get desired result?
Want to get CPU % by adding two fileds and divide by no of cores.
ex:((a+b)/n)*100

Below code dosen't work:

ruby {
code => "
userpct = event.get('system.cpu.user.pct')
systempct = event.get('system.cpu.system.pct')
cores = event.get('system.cpu.cores')
cpuusage = (((userpct+systempct)/cores)*100)
if (cpuusage > 20)
event.set('system.cpuusage',cpuusage)
event.set('system.cpu.status','CPUCritical')
else
event.set('system.cpu.status','CPUHealthy')
end

				"
       }

Image:

See this post. Try [system][cpu][user][pct]

@Badger Thanx for your response! Tried the above way you mentioned,didn't worked.


filter
{
mutate { add_field => { "mount.point.usage" => "%{[host][name]} %{[system][filesystem][mount_point]}" } }

ruby {
         code => "
						  userpct = event.get([system][cpu][user][pct])
				          systempct = event.get([system][cpu][system][pct])
						  cores = event.get([system][cpu][cores])
					      cpuusage = (((userpct+systempct)/cores)*100)
                          if (cpuusage > 20)
						  event.set('system.cpuusage',cpuusage)
	                      event.set('system.cpu.status','CPUCritical')
						  else
						  event.set('system.cpu.status','CPUHealthy')
						  end
						  
				"
       }

}

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.