Skip to content
Snippets Groups Projects
Commit 2d842fef authored by Marko Crnic's avatar Marko Crnic Committed by Cameron Sparr
Browse files

haproxy: add support for socket name globbing

parent d63e3c8c
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"net" "net"
"net/http" "net/http"
"net/url" "net/url"
"path/filepath"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
...@@ -116,10 +117,36 @@ func (g *haproxy) Gather(acc telegraf.Accumulator) error { ...@@ -116,10 +117,36 @@ func (g *haproxy) Gather(acc telegraf.Accumulator) error {
return g.gatherServer("http://127.0.0.1:1936/haproxy?stats", acc) return g.gatherServer("http://127.0.0.1:1936/haproxy?stats", acc)
} }
endpoints := make([]string, 0, len(g.Servers))
for _, endpoint := range g.Servers {
if strings.HasPrefix(endpoint, "http") {
endpoints = append(endpoints, endpoint)
continue
}
socketPath := getSocketAddr(endpoint)
matches, err := filepath.Glob(socketPath)
if err != nil {
return err
}
if len(matches) == 0 {
endpoints = append(endpoints, socketPath)
} else {
for _, match := range matches {
endpoints = append(endpoints, match)
}
}
}
var wg sync.WaitGroup var wg sync.WaitGroup
errChan := errchan.New(len(g.Servers)) errChan := errchan.New(len(endpoints))
wg.Add(len(g.Servers)) wg.Add(len(endpoints))
for _, server := range g.Servers { for _, server := range endpoints {
go func(serv string) { go func(serv string) {
defer wg.Done() defer wg.Done()
errChan.C <- g.gatherServer(serv, acc) errChan.C <- g.gatherServer(serv, acc)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment