# When I want to use the 'count' value in metric, it returns nilClass

**URL:** https://discuss.elastic.co/t/when-i-want-to-use-the-count-value-in-metric-it-returns-nilclass/70032
**Category:** Logstash
**Created:** [December 27, 2016, 3:26am UTC](https://discuss.elastic.co/t/when-i-want-to-use-the-count-value-in-metric-it-returns-nilclass/70032 "2016-12-27T03:26:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![eastmxc](https://avatars.discourse-cdn.com/v4/letter/e/e36b37/32.png) [@eastmxc](https://discuss.elastic.co/u/eastmxc)
#### Post date: [December 27, 2016, 3:26am UTC](https://discuss.elastic.co/t/when-i-want-to-use-the-count-value-in-metric-it-returns-nilclass/70032/1 "2016-12-27T03:26:00Z")

</div>

I'm doing some test, my filter is like the following:

> ```
> filter{
> grok{
> patterns_dir => ["./my_pattern"]
> match => ["message","%{MY_PATTERN:ppp}"]
> remove_field => ["message"]
> add_tag => "warn"
> }
> metrics{
> meter => "events_%{ppp}"
> add_tag => "metric"
> }
> if "metric" in [tags]{
> ruby{
> code => 'event.cancel if event.get("[event_qwert][count]") < 5'
> }
> }
> }
> 
> ```

But when I run it, I always get a ruby exception like this:

> [2016-12-27T18:42:59,080][ERROR][logstash.filters.ruby] Ruby exception occurred: undefined method `\<' for nil:NilClass

I'm sure the value exists, this is the output:

> ```
> {
> "@timestamp" => 2016-12-27T23:42:59.058Z,
> "@version" => "1",
> "events_qwert" => {
> "rate_1m" => 0.2,
> "rate_15m" => 0.2,
> "count" => 1,
> "rate_5m" => 0.2
> },
> "message" => "netdm-2",
> "tags" => [
> [0] "metric",
> [1] "_rubyexception"
> ]
> }
> 
> ```

so, what's wrong with my configuration? Why can't it get the value?

---

<div class="post-metadata">

### Author: ![jsvd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsvd/32/6203_2.png) [@jsvd](https://discuss.elastic.co/u/jsvd)
#### Post date: [December 27, 2016, 10:06am UTC](https://discuss.elastic.co/t/when-i-want-to-use-the-count-value-in-metric-it-returns-nilclass/70032/2 "2016-12-27T10:06:31Z")

</div>

> [@eastmxc](#):
>
> event.get("[event\_qwert][count]")

in your config you have: `meter => "events_%{ppp}"`

So the ruby code is missing an "s" in the getter, should be `event.get("[events_qwert][count]")`

---

<div class="post-metadata">

### Author: ![eastmxc](https://avatars.discourse-cdn.com/v4/letter/e/e36b37/32.png) [@eastmxc](https://discuss.elastic.co/u/eastmxc)
#### Post date: [December 27, 2016, 10:34am UTC](https://discuss.elastic.co/t/when-i-want-to-use-the-count-value-in-metric-it-returns-nilclass/70032/3 "2016-12-27T10:34:22Z")

</div>

Ooops! It's really a fool mistake.....and sometimes it's hard to detected by oneself. Anyway, thanks a lot!!!

---

<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: [January 24, 2017, 10:34am UTC](https://discuss.elastic.co/t/when-i-want-to-use-the-count-value-in-metric-it-returns-nilclass/70032/4 "2017-01-24T10:34:22Z")

</div>

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