Set user agent when scraping prom metrics (#9271)
This commit is contained in:
parent
3a1a44d67e
commit
e8ae01921b
|
|
@ -15,6 +15,7 @@ import (
|
|||
|
||||
"github.com/influxdata/telegraf"
|
||||
"github.com/influxdata/telegraf/config"
|
||||
"github.com/influxdata/telegraf/internal"
|
||||
"github.com/influxdata/telegraf/plugins/common/tls"
|
||||
"github.com/influxdata/telegraf/plugins/inputs"
|
||||
parser_v2 "github.com/influxdata/telegraf/plugins/parsers/prometheus"
|
||||
|
|
@ -58,7 +59,8 @@ type Prometheus struct {
|
|||
|
||||
Log telegraf.Logger
|
||||
|
||||
client *http.Client
|
||||
client *http.Client
|
||||
headers map[string]string
|
||||
|
||||
// Should we scrape Kubernetes services for prometheus annotations
|
||||
MonitorPods bool `toml:"monitor_kubernetes_pods"`
|
||||
|
|
@ -273,6 +275,10 @@ func (p *Prometheus) Gather(acc telegraf.Accumulator) error {
|
|||
return err
|
||||
}
|
||||
p.client = client
|
||||
p.headers = map[string]string{
|
||||
"User-Agent": internal.ProductToken(),
|
||||
"Accept": acceptHeader,
|
||||
}
|
||||
}
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
|
@ -350,7 +356,7 @@ func (p *Prometheus) gatherURL(u URLAndAddress, acc telegraf.Accumulator) error
|
|||
}
|
||||
}
|
||||
|
||||
req.Header.Add("Accept", acceptHeader)
|
||||
p.addHeaders(req)
|
||||
|
||||
if p.BearerToken != "" {
|
||||
token, err := ioutil.ReadFile(p.BearerToken)
|
||||
|
|
@ -427,6 +433,12 @@ func (p *Prometheus) gatherURL(u URLAndAddress, acc telegraf.Accumulator) error
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Prometheus) addHeaders(req *http.Request) {
|
||||
for header, value := range p.headers {
|
||||
req.Header.Add(header, value)
|
||||
}
|
||||
}
|
||||
|
||||
/* Check if the field selector specified is valid.
|
||||
* See ToSelectableFields() for list of fields that are selectable:
|
||||
* https://github.com/kubernetes/kubernetes/release-1.20/pkg/registry/core/pod/strategy.go
|
||||
|
|
|
|||
Loading…
Reference in New Issue