mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-10 15:44:05 -08:00
Merge pull request #976 from JanBerktold/web_reload
Allow reloading via webhandler
This commit is contained in:
commit
3c941b9e81
|
@ -104,7 +104,11 @@ func Main() int {
|
||||||
signal.Notify(hup, syscall.SIGHUP)
|
signal.Notify(hup, syscall.SIGHUP)
|
||||||
go func() {
|
go func() {
|
||||||
<-hupReady
|
<-hupReady
|
||||||
for range hup {
|
for {
|
||||||
|
select {
|
||||||
|
case <-hup:
|
||||||
|
case <-webHandler.Reload():
|
||||||
|
}
|
||||||
reloadConfig(cfg.configFile, status, targetManager, ruleManager)
|
reloadConfig(cfg.configFile, status, targetManager, ruleManager)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
12
web/web.go
12
web/web.go
|
@ -61,6 +61,7 @@ type Handler struct {
|
||||||
|
|
||||||
router *route.Router
|
router *route.Router
|
||||||
quitCh chan struct{}
|
quitCh chan struct{}
|
||||||
|
reloadCh chan struct{}
|
||||||
options *Options
|
options *Options
|
||||||
statusInfo *PrometheusStatus
|
statusInfo *PrometheusStatus
|
||||||
|
|
||||||
|
@ -111,6 +112,7 @@ func New(st local.Storage, qe *promql.Engine, rm *rules.Manager, status *Prometh
|
||||||
h := &Handler{
|
h := &Handler{
|
||||||
router: router,
|
router: router,
|
||||||
quitCh: make(chan struct{}),
|
quitCh: make(chan struct{}),
|
||||||
|
reloadCh: make(chan struct{}),
|
||||||
options: o,
|
options: o,
|
||||||
statusInfo: status,
|
statusInfo: status,
|
||||||
|
|
||||||
|
@ -171,6 +173,7 @@ func New(st local.Storage, qe *promql.Engine, rm *rules.Manager, status *Prometh
|
||||||
router.Post("/-/quit", h.quit)
|
router.Post("/-/quit", h.quit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
router.Post("/-/reload", h.reload)
|
||||||
router.Get("/debug/*subpath", http.DefaultServeMux.ServeHTTP)
|
router.Get("/debug/*subpath", http.DefaultServeMux.ServeHTTP)
|
||||||
|
|
||||||
return h
|
return h
|
||||||
|
@ -181,6 +184,10 @@ func (h *Handler) Quit() <-chan struct{} {
|
||||||
return h.quitCh
|
return h.quitCh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) Reload() <-chan struct{} {
|
||||||
|
return h.reloadCh
|
||||||
|
}
|
||||||
|
|
||||||
// Run serves the HTTP endpoints.
|
// Run serves the HTTP endpoints.
|
||||||
func (h *Handler) Run() {
|
func (h *Handler) Run() {
|
||||||
log.Infof("Listening on %s", h.options.ListenAddress)
|
log.Infof("Listening on %s", h.options.ListenAddress)
|
||||||
|
@ -293,6 +300,11 @@ func (h *Handler) quit(w http.ResponseWriter, r *http.Request) {
|
||||||
close(h.quitCh)
|
close(h.quitCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *Handler) reload(w http.ResponseWriter, r *http.Request) {
|
||||||
|
fmt.Fprintf(w, "Reloading configuration file...")
|
||||||
|
h.reloadCh <- struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
func (h *Handler) getTemplateFile(name string) (string, error) {
|
func (h *Handler) getTemplateFile(name string) (string, error) {
|
||||||
if h.options.UseLocalAssets {
|
if h.options.UseLocalAssets {
|
||||||
file, err := ioutil.ReadFile(fmt.Sprintf("web/blob/templates/%s.html", name))
|
file, err := ioutil.ReadFile(fmt.Sprintf("web/blob/templates/%s.html", name))
|
||||||
|
|
Loading…
Reference in a new issue