github.com/djenriquez/nomad-1@v0.8.1/command/agent/metrics_endpoint.go (about) 1 package agent 2 3 import ( 4 "net/http" 5 6 "github.com/prometheus/client_golang/prometheus" 7 "github.com/prometheus/client_golang/prometheus/promhttp" 8 ) 9 10 // MetricsRequest returns metrics for the agent. Metrics are JSON by default 11 // but Prometheus is an optional format. 12 func (s *HTTPServer) MetricsRequest(resp http.ResponseWriter, req *http.Request) (interface{}, error) { 13 if req.Method != "GET" { 14 return nil, CodedError(405, ErrInvalidMethod) 15 } 16 17 if format := req.URL.Query().Get("format"); format == "prometheus" { 18 handlerOptions := promhttp.HandlerOpts{ 19 ErrorLog: s.logger, 20 ErrorHandling: promhttp.ContinueOnError, 21 DisableCompression: true, 22 } 23 24 handler := promhttp.HandlerFor(prometheus.DefaultGatherer, handlerOptions) 25 handler.ServeHTTP(resp, req) 26 return nil, nil 27 } 28 29 return s.agent.InmemSink.DisplayMetrics(resp, req) 30 }