Skip to content

Commit

Permalink
Add User-Agent header (#185) (#186)
Browse files Browse the repository at this point in the history
Set to format: Prometheus-Apache-Exporter/%s
  • Loading branch information
theS1LV3R authored Jan 30, 2024
1 parent e37f742 commit 8f3fa03
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package collector
import (
"crypto/tls"
"fmt"
"github.com/prometheus/common/version"
"io"
"net/http"
"strconv"
Expand All @@ -31,6 +32,7 @@ type Exporter struct {
customHeaders map[string]string
mutex sync.Mutex
client *http.Client
userAgent string

up *prometheus.Desc
scrapeFailures prometheus.Counter
Expand Down Expand Up @@ -197,6 +199,7 @@ func NewExporter(logger log.Logger, config *Config) *Exporter {
TLSClientConfig: &tls.Config{InsecureSkipVerify: config.Insecure},
},
},
userAgent: fmt.Sprintf("Prometheus-Apache-Exporter/%s", version.Version),
}
}

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

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

0 comments on commit 8f3fa03

Please sign in to comment.