45 lines
777 B
Go
45 lines
777 B
Go
package nodes
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
type prometheusDiscovery struct {
|
|
Labels Labels `json:"Labels"`
|
|
Targets []string `json:"Targets"`
|
|
}
|
|
|
|
func GetPrometheusSD(p *NodesProcessor, ss string) []prometheusDiscovery {
|
|
ns := p.List()
|
|
|
|
pds := []prometheusDiscovery{
|
|
{
|
|
Labels: Labels{},
|
|
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
|
|
}
|