From aaf201b9d2f4269bf95970b768650baae814dd8c Mon Sep 17 00:00:00 2001 From: kongfei Date: Tue, 28 Jun 2022 11:34:08 +0800 Subject: [PATCH] support env var for prom instances --- inputs/prometheus/prometheus.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/inputs/prometheus/prometheus.go b/inputs/prometheus/prometheus.go index 32bfd6ce..0913edcd 100644 --- a/inputs/prometheus/prometheus.go +++ b/inputs/prometheus/prometheus.go @@ -57,6 +57,11 @@ func (ins *Instance) Init() error { } else if len(ins.URLs) == 0 { return types.ErrInstancesEmpty } + for i, u := range ins.URLs { + ins.URLs[i] = strings.Replace(u, "$hostname", config.Config.GetHostname(), -1) + ins.URLs[i] = strings.Replace(u, "$ip", config.Config.Global.IP, -1) + ins.URLs[i] = os.Expand(u, config.GetEnv) + } if ins.Timeout <= 0 { ins.Timeout = config.Duration(time.Second * 3)