Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add User-Agent header (#185) #186

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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