# Filter Metric Flush\_Interval

**URL:** https://discuss.elastic.co/t/filter-metric-flush-interval/184618
**Category:** Logstash
**Created:** [June 6, 2019, 3:12pm UTC](https://discuss.elastic.co/t/filter-metric-flush-interval/184618 "2019-06-06T15:12:41Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![BrunoSdeMenezes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brunosdemenezes/32/46413_2.png) [@BrunoSdeMenezes](https://discuss.elastic.co/u/BrunoSdeMenezes)
#### Post date: [June 6, 2019, 3:12pm UTC](https://discuss.elastic.co/t/filter-metric-flush-interval/184618/1 "2019-06-06T15:12:41Z")

</div>

Hello, I'm doing some metrics in a logstash script to generate a new index with some calculations.

Everything works fine for now, but when I change the flush\_interval to some value high, it doesn't work, there is no output. But when I use a flush\_interval with low value, the output creates 2 or 3 events on index depending on value I use.

I want to know if there is a way to flush\_interval be automatized accordingly to the size of input.

This is my script for now:

```
input{
   elasticsearch{
    hosts => "localhost"
    index => "teste"
   }
}

filter {

      metrics{
        meter => ["%{status_contrato}", "events"]
        add_tag => "metric"
        flush_interval => 25
      }

      mutate{
        remove_field =>["message","status_contrato", "[PENDENTE][rate_5m]", "[PENDENTE][rate_1m]", "[PENDENTE][rate_15m]", "[APROVADO][rate_1m]", "[APROVADO][rate_5m]", "[APROVADO][rate_15m]", "[events][rate_15m]", "[events][rate_1m]", "[events][rate_5m]"]
      }

      mutate{
        convert =>{"[APROVADO][count]" => "float"}
        convert =>{"[events][count]" => "float"}
      }

      if "metric" in [tags]{
        ruby{
          code => " aprovados = event.get(%{[APROVADO][count]})/event.get(%{[events][count]})*100;
                    event.set('pct_aprovado', aprovados);

                    pendentes = event.get(%{[PENDENTE][count]})/event.get(%{[events][count]})*100;
                    event.set('pct_pendente', pendentes);
                    "
          add_tag => "metric"
        }
      }

      if "metric" not in [tags]{
        drop{}
      }

      mutate{
        add_field => {"total_aprovados" => "%{[APROVADO][count]}"}
        add_field => {"total_pendentes" => "%{[PENDENTE][count]}"}
        add_field => {"total_contratos" => "%{[events][count]}"}
      }

      mutate{
        convert => {"total_aprovados" => "integer"}
        convert => {"total_pendentes" => "integer"}
        convert => {"total_contratos" => "integer"}
        remove_field => ["[APROVADO]", "[PENDENTE]", "events", "tags", "@version"]
      }

}

output{

  stdout{
    codec => rubydebug
  }

      elasticsearch{
        hosts => "localhost:9200"
        index => "calculos"
      }

```

}

Thanks in advance

---

<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 4, 2019, 3:12pm UTC](https://discuss.elastic.co/t/filter-metric-flush-interval/184618/2 "2019-07-04T15:12:44Z")

</div>

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