# How to set environment variables globally in metric beats

**URL:** https://discuss.elastic.co/t/how-to-set-environment-variables-globally-in-metric-beats/154816
**Category:** Beats
**Tags:** metricbeat
**Created:** [October 31, 2018, 10:58am UTC](https://discuss.elastic.co/t/how-to-set-environment-variables-globally-in-metric-beats/154816 "2018-10-31T10:58:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![karthick\_tgi](https://avatars.discourse-cdn.com/v4/letter/k/898d66/32.png) [@karthick\_tgi](https://discuss.elastic.co/u/karthick_tgi)
#### Post date: [October 31, 2018, 10:58am UTC](https://discuss.elastic.co/t/how-to-set-environment-variables-globally-in-metric-beats/154816/1 "2018-10-31T10:58:01Z")

</div>

How to set **environment variables globally** in metric beats.

For example,  
In metric beat folder inside the mysql.yml file defaultlly its hard coded like  
hosts: ["root:root@tcp(localhost:3306)/"]  
username and password are root & root port-3306

Now i set username and password are globally inside the metricbeat . i can access this through in **environemnt property file**.

If you have any idea please share with us.

---

<div class="post-metadata">

### Author: ![jsoriano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsoriano/32/27920_2.png) [@jsoriano](https://discuss.elastic.co/u/jsoriano)
#### Post date: [November 1, 2018, 12:47pm UTC](https://discuss.elastic.co/t/how-to-set-environment-variables-globally-in-metric-beats/154816/2 "2018-11-01T12:47:34Z")

</div>

Hi @karthick_tgi,

You can use environment variables in the configuration, take a look to the documentation page about this: [https://www.elastic.co/guide/en/beats/metricbeat/6.4/using-environ-vars.html](https://www.elastic.co/guide/en/beats/metricbeat/6.4/using-environ-vars.html)

In your case you can modify the `mysql.yml` host entry to something like this:

```auto
    hosts: ['${MYSQL_USER}:${MYSQL_PASSWORD}@tcp(localhost:3306)/']

```

---

<div class="post-metadata">

### Author: ![karthick\_tgi](https://avatars.discourse-cdn.com/v4/letter/k/898d66/32.png) [@karthick\_tgi](https://discuss.elastic.co/u/karthick_tgi)
#### Post date: [November 2, 2018, 4:48am UTC](https://discuss.elastic.co/t/how-to-set-environment-variables-globally-in-metric-beats/154816/3 "2018-11-02T04:48:06Z")

</div>

Dear @jsoriano

Thanks for your quick reply.  
Yes, as you mentioned we can achieve.

Our requirement is:  
#1. Need to use 2 properties like below.  
a) metricbeat-staging.properties  
a) metricbeat-prod.properties

#2 From yaml/yml file need to access the MySql Host, Username and Password values from properties based on the env.

Please let me know if it is possible or not.  
If possible then how can we achieve.

Thanks,  
Karthick

---

<div class="post-metadata">

### Author: ![jsoriano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jsoriano/32/27920_2.png) [@jsoriano](https://discuss.elastic.co/u/jsoriano)
#### Post date: [November 2, 2018, 11:34am UTC](https://discuss.elastic.co/t/how-to-set-environment-variables-globally-in-metric-beats/154816/4 "2018-11-02T11:34:48Z")

</div>

Sorry, it is not possible to load environment variables from files using only metricbeat. For that you'd have to rely on the scripts or service managers you use to configure and start metricbeat.

---

<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: [November 30, 2018, 11:34am UTC](https://discuss.elastic.co/t/how-to-set-environment-variables-globally-in-metric-beats/154816/5 "2018-11-30T11:34:48Z")

</div>

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