1
0
mirror of https://github.com/Lusitaniae/apache_exporter.git synced 2025-07-30 12:03:06 +03:00

Add option to override 'Host' header

This commit is contained in:
Niklas Hambüchen
2019-04-20 00:02:39 +02:00
parent 77c9bc928e
commit 5b8f6b83e8

View File

@ -24,6 +24,7 @@ var (
listeningAddress = flag.String("telemetry.address", ":9117", "Address on which to expose metrics.")
metricsEndpoint = flag.String("telemetry.endpoint", "/metrics", "Path under which to expose metrics.")
scrapeURI = flag.String("scrape_uri", "http://localhost/server-status/?auto", "URI to apache stub status page.")
hostOverride = flag.String("host_override", "", "Override for HTTP Host header; empty string for no override.")
insecure = flag.Bool("insecure", false, "Ignore server certificate if using https.")
showVersion = flag.Bool("version", false, "Print version information.")
)
@ -165,7 +166,14 @@ func (e *Exporter) updateScoreboard(scoreboard string) {
}
func (e *Exporter) collect(ch chan<- prometheus.Metric) error {
resp, err := e.client.Get(e.URI)
req, err := http.NewRequest("GET", e.URI, nil)
if *hostOverride != "" {
req.Host = *hostOverride
}
if err != nil {
return fmt.Errorf("Error building scraping request: %v", err)
}
resp, err := e.client.Do(req)
if err != nil {
ch <- prometheus.MustNewConstMetric(e.up, prometheus.GaugeValue, 0)
return fmt.Errorf("Error scraping apache: %v", err)