Skip to content

Commit

Permalink
Provide scraping target different from FQDN
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Castellini <[email protected]>
  • Loading branch information
mcastellini committed Jan 7, 2021
1 parent a68733f commit 2bffc8a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var (
tlsCert = kingpin.Flag("tls.cert", "<cert> Client certificate file").String()
tlsKey = kingpin.Flag("tls.key", "<key> Private key file").String()
metricsAddr = kingpin.Flag("metrics-addr", "Serve Prometheus metrics at this address").Default(":9369").String()
target = kingpin.Flag("target", "Scraping target").String()
)

var (
Expand Down Expand Up @@ -121,6 +122,14 @@ func (c *Coordinator) doScrape(request *http.Request, client *http.Client) {
return
}

if *target != "" {
if request.URL.Port() == "" {
request.URL.Host = *target
} else {
request.URL.Host = *target + ":" + request.URL.Port()
}
}

scrapeResp, err := client.Do(request)
if err != nil {
msg := fmt.Sprintf("failed to scrape %s", request.URL.String())
Expand Down Expand Up @@ -285,6 +294,10 @@ func main() {
}()
}

if *target != "" {
level.Info(coordinator.logger).Log("msg", "Scraping target", "target", *target)
}

transport := &http.Transport{
Proxy: http.ProxyFromEnvironment,
DialContext: (&net.Dialer{
Expand Down

0 comments on commit 2bffc8a

Please sign in to comment.