Env variable on metricbeat.yml

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

then edited /lib/systemd/system/metricbeat.service file and added

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?


Please check Use environment variables in the configuration | Metricbeat Reference [7.13] | Elastic to find out more about how Metricbeat supports env vars natively. Maybe this is what you need.