diff --git a/zetaclient/metrics/metrics.go b/zetaclient/metrics/metrics.go index efb3232590..d6525a70ba 100644 --- a/zetaclient/metrics/metrics.go +++ b/zetaclient/metrics/metrics.go @@ -87,20 +87,16 @@ var ( ) func NewMetrics() (*Metrics, error) { - server := http.NewServeMux() - - server.Handle("/metrics", - promhttp.InstrumentMetricHandler( - prometheus.DefaultRegisterer, - promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{ - Timeout: 30 * time.Second, - }), - ), + handler := promhttp.InstrumentMetricHandler( + prometheus.DefaultRegisterer, + promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{ + Timeout: 30 * time.Second, + }), ) s := &http.Server{ Addr: ":8886", - Handler: server, + Handler: handler, ReadTimeout: 5 * time.Second, ReadHeaderTimeout: 5 * time.Second, } diff --git a/zetaclient/metrics/metrics_test.go b/zetaclient/metrics/metrics_test.go index f40001bbee..b73bf00530 100644 --- a/zetaclient/metrics/metrics_test.go +++ b/zetaclient/metrics/metrics_test.go @@ -30,7 +30,13 @@ func (ms *MetricsSuite) TestMetrics(c *C) { time.Sleep(1 * time.Second) res, err := http.Get("http://127.0.0.1:8886/metrics") c.Assert(err, IsNil) + c.Assert(res.StatusCode, Equals, http.StatusOK) defer res.Body.Close() //out, err := ioutil.ReadAll(res.Body) //fmt.Println(string(out)) + + res, err = http.Get("http://127.0.0.1:8886") + c.Assert(err, IsNil) + c.Assert(res.StatusCode, Equals, http.StatusOK) + defer res.Body.Close() }