Beats (Metricbeat) config not accepting environment variables

We are using Env Vars in our metricbeat.yml file but they are not getting picked up when restarting the service. Metricbeat 5.1.1.

This is basically the same question as answered here:

But...we are exporting the Env Var just before restarting the service and doing this under root (same user that metricbeat service is running under).

   field1: ${THEFIELD}```

```sudo su
export THEFIELD=thevalue
service metricbeat restart```

>Exiting: error unpacking config data: missing field accessing 'fields.field1' (source:'/etc/metricbeat/metricbeat.yml')!

Any ideas?

is the service command really picking up environment variables? Looks like service is actually dropping environment variables when starting daemons.

Thanks Steffen you are right. I misunderstood the behaviour of the service command. The metricbeat doc states

After changing the value of an environment variable, you need to restart Metricbeat to pick up the new value.

What is best practice for restarting Metricbeat if we cannot use the service command?

I wouldn't use an environment variable here. The problem with service startup is, is your environment variable already available by init-process (most likely not).

Either update your config file or the startup script.

See google

This topic was automatically closed after 21 days. New replies are no longer allowed.