2024-12-22 12:40:50 +00:00
|
|
|
package nodes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type prometheusDiscovery struct {
|
2024-12-22 12:43:31 +00:00
|
|
|
Labels map[string]string `json:"Labels"`
|
|
|
|
Targets []string `json:"Targets"`
|
2024-12-22 12:40:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func GetPrometheusSD(p *NodesProcessor, ss string) []prometheusDiscovery {
|
|
|
|
ns := p.List()
|
|
|
|
|
|
|
|
pds := []prometheusDiscovery{
|
|
|
|
{
|
2024-12-22 12:43:31 +00:00
|
|
|
Labels: make(map[string]string),
|
2024-12-22 12:40:50 +00:00
|
|
|
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
|
|
|
|
}
|