# Creating a delta filter in logstash using global variable

**URL:** <https://discuss.elastic.co/t/creating-a-delta-filter-in-logstash-using-global-variable/75008>\
**Category:** Logstash\
**Created:** [February 14, 2017, 10:24am UTC](https://discuss.elastic.co/t/creating-a-delta-filter-in-logstash-using-global-variable/75008 "2017-02-14T10:24:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jayesh.w](https://avatars.discourse-cdn.com/v4/letter/j/e79b87/32.png) [@jayesh.w](https://discuss.elastic.co/u/jayesh.w)\
**Post date:** [February 14, 2017, 10:24am UTC](https://discuss.elastic.co/t/creating-a-delta-filter-in-logstash-using-global-variable/75008/1 "2017-02-14T10:24:06Z")

</div>

I was trying to replicate cpu usage graph in [jconsole.It](http://jconsole.It) needs to substract prvious values from the present [values.So](http://values.So) I am trying to use @@prevprocesscpuload as a global variable.But it is not working please help  
filter{  
if [metric\_path] == "com.hcl.jmxInput.ProcessCpuLoad.ProcessCpuLoad"  
{

ruby{  
init=\>"@@prevprocesscpuload=-1"  
code=\>'  
if(@@prevprocesscpuload==-1)  
delta=0  
else  
delta=event.get(['metric\_value\_number'])-@@prevprocesscpuload  
end  
event.set(['@version'], delta )

@@prevprocesscpuload=event.get(['metric\_value\_number'])  
'  
}

}  
}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 14, 2017, 10:24am UTC](https://discuss.elastic.co/t/creating-a-delta-filter-in-logstash-using-global-variable/75008/2 "2017-03-14T10:24:11Z")

</div>

Closed on March 14, 2017, 10:24am UTC

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