From 1800ee2925a802c57a7e2c99f572b845086c3590 Mon Sep 17 00:00:00 2001 From: "Matt T. Proud" Date: Fri, 11 Jan 2013 22:52:36 +0100 Subject: [PATCH] Make listening port for examples to be settable. This will be better for our own internal tests. --- examples/random/main.go | 13 ++++++++++++- examples/simple/main.go | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/examples/random/main.go b/examples/random/main.go index 144c58a..d88e94f 100644 --- a/examples/random/main.go +++ b/examples/random/main.go @@ -17,6 +17,7 @@ distributions. package main import ( + "flag" "github.com/matttproud/golang_instrumentation" "github.com/matttproud/golang_instrumentation/maths" "github.com/matttproud/golang_instrumentation/metrics" @@ -25,7 +26,17 @@ import ( "time" ) +var ( + listeningAddress string +) + +func init() { + flag.StringVar(&listeningAddress, "listeningAddress", ":8080", "The address to listen to requests on.") +} + func main() { + flag.Parse() + foo_rpc_latency := metrics.CreateHistogram(&metrics.HistogramSpecification{ Starts: metrics.EquallySizedBucketsFor(0, 200, 4), BucketMaker: metrics.AccumulatingBucketBuilder(metrics.EvictAndReplaceWith(10, maths.Average), 50), @@ -71,5 +82,5 @@ func main() { exporter := metrics.YieldExporter() http.Handle("/metrics.json", exporter) - http.ListenAndServe(":8080", nil) + http.ListenAndServe(listeningAddress, nil) } diff --git a/examples/simple/main.go b/examples/simple/main.go index bcd117c..b4a57fc 100644 --- a/examples/simple/main.go +++ b/examples/simple/main.go @@ -13,13 +13,24 @@ framework is registered and invoked. package main import ( + "flag" "github.com/matttproud/golang_instrumentation" "net/http" ) +var ( + listeningAddress string +) + +func init() { + flag.StringVar(&listeningAddress, "listeningAddress", ":8080", "The address to listen to requests on.") +} + func main() { + flag.Parse() + exporter := registry.DefaultRegistry.YieldExporter() http.Handle("/metrics.json", exporter) - http.ListenAndServe(":8080", nil) + http.ListenAndServe(listeningAddress, nil) }