2015-01-21 19:07:45 +00:00
|
|
|
// Copyright 2013 The Prometheus Authors
|
2013-02-22 20:07:35 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2013-01-11 01:27:03 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2013-10-22 18:31:52 +00:00
|
|
|
"net/http"
|
2014-06-30 11:19:07 +00:00
|
|
|
|
2014-06-18 17:43:15 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2013-10-22 18:31:52 +00:00
|
|
|
|
2015-03-27 22:43:47 +00:00
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
|
|
|
|
2014-06-06 09:55:53 +00:00
|
|
|
"github.com/prometheus/prometheus/storage/local"
|
2014-12-10 15:16:49 +00:00
|
|
|
"github.com/prometheus/prometheus/web/httputils"
|
2013-01-11 01:27:03 +00:00
|
|
|
)
|
|
|
|
|
2014-12-10 15:16:49 +00:00
|
|
|
// MetricsService manages the /api HTTP endpoint.
|
2013-01-11 01:27:03 +00:00
|
|
|
type MetricsService struct {
|
2015-03-27 22:43:47 +00:00
|
|
|
Now func() clientmodel.Timestamp
|
2015-03-27 17:51:13 +00:00
|
|
|
Storage local.Storage
|
2013-01-11 01:27:03 +00:00
|
|
|
}
|
2013-10-22 18:31:52 +00:00
|
|
|
|
2014-12-10 15:16:49 +00:00
|
|
|
// RegisterHandler registers the handler for the various endpoints below /api.
|
2015-03-24 21:04:38 +00:00
|
|
|
func (msrv *MetricsService) RegisterHandler(pathPrefix string) {
|
2013-10-22 18:31:52 +00:00
|
|
|
handler := func(h func(http.ResponseWriter, *http.Request)) http.Handler {
|
2014-12-10 15:16:49 +00:00
|
|
|
return httputils.CompressionHandler{
|
2013-10-22 18:31:52 +00:00
|
|
|
Handler: http.HandlerFunc(h),
|
|
|
|
}
|
|
|
|
}
|
2015-03-24 21:04:38 +00:00
|
|
|
http.Handle(pathPrefix + "api/query", prometheus.InstrumentHandler(
|
|
|
|
pathPrefix + "api/query", handler(msrv.Query),
|
2014-06-18 17:43:15 +00:00
|
|
|
))
|
2015-03-24 21:04:38 +00:00
|
|
|
http.Handle(pathPrefix + "api/query_range", prometheus.InstrumentHandler(
|
|
|
|
pathPrefix + "api/query_range", handler(msrv.QueryRange),
|
2014-06-18 17:43:15 +00:00
|
|
|
))
|
2015-03-24 21:04:38 +00:00
|
|
|
http.Handle(pathPrefix + "api/metrics", prometheus.InstrumentHandler(
|
|
|
|
pathPrefix + "api/metrics", handler(msrv.Metrics),
|
2014-06-18 17:43:15 +00:00
|
|
|
))
|
2013-10-22 18:31:52 +00:00
|
|
|
}
|