From c4ff895168a4f3d61f94a1c3abb74e91c7c8ecb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Tue, 30 Aug 2022 13:35:54 +0100 Subject: [PATCH] Add --address flag for setting listening address MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ɓukasz Mierzwa --- cmd/avalanche.go | 5 +++-- metrics/serve.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmd/avalanche.go b/cmd/avalanche.go index 5a0925a..2965640 100644 --- a/cmd/avalanche.go +++ b/cmd/avalanche.go @@ -39,6 +39,7 @@ var ( valueInterval = kingpin.Flag("value-interval", "Change series values every {interval} seconds.").Default("30").Int() labelInterval = kingpin.Flag("series-interval", "Change series_id label values every {interval} seconds.").Default("60").Int() metricInterval = kingpin.Flag("metric-interval", "Change __name__ label values every {interval} seconds.").Default("120").Int() + address = kingpin.Flag("address", "Address to serve at").Default("").String() port = kingpin.Flag("port", "Port to serve at").Default("9001").Int() remoteURL = kingpin.Flag("remote-url", "URL to send samples via remote_write API.").URL() remotePprofURLs = kingpin.Flag("remote-pprof-urls", "a list of urls to download pprofs during the remote write: --remote-pprof-urls=http://127.0.0.1:10902/debug/pprof/heap --remote-pprof-urls=http://127.0.0.1:10902/debug/pprof/profile").URLList() @@ -131,8 +132,8 @@ func main() { return } - fmt.Printf("Serving ur metrics at localhost:%v/metrics\n", *port) - err = metrics.ServeMetrics(*port) + fmt.Printf("Serving ur metrics at %s:%v/metrics\n", *address, *port) + err = metrics.ServeMetrics(*address, *port) if err != nil { log.Fatal(err) } diff --git a/metrics/serve.go b/metrics/serve.go index f4a495f..5c22529 100644 --- a/metrics/serve.go +++ b/metrics/serve.go @@ -165,11 +165,11 @@ func RunMetrics(metricCount, labelCount, seriesCount, metricLength, labelLength, } // ServeMetrics serves a prometheus metrics endpoint with test series -func ServeMetrics(port int) error { +func ServeMetrics(address string, port int) error { http.Handle("/metrics", promhttp.HandlerFor(promRegistry, promhttp.HandlerOpts{})) h := health.New(health.Health{}) http.HandleFunc("/health", h.Handler) - err := http.ListenAndServe(fmt.Sprintf(":%v", port), nil) + err := http.ListenAndServe(fmt.Sprintf("%s:%v", address, port), nil) if err != nil { return err }