2013-02-22 12:07:35 -08:00
|
|
|
// Copyright 2013 Prometheus Team
|
|
|
|
// 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-10 17:27:03 -08:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2013-10-22 11:31:52 -07:00
|
|
|
"net/http"
|
2014-06-30 04:19:07 -07:00
|
|
|
|
2014-06-18 10:43:15 -07:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2013-10-22 11:31:52 -07:00
|
|
|
|
2013-05-05 10:32:04 -07:00
|
|
|
"github.com/prometheus/prometheus/config"
|
|
|
|
"github.com/prometheus/prometheus/retrieval"
|
2014-06-06 02:55:53 -07:00
|
|
|
"github.com/prometheus/prometheus/storage/local"
|
2013-01-27 10:59:20 -08:00
|
|
|
"github.com/prometheus/prometheus/utility"
|
2014-12-10 07:16:49 -08:00
|
|
|
"github.com/prometheus/prometheus/web/httputils"
|
2013-01-10 17:27:03 -08:00
|
|
|
)
|
|
|
|
|
2014-12-10 07:16:49 -08:00
|
|
|
// MetricsService manages the /api HTTP endpoint.
|
2013-01-10 17:27:03 -08:00
|
|
|
type MetricsService struct {
|
2013-10-22 11:31:52 -07:00
|
|
|
time utility.Time
|
2013-05-05 10:32:04 -07:00
|
|
|
Config *config.Config
|
|
|
|
TargetManager retrieval.TargetManager
|
2014-09-16 06:47:24 -07:00
|
|
|
Storage local.Storage
|
2013-01-10 17:27:03 -08:00
|
|
|
}
|
2013-10-22 11:31:52 -07:00
|
|
|
|
2014-12-10 07:16:49 -08:00
|
|
|
// RegisterHandler registers the handler for the various endpoints below /api.
|
2013-10-22 11:31:52 -07:00
|
|
|
func (msrv *MetricsService) RegisterHandler() {
|
|
|
|
handler := func(h func(http.ResponseWriter, *http.Request)) http.Handler {
|
2014-12-10 07:16:49 -08:00
|
|
|
return httputils.CompressionHandler{
|
2013-10-22 11:31:52 -07:00
|
|
|
Handler: http.HandlerFunc(h),
|
|
|
|
}
|
|
|
|
}
|
2014-06-18 10:43:15 -07:00
|
|
|
http.Handle("/api/query", prometheus.InstrumentHandler(
|
|
|
|
"/api/query", handler(msrv.Query),
|
|
|
|
))
|
|
|
|
http.Handle("/api/query_range", prometheus.InstrumentHandler(
|
|
|
|
"/api/query_range", handler(msrv.QueryRange),
|
|
|
|
))
|
|
|
|
http.Handle("/api/metrics", prometheus.InstrumentHandler(
|
|
|
|
"/api/metrics", handler(msrv.Metrics),
|
|
|
|
))
|
|
|
|
http.Handle("/api/targets", prometheus.InstrumentHandler(
|
|
|
|
"/api/targets", handler(msrv.SetTargets),
|
|
|
|
))
|
2013-10-22 11:31:52 -07:00
|
|
|
}
|