mirror of
https://github.com/prometheus/prometheus
synced 2024-12-26 00:23:18 +00:00
web: expose a version information endpoint
This commit is contained in:
parent
39edc2df7a
commit
119801027f
23
web/web.go
23
web/web.go
@ -14,6 +14,7 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@ -59,7 +60,7 @@ type Handler struct {
|
||||
router *route.Router
|
||||
quitCh chan struct{}
|
||||
options *Options
|
||||
status *PrometheusStatus
|
||||
statusInfo *PrometheusStatus
|
||||
|
||||
muAlerts sync.Mutex
|
||||
}
|
||||
@ -110,7 +111,7 @@ func New(st local.Storage, qe *promql.Engine, rm *rules.Manager, status *Prometh
|
||||
router: router,
|
||||
quitCh: make(chan struct{}),
|
||||
options: o,
|
||||
status: status,
|
||||
statusInfo: status,
|
||||
|
||||
ruleManager: rm,
|
||||
queryEngine: qe,
|
||||
@ -137,9 +138,10 @@ func New(st local.Storage, qe *promql.Engine, rm *rules.Manager, status *Prometh
|
||||
instrf := prometheus.InstrumentHandlerFunc
|
||||
instrh := prometheus.InstrumentHandler
|
||||
|
||||
router.Get("/", instrf("status", h.statush))
|
||||
router.Get("/", instrf("status", h.status))
|
||||
router.Get("/alerts", instrf("alerts", h.alerts))
|
||||
router.Get("/graph", instrf("graph", h.graph))
|
||||
router.Get("/version", instrf("version", h.version))
|
||||
|
||||
router.Get("/heap", instrf("heap", dumpHeap))
|
||||
|
||||
@ -259,19 +261,26 @@ 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()
|
||||
func (h *Handler) status(w http.ResponseWriter, r *http.Request) {
|
||||
h.statusInfo.mu.RLock()
|
||||
defer h.statusInfo.mu.RUnlock()
|
||||
|
||||
h.executeTemplate(w, "status", struct {
|
||||
Status *PrometheusStatus
|
||||
Info map[string]string
|
||||
}{
|
||||
Status: h.status,
|
||||
Status: h.statusInfo,
|
||||
Info: version.Map,
|
||||
})
|
||||
}
|
||||
|
||||
func (h *Handler) version(w http.ResponseWriter, r *http.Request) {
|
||||
dec := json.NewEncoder(w)
|
||||
if err := dec.Encode(version.Map); err != nil {
|
||||
http.Error(w, fmt.Sprintf("error encoding JSON: %s", err), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func (h *Handler) quit(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Requesting termination... Goodbye!")
|
||||
close(h.quitCh)
|
||||
|
Loading…
Reference in New Issue
Block a user