2015-01-21 19:07:45 +00:00
|
|
|
// Copyright 2013 The Prometheus Authors
|
2013-02-12 12:15:40 +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.
|
|
|
|
|
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2013-05-05 17:32:04 +00:00
|
|
|
"sync"
|
2013-05-24 08:44:34 +00:00
|
|
|
"time"
|
2013-08-13 15:19:13 +00:00
|
|
|
|
2015-05-12 14:52:56 +00:00
|
|
|
"github.com/prometheus/prometheus/config"
|
2013-08-13 15:19:13 +00:00
|
|
|
"github.com/prometheus/prometheus/retrieval"
|
2015-03-30 17:43:19 +00:00
|
|
|
"github.com/prometheus/prometheus/rules"
|
2013-02-12 12:15:40 +00:00
|
|
|
)
|
|
|
|
|
2014-12-10 15:16:49 +00:00
|
|
|
// PrometheusStatusHandler implements http.Handler.
|
2013-08-13 15:19:13 +00:00
|
|
|
type PrometheusStatusHandler struct {
|
|
|
|
mu sync.RWMutex
|
|
|
|
|
2015-05-12 13:46:16 +00:00
|
|
|
BuildInfo map[string]string
|
|
|
|
Config string
|
|
|
|
Flags map[string]string
|
|
|
|
|
2015-04-29 08:26:49 +00:00
|
|
|
RuleManager *rules.Manager
|
2015-04-20 10:24:25 +00:00
|
|
|
TargetPools func() map[string][]retrieval.Target
|
2013-05-24 08:44:34 +00:00
|
|
|
|
2015-04-16 23:12:04 +00:00
|
|
|
Birth time.Time
|
2015-03-24 21:04:38 +00:00
|
|
|
PathPrefix string
|
2013-02-12 12:15:40 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 17:53:43 +00:00
|
|
|
// TargetStateToClass returns a map of TargetState to the name of a Bootstrap CSS class.
|
2015-03-07 21:27:39 +00:00
|
|
|
func (h *PrometheusStatusHandler) TargetStateToClass() map[retrieval.TargetState]string {
|
|
|
|
return map[retrieval.TargetState]string{
|
|
|
|
retrieval.Unknown: "warning",
|
|
|
|
retrieval.Healthy: "success",
|
|
|
|
retrieval.Unhealthy: "danger",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-13 15:19:13 +00:00
|
|
|
func (h *PrometheusStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
2015-05-12 14:52:56 +00:00
|
|
|
h.mu.RLock()
|
2015-03-24 21:04:38 +00:00
|
|
|
executeTemplate(w, "status", h, h.PathPrefix)
|
2015-05-12 14:52:56 +00:00
|
|
|
h.mu.RUnlock()
|
|
|
|
}
|
|
|
|
|
|
|
|
// ApplyConfig updates the status handler's state as the new config requires.
|
|
|
|
func (h *PrometheusStatusHandler) ApplyConfig(conf *config.Config) {
|
|
|
|
h.mu.Lock()
|
|
|
|
h.Config = conf.String()
|
|
|
|
h.mu.Unlock()
|
2013-02-12 12:15:40 +00:00
|
|
|
}
|