How to set environment variables globally in metric beats

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.

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

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

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

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

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.

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