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 --address flag for setting listening address #45

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/avalanche.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions metrics/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down