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"
|
||||||
"github.com/influxdata/telegraf/config"
|
"github.com/influxdata/telegraf/config"
|
||||||
|
"github.com/influxdata/telegraf/internal"
|
||||||
"github.com/influxdata/telegraf/plugins/common/tls"
|
"github.com/influxdata/telegraf/plugins/common/tls"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
parser_v2 "github.com/influxdata/telegraf/plugins/parsers/prometheus"
|
parser_v2 "github.com/influxdata/telegraf/plugins/parsers/prometheus"
|
||||||
|
|
@ -58,7 +59,8 @@ type Prometheus struct {
|
||||||
|
|
||||||
Log telegraf.Logger
|
Log telegraf.Logger
|
||||||
|
|
||||||
client *http.Client
|
client *http.Client
|
||||||
|
headers map[string]string
|
||||||
|
|
||||||
// Should we scrape Kubernetes services for prometheus annotations
|
// Should we scrape Kubernetes services for prometheus annotations
|
||||||
MonitorPods bool `toml:"monitor_kubernetes_pods"`
|
MonitorPods bool `toml:"monitor_kubernetes_pods"`
|
||||||
|
|
@ -273,6 +275,10 @@ func (p *Prometheus) Gather(acc telegraf.Accumulator) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
p.client = client
|
p.client = client
|
||||||
|
p.headers = map[string]string{
|
||||||
|
"User-Agent": internal.ProductToken(),
|
||||||
|
"Accept": acceptHeader,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
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 != "" {
|
if p.BearerToken != "" {
|
||||||
token, err := ioutil.ReadFile(p.BearerToken)
|
token, err := ioutil.ReadFile(p.BearerToken)
|
||||||
|
|
@ -427,6 +433,12 @@ func (p *Prometheus) gatherURL(u URLAndAddress, acc telegraf.Accumulator) error
|
||||||
return nil
|
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.
|
/* Check if the field selector specified is valid.
|
||||||
* See ToSelectableFields() for list of fields that are selectable:
|
* See ToSelectableFields() for list of fields that are selectable:
|
||||||
* https://github.com/kubernetes/kubernetes/release-1.20/pkg/registry/core/pod/strategy.go
|
* https://github.com/kubernetes/kubernetes/release-1.20/pkg/registry/core/pod/strategy.go
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue