# Work with output and metrics

**URL:** https://discuss.elastic.co/t/work-with-output-and-metrics/40464
**Category:** Logstash
**Created:** [January 29, 2016, 10:28am UTC](https://discuss.elastic.co/t/work-with-output-and-metrics/40464 "2016-01-29T10:28:35Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![marcmga](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@marcmga](https://discuss.elastic.co/u/marcmga)
#### Post date: [January 29, 2016, 10:28am UTC](https://discuss.elastic.co/t/work-with-output-and-metrics/40464/1 "2016-01-29T10:28:35Z")

</div>

Hi,

I'm working with metrics.  
Here's my code, which in meter i use the hostname to isolate metrics.

> metrics {  
> meter =\> ["%{host}"]  
> flush\_interval =\> 60  
> clear\_interval =\> 300  
> }

In kibana i'm able to see the metric variables not in the output (email).

In my output i check the metric with this statement:

[%{host}][count]

When i receive an e-mail i've got something like [_hostname_][count] but not the content.  
I tried %{[%{host}][count]}

No idea what i'm doing wrong.

Thanks in advance

---

<div class="post-metadata">

### Author: ![terramexx](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@terramexx](https://discuss.elastic.co/u/terramexx)
#### Post date: [January 30, 2016, 10:35am UTC](https://discuss.elastic.co/t/work-with-output-and-metrics/40464/2 "2016-01-30T10:35:42Z")

</div>

Hi,

I am not sure if it is possible to make such dynamic nested hash access. I cannot found the way too.

But one possible solution could lead through using the ruby filter.

```auto
input {
  generator {
    type => "generated"
  }
}

filter {
  # make up the host_name value
  mutate {
    add_field => {
      "host_name" => "localhost"
    }
  }

  metrics {
    meter => ["%{host_name}"]
    flush_interval => 60
    clear_interval => 300
    # mark the metric event
    add_tag => "metric"  
  }

  if "metric" in [tags] {
  
    # the metric event starts just after the metrics filter
    #the host_name field should be put there back manually
    mutate {
      add_field => {
        "host_name" => "localhost"
      }
    }

    ruby {
      code => "event['host_count'] = event[event['host_name']]['count']"
    }
  }
}

output {
  if "metric" in [tags] {
    stdout {
      codec => line {
        format => "rate %{host_name}: %{host_count}"
      }
    }
  }
}

```

I am not sure how do you fill the host field, actually I had problems when using such variable name thus I used host\_name and I am filling it statically .

---

<div class="post-metadata">

### Author: ![marcmga](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@marcmga](https://discuss.elastic.co/u/marcmga)
#### Post date: [February 1, 2016, 8:40am UTC](https://discuss.elastic.co/t/work-with-output-and-metrics/40464/3 "2016-02-01T08:40:43Z")

</div>

Hello,

It hasn't worked for me.  
I get the host variable from each server. I get it from the message.

Any other ideas why i'm not getting the metric in output configuration?

Thanks

---

<div class="post-metadata">

### Author: ![terramexx](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@terramexx](https://discuss.elastic.co/u/terramexx)
#### Post date: [February 1, 2016, 2:04pm UTC](https://discuss.elastic.co/t/work-with-output-and-metrics/40464/4 "2016-02-01T14:04:25Z")

</div>

That's a pity it didn't help.

I would rather avoid the host variable name, still not sure about the reason, but my example with such name does not work.

The host variable value has to be reintroduced for the metric event, the metric event starts just after the metric filter.

---

<div class="post-metadata">

### Author: ![marcmga](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@marcmga](https://discuss.elastic.co/u/marcmga)
#### Post date: [February 2, 2016, 7:58am UTC](https://discuss.elastic.co/t/work-with-output-and-metrics/40464/5 "2016-02-02T07:58:51Z")

</div>

Hi terramexx,

Thanks for your solution, but doesn't work.  
I don't know why is not working, my solution. It worked for other filter, but not metrics.  
my meter is %{host}. In kibana i can see the metrics, it seems to work properly. However, in output filter, it doesn't work, i use [%{host}][count] and i get something like server1[count].

Any ideas?

Thanks

---

<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:13am UTC](https://discuss.elastic.co/t/work-with-output-and-metrics/40464/6 "2017-07-06T05:13:26Z")

</div>


