# Regarding Metric Filter

**URL:** https://discuss.elastic.co/t/regarding-metric-filter/265211
**Category:** Logstash
**Created:** [February 23, 2021, 2:30pm UTC](https://discuss.elastic.co/t/regarding-metric-filter/265211 "2021-02-23T14:30:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![dawiro](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@dawiro](https://discuss.elastic.co/u/dawiro)
#### Post date: [February 23, 2021, 2:30pm UTC](https://discuss.elastic.co/t/regarding-metric-filter/265211/1 "2021-02-23T14:30:10Z")

</div>

Hi,  
I'm trying to dynamically add fields to a metric filter. Can you tell me why this is failing interpolation?

```auto
        metrics {
          meter => ["events"]
          add_field => {
            "agent" => "%{[agent][hostname]}"
          }
          add_tag => ["metric"]
          enable_metric => false
        }

```

if I use the same syntax with the mutate filter it works fine:

```auto
      mutate {
        add_field => {
        "agent" => "%{[agent][hostname]}"
        }
      }

```

Logstash version is 7.11.1.

Thx  
D

---

<div class="post-metadata">

### Author: ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)
#### Post date: [February 23, 2021, 3:50pm UTC](https://discuss.elastic.co/t/regarding-metric-filter/265211/2 "2021-02-23T15:50:44Z")

</div>

> [@dawiro](#):
>
> I'm trying to dynamically add fields to a metric filter. Can you tell me why this is failing interpolation?

The metrics filter is generating a new event based on the number of events it has seen in the previous five seconds. If it has seen 10 events, from which of those should it extract [agent][hostname]? logstash cannot decide. See [issue 49](https://github.com/logstash-plugins/logstash-filter-metrics/issues/49).

---

<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 23, 2021, 3:51pm UTC](https://discuss.elastic.co/t/regarding-metric-filter/265211/3 "2021-03-23T15:51:35Z")

</div>

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