2015-01-21 19:07:45 +00:00
|
|
|
// Copyright 2013 The Prometheus Authors
|
2013-02-08 13:49:55 +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 (
|
2013-04-05 11:41:52 +00:00
|
|
|
"fmt"
|
2015-06-15 10:50:53 +00:00
|
|
|
"io"
|
2014-07-29 16:28:48 +00:00
|
|
|
"io/ioutil"
|
2013-02-08 13:49:55 +00:00
|
|
|
"net/http"
|
2015-06-15 10:50:53 +00:00
|
|
|
"net/url"
|
2013-08-09 16:09:44 +00:00
|
|
|
"os"
|
2015-06-15 10:50:53 +00:00
|
|
|
"path/filepath"
|
|
|
|
"sort"
|
2015-03-24 21:04:38 +00:00
|
|
|
"strings"
|
2015-06-15 10:50:53 +00:00
|
|
|
"sync"
|
2013-08-29 13:15:22 +00:00
|
|
|
"time"
|
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
template_std "html/template"
|
2013-08-29 13:15:22 +00:00
|
|
|
pprof_runtime "runtime/pprof"
|
2013-06-28 08:19:16 +00:00
|
|
|
|
2015-06-04 16:24:04 +00:00
|
|
|
clientmodel "github.com/prometheus/client_golang/model"
|
2013-06-28 08:19:16 +00:00
|
|
|
"github.com/prometheus/client_golang/prometheus"
|
2015-05-20 16:10:29 +00:00
|
|
|
"github.com/prometheus/log"
|
2013-06-28 08:19:16 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
"github.com/prometheus/prometheus/config"
|
|
|
|
"github.com/prometheus/prometheus/promql"
|
|
|
|
"github.com/prometheus/prometheus/retrieval"
|
|
|
|
"github.com/prometheus/prometheus/rules"
|
|
|
|
"github.com/prometheus/prometheus/storage/local"
|
|
|
|
"github.com/prometheus/prometheus/template"
|
|
|
|
"github.com/prometheus/prometheus/util/route"
|
2015-06-15 10:23:02 +00:00
|
|
|
"github.com/prometheus/prometheus/version"
|
2015-06-04 16:24:04 +00:00
|
|
|
"github.com/prometheus/prometheus/web/api/legacy"
|
|
|
|
"github.com/prometheus/prometheus/web/api/v1"
|
2013-06-28 08:19:16 +00:00
|
|
|
"github.com/prometheus/prometheus/web/blob"
|
2013-02-08 13:49:55 +00:00
|
|
|
)
|
|
|
|
|
2015-05-18 10:16:25 +00:00
|
|
|
var localhostRepresentations = []string{"127.0.0.1", "localhost"}
|
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
// Handler serves various HTTP endpoints of the Prometheus server
|
|
|
|
type Handler struct {
|
|
|
|
ruleManager *rules.Manager
|
|
|
|
queryEngine *promql.Engine
|
|
|
|
|
|
|
|
apiV1 *v1.API
|
|
|
|
apiLegacy *legacy.API
|
|
|
|
|
|
|
|
router *route.Router
|
|
|
|
quitCh chan struct{}
|
|
|
|
options *Options
|
|
|
|
status *PrometheusStatus
|
|
|
|
|
|
|
|
muAlerts sync.Mutex
|
|
|
|
}
|
2013-02-08 14:38:50 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
// PrometheusStatus contains various information about the status
|
|
|
|
// of the running Prometheus process.
|
|
|
|
type PrometheusStatus struct {
|
2015-06-15 10:23:02 +00:00
|
|
|
Birth time.Time
|
|
|
|
Flags map[string]string
|
|
|
|
Config string
|
2015-06-15 10:50:53 +00:00
|
|
|
|
|
|
|
// A function that returns the current scrape targets pooled
|
|
|
|
// by their job name.
|
|
|
|
TargetPools func() map[string][]*retrieval.Target
|
|
|
|
// A function that returns all loaded rules.
|
|
|
|
Rules func() []rules.Rule
|
|
|
|
|
|
|
|
mu sync.RWMutex
|
2015-06-02 11:07:46 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
// ApplyConfig updates the status state as the new config requires.
|
|
|
|
// Returns true on success.
|
|
|
|
func (s *PrometheusStatus) ApplyConfig(conf *config.Config) bool {
|
|
|
|
s.mu.Lock()
|
|
|
|
s.Config = conf.String()
|
|
|
|
s.mu.Unlock()
|
|
|
|
return true
|
2013-05-05 17:32:04 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
// Options for the web Handler.
|
|
|
|
type Options struct {
|
|
|
|
PathPrefix string
|
|
|
|
ListenAddress string
|
|
|
|
Hostname string
|
|
|
|
MetricsPath string
|
|
|
|
UseLocalAssets bool
|
|
|
|
UserAssetsPath string
|
|
|
|
ConsoleTemplatesPath string
|
|
|
|
ConsoleLibrariesPath string
|
|
|
|
EnableQuit bool
|
|
|
|
}
|
|
|
|
|
|
|
|
// New initializes a new web Handler.
|
|
|
|
func New(st local.Storage, qe *promql.Engine, rm *rules.Manager, status *PrometheusStatus, o *Options) *Handler {
|
2015-06-03 06:38:50 +00:00
|
|
|
router := route.New()
|
2015-03-24 21:04:38 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
h := &Handler{
|
|
|
|
router: router,
|
|
|
|
quitCh: make(chan struct{}),
|
|
|
|
options: o,
|
|
|
|
status: status,
|
|
|
|
|
|
|
|
ruleManager: rm,
|
|
|
|
queryEngine: qe,
|
|
|
|
|
|
|
|
apiV1: &v1.API{
|
|
|
|
QueryEngine: qe,
|
|
|
|
Storage: st,
|
|
|
|
},
|
|
|
|
apiLegacy: &legacy.API{
|
|
|
|
QueryEngine: qe,
|
|
|
|
Storage: st,
|
|
|
|
Now: clientmodel.Now,
|
|
|
|
},
|
2015-06-02 11:07:46 +00:00
|
|
|
}
|
2013-05-06 07:56:32 +00:00
|
|
|
|
2015-06-03 06:38:50 +00:00
|
|
|
if o.PathPrefix != "" {
|
2015-06-15 10:50:53 +00:00
|
|
|
// If the prefix is missing for the root path, prepend it.
|
2015-06-03 06:38:50 +00:00
|
|
|
router.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
2015-06-15 10:50:53 +00:00
|
|
|
http.Redirect(w, r, o.PathPrefix, http.StatusFound)
|
2015-06-03 06:38:50 +00:00
|
|
|
})
|
|
|
|
router = router.WithPrefix(o.PathPrefix)
|
|
|
|
}
|
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
instrf := prometheus.InstrumentHandlerFunc
|
|
|
|
instrh := prometheus.InstrumentHandler
|
2015-06-03 06:38:50 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
router.Get("/", instrf("status", h.statush))
|
|
|
|
router.Get("/alerts", instrf("alerts", h.alerts))
|
|
|
|
router.Get("/graph", instrf("graph", h.graph))
|
2015-06-03 06:38:50 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
router.Get("/heap", instrf("heap", dumpHeap))
|
2015-06-03 06:38:50 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
router.Get(o.MetricsPath, prometheus.Handler().ServeHTTP)
|
2015-06-04 16:24:04 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
h.apiLegacy.Register(router.WithPrefix("/api"))
|
|
|
|
h.apiV1.Register(router.WithPrefix("/api/v1"))
|
2015-06-03 06:38:50 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
router.Get("/consoles/*filepath", instrf("consoles", h.consoles))
|
2015-06-03 06:38:50 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
if o.UseLocalAssets {
|
|
|
|
router.Get("/static/*filepath", instrf("static", route.FileServe("web/blob/static")))
|
2013-03-21 12:55:59 +00:00
|
|
|
} else {
|
2015-06-15 10:50:53 +00:00
|
|
|
router.Get("/static/*filepath", instrh("static", blob.Handler{}))
|
2013-03-21 12:55:59 +00:00
|
|
|
}
|
2013-02-08 13:49:55 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
if o.UserAssetsPath != "" {
|
|
|
|
router.Get("/user/*filepath", instrf("user", route.FileServe(o.UserAssetsPath)))
|
2013-05-23 13:47:00 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
if o.EnableQuit {
|
|
|
|
router.Post("/-/quit", h.quit)
|
2015-03-24 21:04:38 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
return h
|
|
|
|
}
|
|
|
|
|
|
|
|
// Quit returns the receive-only quit channel.
|
|
|
|
func (h *Handler) Quit() <-chan struct{} {
|
|
|
|
return h.quitCh
|
2015-06-02 11:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run serves the HTTP endpoints.
|
2015-06-15 10:50:53 +00:00
|
|
|
func (h *Handler) Run() {
|
|
|
|
log.Infof("Listening on %s", h.options.ListenAddress)
|
2013-05-05 17:32:04 +00:00
|
|
|
|
2015-05-19 12:38:50 +00:00
|
|
|
// If we cannot bind to a port, retry after 30 seconds.
|
|
|
|
for {
|
2015-06-15 10:50:53 +00:00
|
|
|
err := http.ListenAndServe(h.options.ListenAddress, h.router)
|
2015-05-19 12:38:50 +00:00
|
|
|
if err != nil {
|
2015-06-15 10:50:53 +00:00
|
|
|
log.Errorf("Could not listen on %s: %s", h.options.ListenAddress, err)
|
2015-05-19 12:38:50 +00:00
|
|
|
}
|
|
|
|
time.Sleep(30 * time.Second)
|
|
|
|
}
|
2013-02-08 13:49:55 +00:00
|
|
|
}
|
2013-03-27 16:40:01 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
func (h *Handler) alerts(w http.ResponseWriter, r *http.Request) {
|
|
|
|
h.muAlerts.Lock()
|
|
|
|
defer h.muAlerts.Unlock()
|
|
|
|
|
|
|
|
alerts := h.ruleManager.AlertingRules()
|
|
|
|
alertsSorter := byAlertStateSorter{alerts: alerts}
|
|
|
|
sort.Sort(alertsSorter)
|
|
|
|
|
|
|
|
alertStatus := AlertStatus{
|
|
|
|
AlertingRules: alertsSorter.alerts,
|
|
|
|
AlertStateToRowClass: map[rules.AlertState]string{
|
|
|
|
rules.StateInactive: "success",
|
|
|
|
rules.StatePending: "warning",
|
|
|
|
rules.StateFiring: "danger",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
h.executeTemplate(w, "alerts", alertStatus)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Handler) consoles(w http.ResponseWriter, r *http.Request) {
|
|
|
|
ctx := route.Context(r)
|
|
|
|
name := route.Param(ctx, "filepath")
|
|
|
|
|
|
|
|
file, err := http.Dir(h.options.ConsoleTemplatesPath).Open(name)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusNotFound)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
text, err := ioutil.ReadAll(file)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Provide URL parameters as a map for easy use. Advanced users may have need for
|
|
|
|
// parameters beyond the first, so provide RawParams.
|
|
|
|
rawParams, err := url.ParseQuery(r.URL.RawQuery)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
params := map[string]string{}
|
|
|
|
for k, v := range rawParams {
|
|
|
|
params[k] = v[0]
|
|
|
|
}
|
|
|
|
data := struct {
|
|
|
|
RawParams url.Values
|
|
|
|
Params map[string]string
|
|
|
|
Path string
|
|
|
|
}{
|
|
|
|
RawParams: rawParams,
|
|
|
|
Params: params,
|
|
|
|
Path: name,
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpl := template.NewTemplateExpander(string(text), "__console_"+name, data, clientmodel.Now(), h.queryEngine, h.options.PathPrefix)
|
|
|
|
filenames, err := filepath.Glob(h.options.ConsoleLibrariesPath + "/*.lib")
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
result, err := tmpl.ExpandHTML(filenames)
|
|
|
|
if err != nil {
|
|
|
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
io.WriteString(w, result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Handler) graph(w http.ResponseWriter, r *http.Request) {
|
|
|
|
h.executeTemplate(w, "graph", nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Handler) statush(w http.ResponseWriter, r *http.Request) {
|
|
|
|
h.status.mu.RLock()
|
|
|
|
defer h.status.mu.RUnlock()
|
|
|
|
|
2015-06-15 10:23:02 +00:00
|
|
|
h.executeTemplate(w, "status", struct {
|
|
|
|
Status *PrometheusStatus
|
|
|
|
Info map[string]string
|
|
|
|
}{
|
|
|
|
Status: h.status,
|
|
|
|
Info: version.Map,
|
|
|
|
})
|
2015-06-15 10:50:53 +00:00
|
|
|
}
|
2014-04-14 23:02:15 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
func (h *Handler) quit(w http.ResponseWriter, r *http.Request) {
|
|
|
|
fmt.Fprintf(w, "Requesting termination... Goodbye!")
|
|
|
|
close(h.quitCh)
|
2014-04-14 23:02:15 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
func (h *Handler) getTemplateFile(name string) (string, error) {
|
|
|
|
if h.options.UseLocalAssets {
|
2015-06-08 23:37:25 +00:00
|
|
|
file, err := ioutil.ReadFile(fmt.Sprintf("web/blob/templates/%s.html", name))
|
2014-07-29 16:28:48 +00:00
|
|
|
if err != nil {
|
2015-05-20 16:10:29 +00:00
|
|
|
log.Errorf("Could not read %s template: %s", name, err)
|
2014-07-29 16:28:48 +00:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(file), nil
|
|
|
|
}
|
2014-12-10 15:16:49 +00:00
|
|
|
file, err := blob.GetFile(blob.TemplateFiles, name+".html")
|
|
|
|
if err != nil {
|
2015-05-20 16:10:29 +00:00
|
|
|
log.Errorf("Could not read %s template: %s", name, err)
|
2014-12-10 15:16:49 +00:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
return string(file), nil
|
2013-06-07 09:17:17 +00:00
|
|
|
}
|
2013-03-27 16:40:01 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
func (h *Handler) getConsoles() string {
|
|
|
|
if _, err := os.Stat(h.options.ConsoleTemplatesPath + "/index.html"); !os.IsNotExist(err) {
|
|
|
|
return h.options.PathPrefix + "/consoles/index.html"
|
2014-10-02 14:44:47 +00:00
|
|
|
}
|
2015-06-15 10:50:53 +00:00
|
|
|
if h.options.UserAssetsPath != "" {
|
|
|
|
if _, err := os.Stat(h.options.UserAssetsPath + "/index.html"); !os.IsNotExist(err) {
|
|
|
|
return h.options.PathPrefix + "/user/index.html"
|
2014-10-02 14:44:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
func (h *Handler) getTemplate(name string) (*template_std.Template, error) {
|
|
|
|
t := template_std.New("_base")
|
2015-05-18 10:16:25 +00:00
|
|
|
var err error
|
2015-03-24 21:04:38 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
t.Funcs(template_std.FuncMap{
|
2014-10-02 14:44:47 +00:00
|
|
|
"since": time.Since,
|
2015-06-15 10:50:53 +00:00
|
|
|
"getConsoles": h.getConsoles,
|
|
|
|
"pathPrefix": func() string { return h.options.PathPrefix },
|
2015-05-18 10:16:25 +00:00
|
|
|
"stripLabels": func(lset clientmodel.LabelSet, labels ...clientmodel.LabelName) clientmodel.LabelSet {
|
|
|
|
for _, ln := range labels {
|
|
|
|
delete(lset, ln)
|
|
|
|
}
|
|
|
|
return lset
|
|
|
|
},
|
|
|
|
"globalURL": func(url string) string {
|
|
|
|
for _, localhostRepresentation := range localhostRepresentations {
|
2015-06-15 10:50:53 +00:00
|
|
|
url = strings.Replace(url, "//"+localhostRepresentation, "//"+h.options.Hostname, 1)
|
2015-05-18 10:16:25 +00:00
|
|
|
}
|
|
|
|
return url
|
|
|
|
},
|
2015-06-15 10:50:53 +00:00
|
|
|
"healthToClass": func(th retrieval.TargetHealth) string {
|
|
|
|
switch th {
|
|
|
|
case retrieval.HealthUnknown:
|
|
|
|
return "warning"
|
|
|
|
case retrieval.HealthGood:
|
|
|
|
return "success"
|
|
|
|
default:
|
|
|
|
return "danger"
|
|
|
|
}
|
|
|
|
},
|
2014-07-29 16:28:48 +00:00
|
|
|
})
|
2015-05-18 10:16:25 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
file, err := h.getTemplateFile("_base")
|
2013-03-27 16:40:01 +00:00
|
|
|
if err != nil {
|
2015-05-20 16:10:29 +00:00
|
|
|
log.Errorln("Could not read base template:", err)
|
2013-03-27 16:40:01 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2015-05-18 10:16:25 +00:00
|
|
|
t, err = t.Parse(file)
|
|
|
|
if err != nil {
|
2015-05-20 16:10:29 +00:00
|
|
|
log.Errorln("Could not parse base template:", err)
|
2015-05-18 10:16:25 +00:00
|
|
|
}
|
2013-03-27 16:40:01 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
file, err = h.getTemplateFile(name)
|
2013-03-27 16:40:01 +00:00
|
|
|
if err != nil {
|
2015-05-20 16:10:29 +00:00
|
|
|
log.Error("Could not read template %s: %s", name, err)
|
2013-03-27 16:40:01 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2015-05-18 10:16:25 +00:00
|
|
|
t, err = t.Parse(file)
|
|
|
|
if err != nil {
|
2015-05-20 16:10:29 +00:00
|
|
|
log.Errorf("Could not parse template %s: %s", name, err)
|
2015-05-18 10:16:25 +00:00
|
|
|
}
|
|
|
|
return t, err
|
2013-03-27 16:40:01 +00:00
|
|
|
}
|
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
func (h *Handler) executeTemplate(w http.ResponseWriter, name string, data interface{}) {
|
|
|
|
tpl, err := h.getTemplate(name)
|
2013-03-27 16:40:01 +00:00
|
|
|
if err != nil {
|
2015-05-20 16:10:29 +00:00
|
|
|
log.Error("Error preparing layout template: ", err)
|
2013-03-27 16:40:01 +00:00
|
|
|
return
|
|
|
|
}
|
2013-04-28 17:01:56 +00:00
|
|
|
err = tpl.Execute(w, data)
|
|
|
|
if err != nil {
|
2015-05-20 16:10:29 +00:00
|
|
|
log.Error("Error executing template: ", err)
|
2013-04-28 17:01:56 +00:00
|
|
|
}
|
2013-03-27 16:40:01 +00:00
|
|
|
}
|
2013-08-09 16:09:44 +00:00
|
|
|
|
2013-08-29 13:15:22 +00:00
|
|
|
func dumpHeap(w http.ResponseWriter, r *http.Request) {
|
|
|
|
target := fmt.Sprintf("/tmp/%d.heap", time.Now().Unix())
|
|
|
|
f, err := os.Create(target)
|
|
|
|
if err != nil {
|
2015-05-20 16:10:29 +00:00
|
|
|
log.Error("Could not dump heap: ", err)
|
2013-08-29 13:15:22 +00:00
|
|
|
}
|
|
|
|
fmt.Fprintf(w, "Writing to %s...", target)
|
|
|
|
defer f.Close()
|
|
|
|
pprof_runtime.WriteHeapProfile(f)
|
|
|
|
fmt.Fprintf(w, "Done")
|
|
|
|
}
|
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
// AlertStatus bundles alerting rules and the mapping of alert states to row classes.
|
|
|
|
type AlertStatus struct {
|
|
|
|
AlertingRules []*rules.AlertingRule
|
|
|
|
AlertStateToRowClass map[rules.AlertState]string
|
2013-08-09 16:09:44 +00:00
|
|
|
}
|
2015-05-22 10:29:33 +00:00
|
|
|
|
2015-06-15 10:50:53 +00:00
|
|
|
type byAlertStateSorter struct {
|
|
|
|
alerts []*rules.AlertingRule
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s byAlertStateSorter) Len() int {
|
|
|
|
return len(s.alerts)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s byAlertStateSorter) Less(i, j int) bool {
|
|
|
|
return s.alerts[i].State() > s.alerts[j].State()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s byAlertStateSorter) Swap(i, j int) {
|
|
|
|
s.alerts[i], s.alerts[j] = s.alerts[j], s.alerts[i]
|
2015-05-22 10:29:33 +00:00
|
|
|
}
|