haproxy: move socket address detection to own function
This commit is contained in:
parent
187a894fe9
commit
d63e3c8cc4
|
@ -131,14 +131,7 @@ func (g *haproxy) Gather(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *haproxy) gatherServerSocket(addr string, acc telegraf.Accumulator) error {
|
func (g *haproxy) gatherServerSocket(addr string, acc telegraf.Accumulator) error {
|
||||||
var socketPath string
|
socketPath := getSocketAddr(addr)
|
||||||
socketAddr := strings.Split(addr, ":")
|
|
||||||
|
|
||||||
if len(socketAddr) >= 2 {
|
|
||||||
socketPath = socketAddr[1]
|
|
||||||
} else {
|
|
||||||
socketPath = socketAddr[0]
|
|
||||||
}
|
|
||||||
|
|
||||||
c, err := net.Dial("unix", socketPath)
|
c, err := net.Dial("unix", socketPath)
|
||||||
|
|
||||||
|
@ -196,6 +189,16 @@ func (g *haproxy) gatherServer(addr string, acc telegraf.Accumulator) error {
|
||||||
return importCsvResult(res.Body, acc, u.Host)
|
return importCsvResult(res.Body, acc, u.Host)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getSocketAddr(sock string) string {
|
||||||
|
socketAddr := strings.Split(sock, ":")
|
||||||
|
|
||||||
|
if len(socketAddr) >= 2 {
|
||||||
|
return socketAddr[1]
|
||||||
|
} else {
|
||||||
|
return socketAddr[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func importCsvResult(r io.Reader, acc telegraf.Accumulator, host string) error {
|
func importCsvResult(r io.Reader, acc telegraf.Accumulator, host string) error {
|
||||||
csv := csv.NewReader(r)
|
csv := csv.NewReader(r)
|
||||||
result, err := csv.ReadAll()
|
result, err := csv.ReadAll()
|
||||||
|
|
Loading…
Reference in New Issue