Split status template into two templates.
This is now using a base template (_base.html) for the 'layout' of the web UI. Within that base template, the actual content templates get rendered.
This commit is contained in:
parent
a4f0578a7e
commit
f27adac848
|
@ -16,9 +16,6 @@ package web
|
||||||
import (
|
import (
|
||||||
"github.com/prometheus/prometheus/appstate"
|
"github.com/prometheus/prometheus/appstate"
|
||||||
"github.com/prometheus/prometheus/retrieval"
|
"github.com/prometheus/prometheus/retrieval"
|
||||||
"github.com/prometheus/prometheus/web/blob"
|
|
||||||
"html/template"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,18 +37,5 @@ 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(),
|
||||||
}
|
}
|
||||||
|
executeTemplate(w, "status", status)
|
||||||
var t *template.Template
|
|
||||||
if *useLocalAssets {
|
|
||||||
t, _ = template.ParseFiles("web/templates/status.html")
|
|
||||||
} else {
|
|
||||||
templateFile, err := blob.GetFile(blob.TemplateFiles, "status.html")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Could not read template: %s", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
t, _ = template.New("status").Parse(string(templateFile))
|
|
||||||
}
|
|
||||||
|
|
||||||
t.Execute(w, status)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||||
|
<title>Prometheus</title>
|
||||||
|
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
|
||||||
|
<link type="text/css" rel="stylesheet" href="static/css/prometheus.css">
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
{{template "content" .}}
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1,14 +1,5 @@
|
||||||
<!DOCTYPE html>
|
{{define "content"}}
|
||||||
<html lang="en">
|
<h2>Status</h2>
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
||||||
<title>Prometheus Status</title>
|
|
||||||
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
|
|
||||||
<link type="text/css" rel="stylesheet" href="static/css/prometheus.css">
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<h2>Status</h2>
|
|
||||||
<div class="grouping_box">
|
<div class="grouping_box">
|
||||||
{{.Status}}
|
{{.Status}}
|
||||||
</div>
|
</div>
|
||||||
|
@ -41,5 +32,4 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
{{end}}
|
||||||
</html>
|
|
||||||
|
|
35
web/web.go
35
web/web.go
|
@ -20,6 +20,8 @@ import (
|
||||||
"github.com/prometheus/prometheus/appstate"
|
"github.com/prometheus/prometheus/appstate"
|
||||||
"github.com/prometheus/prometheus/web/api"
|
"github.com/prometheus/prometheus/web/api"
|
||||||
"github.com/prometheus/prometheus/web/blob"
|
"github.com/prometheus/prometheus/web/blob"
|
||||||
|
"html/template"
|
||||||
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
)
|
)
|
||||||
|
@ -45,3 +47,36 @@ func StartServing(appState *appstate.ApplicationState) {
|
||||||
|
|
||||||
go http.ListenAndServe(*listenAddress, nil)
|
go http.ListenAndServe(*listenAddress, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTemplate(name string) (t *template.Template, err error) {
|
||||||
|
if *useLocalAssets {
|
||||||
|
return template.ParseFiles("web/templates/_base.html", "web/templates/"+name+".html")
|
||||||
|
}
|
||||||
|
|
||||||
|
t = template.New("_base")
|
||||||
|
|
||||||
|
file, err := blob.GetFile(blob.TemplateFiles, "_base.html")
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Could not read base template: %s", err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
t.Parse(string(file))
|
||||||
|
|
||||||
|
file, err = blob.GetFile(blob.TemplateFiles, name+".html")
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Could not read %s template: %s", name, err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
t.Parse(string(file))
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func executeTemplate(w http.ResponseWriter, name string, data interface{}) {
|
||||||
|
tpl, err := getTemplate(name)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Errror preparing layout template: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tpl.Execute(w, data)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue