# Metric's meter.count ruby variable name?

**URL:** https://discuss.elastic.co/t/metrics-meter-count-ruby-variable-name/2051
**Category:** Logstash
**Created:** [June 6, 2015, 12:48am UTC](https://discuss.elastic.co/t/metrics-meter-count-ruby-variable-name/2051 "2015-06-06T00:48:49Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![kelvinfann](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kelvinfann](https://discuss.elastic.co/u/kelvinfann)
#### Post date: [June 6, 2015, 12:48am UTC](https://discuss.elastic.co/t/metrics-meter-count-ruby-variable-name/2051/1 "2015-06-06T00:48:49Z")

</div>

I am trying to edit the metric's meter.count value with the ruby filter. Does anyone know the variable name of the metric?  
I know it isn't Event['meter\_name.count']

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [June 6, 2015, 10:00am UTC](https://discuss.elastic.co/t/metrics-meter-count-ruby-variable-name/2051/2 "2015-06-06T10:00:49Z")

</div>

`event['meter_name.count']` works fine for me (with Logstash 1.5).

```
input {
  stdin {}
}

filter {
  metrics {
    meter => "meter_name"
    add_tag => "metric"
  }
  ruby {
    code => "
      event['message'] = 'Current count is: ' + event['meter_name.count'].to_s
    "
  }
}

output {
  if "metric" in [tags] {
    stdout {
      codec => json_lines
    }
  }
}
```

---

<div class="post-metadata">

### Author: ![kelvinfann](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kelvinfann](https://discuss.elastic.co/u/kelvinfann)
#### Post date: [June 6, 2015, 2:07pm UTC](https://discuss.elastic.co/t/metrics-meter-count-ruby-variable-name/2051/3 "2015-06-06T14:07:42Z")

</div>

That only gives me an instance (copy) of the actual meter\_name.count. I believe that is the same thing as simply outputting the meter's info. I need to be able to change the meter\_name.count so that all metric event instances will use that changed count after I change it.

I need to be able to do something like this (the following code will error):

```
input {
 stdin {}
}

filter {
  metrics {
    meter => "meter_name"
    add_tag => "metric"
  }
  ruby {
    code => "
      if meter_name.count > SOMENUM then meter_name.count = 0 done
    "
  }
}

output {
  if "metric" in [tags] {
    stdout {
        codec => rubydebug
    }
  }
}
```

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [June 6, 2015, 2:54pm UTC](https://discuss.elastic.co/t/metrics-meter-count-ruby-variable-name/2051/4 "2015-06-06T14:54:42Z")

</div>

Oh, sorry. I missed the part about you wanting to _modify_ the count. That's not supported, but it might be possible to access the filters via the pipeline object, locate the metrics filter, and access its members. Even if that's possible I'd try to find another way of solving the original problem.

---

<div class="post-metadata">

### Author: ![kelvinfann](https://avatars.discourse-cdn.com/v4/letter/k/13edae/32.png) [@kelvinfann](https://discuss.elastic.co/u/kelvinfann)
#### Post date: [June 6, 2015, 11:33pm UTC](https://discuss.elastic.co/t/metrics-meter-count-ruby-variable-name/2051/5 "2015-06-06T23:33:43Z")

</div>

Well, my goal is to simply reset the counter after a certain amount/time. I know there is a clear\_interval but I cannot seem to set the clear to occur directly after a flush. Is there a way to accomplish that?

Right now it seems that if I set clear\_interval and flush\_interval to the same time, the order of occurrences is set (I think the commands are set asynchronously?)

---

<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: [July 6, 2017, 5:38am UTC](https://discuss.elastic.co/t/metrics-meter-count-ruby-variable-name/2051/6 "2017-07-06T05:38:17Z")

</div>


