Skip to content

Commit

Permalink
refactoring prometheus endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
chelseakomlo committed Sep 10, 2017
1 parent 7fbaa64 commit ce97e92
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions command/agent/metrics_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,28 @@ package agent

import (
"net/http"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)

// MetricsRequest returns metrics in JSON format
func (s *HTTPServer) MetricsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
if req.Method == "GET" {
return s.agent.InmemSink.DisplayMetrics(resp, req)
if req.Method != "GET" {
return nil, CodedError(405, ErrInvalidMethod)
}
return nil, CodedError(405, ErrInvalidMethod)

if format := req.URL.Query().Get("format"); format == "prometheus" {
handlerOptions := promhttp.HandlerOpts{
ErrorLog: s.logger,
ErrorHandling: promhttp.ContinueOnError,
DisableCompression: true,
}

handler := promhttp.HandlerFor(prometheus.DefaultGatherer, handlerOptions)
handler.ServeHTTP(resp, req)
return nil, nil
}

return s.agent.InmemSink.DisplayMetrics(resp, req)
}

0 comments on commit ce97e92

Please sign in to comment.