2021-06-25 08:42:47 +00:00
|
|
|
package docker
|
2020-10-12 10:38:21 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/promauth"
|
2020-12-24 08:56:10 +00:00
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/proxy"
|
2020-10-12 10:38:21 +00:00
|
|
|
)
|
|
|
|
|
2021-06-25 08:42:47 +00:00
|
|
|
// DockerSDConfig defines the `docker_sd` section for Docker based discovery
|
2020-10-12 10:38:21 +00:00
|
|
|
//
|
2021-06-25 08:42:47 +00:00
|
|
|
// See https://prometheus.io/docs/prometheus/latest/configuration/configuration/#docker_sd_config
|
|
|
|
type DockerSDConfig struct {
|
2020-11-23 14:26:52 +00:00
|
|
|
Host string `yaml:"host"`
|
|
|
|
Port int `yaml:"port,omitempty"`
|
|
|
|
Filters []Filter `yaml:"filters,omitempty"`
|
|
|
|
|
2021-04-03 21:40:08 +00:00
|
|
|
HTTPClientConfig promauth.HTTPClientConfig `yaml:",inline"`
|
|
|
|
ProxyURL proxy.URL `yaml:"proxy_url,omitempty"`
|
|
|
|
ProxyClientConfig promauth.ProxyClientConfig `yaml:",inline"`
|
2021-06-25 08:42:47 +00:00
|
|
|
// refresh_interval is obtained from `-promscrape.dockerSDCheckInterval` command-line option
|
2020-10-12 10:38:21 +00:00
|
|
|
}
|
|
|
|
|
2020-11-23 14:26:52 +00:00
|
|
|
// Filter is a filter, which can be passed to SDConfig.
|
|
|
|
type Filter struct {
|
|
|
|
Name string `yaml:"name"`
|
|
|
|
Values []string `yaml:"values"`
|
|
|
|
}
|
|
|
|
|
2021-06-25 08:42:47 +00:00
|
|
|
// GetLabels returns docker labels according to sdc.
|
|
|
|
func (sdc *DockerSDConfig) GetLabels(baseDir string) ([]map[string]string, error) {
|
|
|
|
cfg, err := getAPIConfigFromDockerSDConfig(sdc, baseDir)
|
2020-10-12 10:38:21 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot get API config: %w", err)
|
|
|
|
}
|
2021-06-25 08:42:47 +00:00
|
|
|
return getContainersLabels(cfg)
|
2020-10-12 10:38:21 +00:00
|
|
|
}
|
2021-03-01 12:13:56 +00:00
|
|
|
|
|
|
|
// MustStop stops further usage for sdc.
|
2021-06-25 08:42:47 +00:00
|
|
|
func (sdc *DockerSDConfig) MustStop() {
|
2021-03-01 12:13:56 +00:00
|
|
|
configMap.Delete(sdc)
|
|
|
|
}
|