From 8e81e95a9a0de9e57635a92b5623bf6d6f4f4a0a Mon Sep 17 00:00:00 2001 From: Matteo Castellini Date: Wed, 3 Jun 2020 16:52:27 +0200 Subject: [PATCH] Provide scraping target different from FQDN Signed-off-by: Matteo Castellini --- cmd/client/main.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmd/client/main.go b/cmd/client/main.go index 74d715b..9877562 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -49,6 +49,7 @@ var ( tlsCert = kingpin.Flag("tls.cert", " Client certificate file").String() tlsKey = kingpin.Flag("tls.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 ( @@ -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()) @@ -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{