mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 14:09:41 -08:00
Implemented host_network_host setting
Signed-off-by: Levi Harrison <git@leviharrison.dev>
This commit is contained in:
parent
60804c5a09
commit
41be43647b
|
@ -54,6 +54,7 @@ var DefaultDockerSDConfig = DockerSDConfig{
|
||||||
RefreshInterval: model.Duration(60 * time.Second),
|
RefreshInterval: model.Duration(60 * time.Second),
|
||||||
Port: 80,
|
Port: 80,
|
||||||
Filters: []Filter{},
|
Filters: []Filter{},
|
||||||
|
HostNetworkHost: "localhost",
|
||||||
HTTPClientConfig: config.DefaultHTTPClientConfig,
|
HTTPClientConfig: config.DefaultHTTPClientConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,6 +69,7 @@ type DockerSDConfig struct {
|
||||||
Host string `yaml:"host"`
|
Host string `yaml:"host"`
|
||||||
Port int `yaml:"port"`
|
Port int `yaml:"port"`
|
||||||
Filters []Filter `yaml:"filters"`
|
Filters []Filter `yaml:"filters"`
|
||||||
|
HostNetworkHost string `yaml:"host_network_host"`
|
||||||
|
|
||||||
RefreshInterval model.Duration `yaml:"refresh_interval"`
|
RefreshInterval model.Duration `yaml:"refresh_interval"`
|
||||||
}
|
}
|
||||||
|
@ -106,6 +108,7 @@ type DockerDiscovery struct {
|
||||||
*refresh.Discovery
|
*refresh.Discovery
|
||||||
client *client.Client
|
client *client.Client
|
||||||
port int
|
port int
|
||||||
|
hostNetworkHost string
|
||||||
filters filters.Args
|
filters filters.Args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +118,7 @@ func NewDockerDiscovery(conf *DockerSDConfig, logger log.Logger) (*DockerDiscove
|
||||||
|
|
||||||
d := &DockerDiscovery{
|
d := &DockerDiscovery{
|
||||||
port: conf.Port,
|
port: conf.Port,
|
||||||
|
hostNetworkHost: conf.HostNetworkHost,
|
||||||
}
|
}
|
||||||
|
|
||||||
hostURL, err := url.Parse(conf.Host)
|
hostURL, err := url.Parse(conf.Host)
|
||||||
|
@ -245,7 +249,15 @@ func (d *DockerDiscovery) refresh(ctx context.Context) ([]*targetgroup.Group, er
|
||||||
labels[model.LabelName(k)] = model.LabelValue(v)
|
labels[model.LabelName(k)] = model.LabelValue(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
addr := net.JoinHostPort(n.IPAddress, strconv.FormatUint(uint64(d.port), 10))
|
// Containers in host networking mode don't have ports,
|
||||||
|
// so they only end up here, not in the previous loop.
|
||||||
|
var addr string
|
||||||
|
if c.HostConfig.NetworkMode != "host" {
|
||||||
|
addr = net.JoinHostPort(n.IPAddress, strconv.FormatUint(uint64(d.port), 10))
|
||||||
|
} else {
|
||||||
|
addr = d.hostNetworkHost
|
||||||
|
}
|
||||||
|
|
||||||
labels[model.AddressLabel] = model.LabelValue(addr)
|
labels[model.AddressLabel] = model.LabelValue(addr)
|
||||||
tg.Targets = append(tg.Targets, labels)
|
tg.Targets = append(tg.Targets, labels)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue