open-nomad/command/agent/metrics_endpoint.go

30 lines
792 B
Go
Raw Normal View History

package agent
import (
"net/http"
2017-09-10 14:43:36 +00:00
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
2017-09-08 18:50:07 +00:00
// MetricsRequest returns metrics in JSON format
func (s *HTTPServer) MetricsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) {
2017-09-10 14:43:36 +00:00
if req.Method != "GET" {
return nil, CodedError(405, ErrInvalidMethod)
}
2017-09-10 14:43:36 +00:00
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)
}