2017-09-04 03:50:05 +00:00
|
|
|
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-04 03:50:05 +00:00
|
|
|
)
|
|
|
|
|
2017-09-11 16:10:09 +00:00
|
|
|
// MetricsRequest returns metrics for the agent. Metrics are JSON by default
|
|
|
|
// but Prometheus is an optional format.
|
2017-09-04 03:50:05 +00:00
|
|
|
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-04 03:50:05 +00:00
|
|
|
}
|
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)
|
2017-09-04 03:50:05 +00:00
|
|
|
}
|