Skip to content

Commit

Permalink
only run prometheus client if metric-addr present
Browse files Browse the repository at this point in the history
  • Loading branch information
siggy committed Jan 25, 2017
1 parent fd7edef commit c964ca1
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ var (
})
)

func init() {
func registerMetrics() {
prometheus.MustRegister(promRequests)
prometheus.MustRegister(promSuccesses)
prometheus.MustRegister(promLatencyHistogram)
Expand All @@ -227,7 +227,7 @@ func main() {
headers := make(headerSet)
flag.Var(&headers, "header", "HTTP request header. (can be repeated.)")
data := flag.String("data", "", "HTTP request data")
addr := flag.String("addr", ":8505", "service port to run on")
metricAddr := flag.String("metric-addr", "", "port to serve metrics on")

flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s <url> [flags]\n", path.Base(os.Args[0]))
Expand Down Expand Up @@ -316,10 +316,13 @@ func main() {
interrupted := make(chan os.Signal, 2)
signal.Notify(interrupted, syscall.SIGINT)

go func() {
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(*addr, nil)
}()
if *metricAddr != "" {
registerMetrics()
go func() {
http.Handle("/metrics", promhttp.Handler())
http.ListenAndServe(*metricAddr, nil)
}()
}

for {
select {
Expand Down

0 comments on commit c964ca1

Please sign in to comment.