Skip to content

Commit 8f3fa03

Browse files
authored
Add User-Agent header (#185) (#186)
Set to format: Prometheus-Apache-Exporter/%s
1 parent e37f742 commit 8f3fa03

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

collector/collector.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package collector
1010
import (
1111
"crypto/tls"
1212
"fmt"
13+
"github.com/prometheus/common/version"
1314
"io"
1415
"net/http"
1516
"strconv"
@@ -31,6 +32,7 @@ type Exporter struct {
3132
customHeaders map[string]string
3233
mutex sync.Mutex
3334
client *http.Client
35+
userAgent string
3436

3537
up *prometheus.Desc
3638
scrapeFailures prometheus.Counter
@@ -197,6 +199,7 @@ func NewExporter(logger log.Logger, config *Config) *Exporter {
197199
TLSClientConfig: &tls.Config{InsecureSkipVerify: config.Insecure},
198200
},
199201
},
202+
userAgent: fmt.Sprintf("Prometheus-Apache-Exporter/%s", version.Version),
200203
}
201204
}
202205

@@ -273,6 +276,7 @@ func (e *Exporter) updateScoreboard(scoreboard string) {
273276

274277
func (e *Exporter) collect(ch chan<- prometheus.Metric) error {
275278
req, err := http.NewRequest("GET", e.URI, nil)
279+
req.Header.Set("User-Agent", e.userAgent)
276280
if e.hostOverride != "" {
277281
req.Host = e.hostOverride
278282
}

0 commit comments

Comments
 (0)