mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
web: expose a version information endpoint
This commit is contained in:
parent
39edc2df7a
commit
119801027f
35
web/web.go
35
web/web.go
|
@ -14,6 +14,7 @@
|
||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -56,10 +57,10 @@ type Handler struct {
|
||||||
apiV1 *v1.API
|
apiV1 *v1.API
|
||||||
apiLegacy *legacy.API
|
apiLegacy *legacy.API
|
||||||
|
|
||||||
router *route.Router
|
router *route.Router
|
||||||
quitCh chan struct{}
|
quitCh chan struct{}
|
||||||
options *Options
|
options *Options
|
||||||
status *PrometheusStatus
|
statusInfo *PrometheusStatus
|
||||||
|
|
||||||
muAlerts sync.Mutex
|
muAlerts sync.Mutex
|
||||||
}
|
}
|
||||||
|
@ -107,10 +108,10 @@ func New(st local.Storage, qe *promql.Engine, rm *rules.Manager, status *Prometh
|
||||||
router := route.New()
|
router := route.New()
|
||||||
|
|
||||||
h := &Handler{
|
h := &Handler{
|
||||||
router: router,
|
router: router,
|
||||||
quitCh: make(chan struct{}),
|
quitCh: make(chan struct{}),
|
||||||
options: o,
|
options: o,
|
||||||
status: status,
|
statusInfo: status,
|
||||||
|
|
||||||
ruleManager: rm,
|
ruleManager: rm,
|
||||||
queryEngine: qe,
|
queryEngine: qe,
|
||||||
|
@ -137,9 +138,10 @@ func New(st local.Storage, qe *promql.Engine, rm *rules.Manager, status *Prometh
|
||||||
instrf := prometheus.InstrumentHandlerFunc
|
instrf := prometheus.InstrumentHandlerFunc
|
||||||
instrh := prometheus.InstrumentHandler
|
instrh := prometheus.InstrumentHandler
|
||||||
|
|
||||||
router.Get("/", instrf("status", h.statush))
|
router.Get("/", instrf("status", h.status))
|
||||||
router.Get("/alerts", instrf("alerts", h.alerts))
|
router.Get("/alerts", instrf("alerts", h.alerts))
|
||||||
router.Get("/graph", instrf("graph", h.graph))
|
router.Get("/graph", instrf("graph", h.graph))
|
||||||
|
router.Get("/version", instrf("version", h.version))
|
||||||
|
|
||||||
router.Get("/heap", instrf("heap", dumpHeap))
|
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)
|
h.executeTemplate(w, "graph", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) statush(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) status(w http.ResponseWriter, r *http.Request) {
|
||||||
h.status.mu.RLock()
|
h.statusInfo.mu.RLock()
|
||||||
defer h.status.mu.RUnlock()
|
defer h.statusInfo.mu.RUnlock()
|
||||||
|
|
||||||
h.executeTemplate(w, "status", struct {
|
h.executeTemplate(w, "status", struct {
|
||||||
Status *PrometheusStatus
|
Status *PrometheusStatus
|
||||||
Info map[string]string
|
Info map[string]string
|
||||||
}{
|
}{
|
||||||
Status: h.status,
|
Status: h.statusInfo,
|
||||||
Info: version.Map,
|
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) {
|
func (h *Handler) quit(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintf(w, "Requesting termination... Goodbye!")
|
fmt.Fprintf(w, "Requesting termination... Goodbye!")
|
||||||
close(h.quitCh)
|
close(h.quitCh)
|
||||||
|
|
Loading…
Reference in a new issue