mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Add flag to read assets from local files.
This commit is contained in:
parent
1f80b17cb7
commit
bf5d312a74
|
@ -40,11 +40,18 @@ func (h *StatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
Status: "TODO: add status information here",
|
Status: "TODO: add status information here",
|
||||||
TargetPools: h.appState.TargetManager.Pools(),
|
TargetPools: h.appState.TargetManager.Pools(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var t *template.Template
|
||||||
|
if *localAssets {
|
||||||
|
t, _ = template.ParseFiles("web/templates/status.html")
|
||||||
|
} else {
|
||||||
templateFile, err := blob.GetFile(blob.TemplateFiles, "status.html")
|
templateFile, err := blob.GetFile(blob.TemplateFiles, "status.html")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Could not read template: %s", err)
|
log.Fatalf("Could not read template: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t, _ := template.New("status").Parse(string(templateFile))
|
t, _ = template.New("status").Parse(string(templateFile))
|
||||||
|
}
|
||||||
|
|
||||||
t.Execute(w, status)
|
t.Execute(w, status)
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ import (
|
||||||
// Commandline flags.
|
// Commandline flags.
|
||||||
var (
|
var (
|
||||||
listenAddress = flag.String("listenAddress", ":9090", "Address to listen on for web interface.")
|
listenAddress = flag.String("listenAddress", ":9090", "Address to listen on for web interface.")
|
||||||
|
localAssets = flag.Bool("localAssets", false, "Read assets/templates from file instead of binary.")
|
||||||
)
|
)
|
||||||
|
|
||||||
func StartServing(appState *appstate.ApplicationState) {
|
func StartServing(appState *appstate.ApplicationState) {
|
||||||
|
@ -36,7 +37,11 @@ func StartServing(appState *appstate.ApplicationState) {
|
||||||
http.Handle("/status", &StatusHandler{appState: appState})
|
http.Handle("/status", &StatusHandler{appState: appState})
|
||||||
http.Handle("/api/", gorest.Handle())
|
http.Handle("/api/", gorest.Handle())
|
||||||
http.Handle("/metrics.json", exporter)
|
http.Handle("/metrics.json", exporter)
|
||||||
|
if *localAssets {
|
||||||
|
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static"))))
|
||||||
|
} else {
|
||||||
http.Handle("/static/", http.StripPrefix("/static/", new(blob.Handler)))
|
http.Handle("/static/", http.StripPrefix("/static/", new(blob.Handler)))
|
||||||
|
}
|
||||||
|
|
||||||
go http.ListenAndServe(*listenAddress, nil)
|
go http.ListenAndServe(*listenAddress, nil)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue