# Env variable on metricbeat.yml

**URL:** https://discuss.elastic.co/t/env-variable-on-metricbeat-yml/279394
**Category:** Beats
**Tags:** metricbeat
**Created:** [July 22, 2021, 1:53pm UTC](https://discuss.elastic.co/t/env-variable-on-metricbeat-yml/279394 "2021-07-22T13:53:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)
#### Post date: [July 22, 2021, 1:53pm UTC](https://discuss.elastic.co/t/env-variable-on-metricbeat-yml/279394/1 "2021-07-22T13:53:46Z")

</div>

In metricbeat I am trying to use env variable to seperate out log file

this is how I understood from few post here that I read.

created /etc/metricbeat/env file and added  
HOST=myelkhost1

then edited /lib/systemd/system/metricbeat.service file and added  
EnvironmentFile=/etc/metricbeat/env

run systemctl daemon-reload

restarted metricbeat and I have logfile metricbeat\_myelkhost1

problem here is that everytime when I update metricbeat I will have to change /lib/systemd/system/metricbeat.service file in order to make this work.

is there any other option?

second problem is that in env file it works only if I hard code name.  
I can't use any `hostname -s` or any linux command.  
how do I manage this with 100s of system?

---

<div class="post-metadata">

### Author: ![ChrsMark](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chrsmark/32/55858_2.png) [@ChrsMark](https://discuss.elastic.co/u/ChrsMark)
#### Post date: [July 26, 2021, 11:08am UTC](https://discuss.elastic.co/t/env-variable-on-metricbeat-yml/279394/2 "2021-07-26T11:08:53Z")

</div>

Hi!

Please check [Use environment variables in the configuration | Metricbeat Reference [7.13] | Elastic](https://www.elastic.co/guide/en/beats/metricbeat/current/using-environ-vars.html) to find out more about how Metricbeat supports env vars natively. Maybe this is what you need.

C.

---

<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: [August 23, 2021, 1:08pm UTC](https://discuss.elastic.co/t/env-variable-on-metricbeat-yml/279394/3 "2021-08-23T13:08:59Z")

</div>

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