# Referencing fields in Metrics output

**URL:** https://discuss.elastic.co/t/referencing-fields-in-metrics-output/60869
**Category:** Logstash
**Created:** [September 19, 2016, 11:02am UTC](https://discuss.elastic.co/t/referencing-fields-in-metrics-output/60869 "2016-09-19T11:02:42Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Kryten](https://avatars.discourse-cdn.com/v4/letter/k/58956e/32.png) [@Kryten](https://discuss.elastic.co/u/Kryten)
#### Post date: [September 19, 2016, 11:02am UTC](https://discuss.elastic.co/t/referencing-fields-in-metrics-output/60869/1 "2016-09-19T11:02:42Z")

</div>

Hi,  
I'm trying to output a custom formatted line which must include:

1. Events per second metric.
2. The LS hostname.

I have this metric filter in the "filter" section:

```
metrics {
    meter => "events"
    add_tag => "metric"
    flush_interval => 5
}

```

And I have this block in my output section:

```
if "metric" in [tags] {
        stdout {
            codec => line {
                format => "%{host} 1m event rate: %{[events][rate_1m]}"
            }
        }
    }

```

But for some reason the %{host} value is not being output and I am getting the literal string '%{host}' ouput to the console like this:

`%{host} 1m event rate: 0.0`

What am I doing wrong? Can we not use %{field\_name} in the metrics output? I need to output a specifically formatted line for the metrics to be collected properly with my application.

Would appreciate any advice on why my fields don't appear to be available to me.

Thanks!

---

<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: [September 19, 2016, 11:23am UTC](https://discuss.elastic.co/t/referencing-fields-in-metrics-output/60869/2 "2016-09-19T11:23:38Z")

</div>

The symptoms indicate that the metrics event don't have a `host` field. Looking at the source it looks like it's the `message` field the includes the hostname. Not sure why it's done like that.

---

<div class="post-metadata">

### Author: ![Kryten](https://avatars.discourse-cdn.com/v4/letter/k/58956e/32.png) [@Kryten](https://discuss.elastic.co/u/Kryten)
#### Post date: [September 19, 2016, 11:57am UTC](https://discuss.elastic.co/t/referencing-fields-in-metrics-output/60869/3 "2016-09-19T11:57:15Z")

</div>

Thanks @magnusbaeck

That's a bit of a disappointment, to say the least. Any ideas about how to get the Logstash hostname or other unique identifier into the metrics output? We are planning on having a cluster of LS machines and it is essential to know what kind of throughput each machine is dealing with... Would be grateful for any suggestions.

---

<div class="post-metadata">

### Author: ![eperry](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eperry/32/551_2.png) [@eperry](https://discuss.elastic.co/u/eperry)
#### Post date: [September 19, 2016, 12:20pm UTC](https://discuss.elastic.co/t/referencing-fields-in-metrics-output/60869/4 "2016-09-19T12:20:29Z")

</div>

You can do what I did , add a flag to logstash --allow-env its a new feature

[https://www.elastic.co/guide/en/logstash/current/environment-variables.html](https://www.elastic.co/guide/en/logstash/current/environment-variables.html)

Then it would be as easy as  
----------------sudo code-----  
mutate {  
add\_field =\> ["host" , "${HOSTNAME}"  
}

---

<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: [September 19, 2016, 1:15pm UTC](https://discuss.elastic.co/t/referencing-fields-in-metrics-output/60869/5 "2016-09-19T13:15:24Z")

</div>

> Any ideas about how to get the Logstash hostname or other unique identifier into the metrics output?

So... the hostname isn't present in the `message` field?

---

<div class="post-metadata">

### Author: ![Kryten](https://avatars.discourse-cdn.com/v4/letter/k/58956e/32.png) [@Kryten](https://discuss.elastic.co/u/Kryten)
#### Post date: [September 20, 2016, 1:43pm UTC](https://discuss.elastic.co/t/referencing-fields-in-metrics-output/60869/6 "2016-09-20T13:43:00Z")

</div>

@magnusbaeck  
Thanks for your input. Yes the message field does indeed contain the hostname and I was able to leverage that to generate the structure/formatting I needed. Many thanks! I do have another question about metrics but I'll create a new thread for that.

@eperry  
Thanks for the suggestion. Much appreciated

---

<div class="post-metadata">

### Author: ![danieljamesscott](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danieljamesscott/32/47151_2.png) [@danieljamesscott](https://discuss.elastic.co/u/danieljamesscott)
#### Post date: [February 7, 2017, 12:14pm UTC](https://discuss.elastic.co/t/referencing-fields-in-metrics-output/60869/7 "2017-02-07T12:14:51Z")

</div>

I'm also experiencing the same issue, I have a 'response' field in my message, which I can use to generate a metric, but am not able to use this field to add a new field to the metric event.

Did you ever solve this?

---

<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, 4:28am UTC](https://discuss.elastic.co/t/referencing-fields-in-metrics-output/60869/8 "2017-07-06T04:28:50Z")

</div>


