lobby2/nodes/prometheus.go
Adam Štrauch ae6ca5c185
All checks were successful
Tests / test (push) Successful in 12s
Support for Prometheus SD
2024-12-22 13:40:50 +01:00

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
}