Query servers in parallel in dns_query input (#4754)
This commit is contained in:
parent
af0ef55c02
commit
7d97ae6421
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
|
@ -70,10 +71,13 @@ func (d *DnsQuery) Description() string {
|
||||||
return "Query given DNS server and gives statistics"
|
return "Query given DNS server and gives statistics"
|
||||||
}
|
}
|
||||||
func (d *DnsQuery) Gather(acc telegraf.Accumulator) error {
|
func (d *DnsQuery) Gather(acc telegraf.Accumulator) error {
|
||||||
|
var wg sync.WaitGroup
|
||||||
d.setDefaultValues()
|
d.setDefaultValues()
|
||||||
|
|
||||||
for _, domain := range d.Domains {
|
for _, domain := range d.Domains {
|
||||||
for _, server := range d.Servers {
|
for _, server := range d.Servers {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(domain, server string) {
|
||||||
fields := make(map[string]interface{}, 2)
|
fields := make(map[string]interface{}, 2)
|
||||||
tags := map[string]string{
|
tags := map[string]string{
|
||||||
"server": server,
|
"server": server,
|
||||||
|
@ -93,9 +97,11 @@ func (d *DnsQuery) Gather(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
acc.AddFields("dns_query", fields, tags)
|
acc.AddFields("dns_query", fields, tags)
|
||||||
|
}(domain, server)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wg.Wait()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue