package nodes import ( "fmt" "strings" ) type prometheusDiscovery struct { Labels map[string]string `json:"Labels"` Targets []string `json:"Targets"` } func GetPrometheusSD(p *NodesProcessor, ss string) []prometheusDiscovery { ns := p.List() pds := []prometheusDiscovery{ { Labels: make(map[string]string), Targets: []string{}, }, } for _, node := range ns { port, ok := node.KV["prometheus_port"] if !ok { port = "9999" } host, ok := node.KV["prometheus_host"] if !ok { host = node.HostName } v, ok := node.KV["prometheus_exporters"] if ok { services := strings.Split(v, ",") for _, service := range services { if ss == service { pds[0].Targets = append(pds[0].Targets, fmt.Sprintf("%s:%s", host, port)) } } } } return pds }