diff --git a/web/status.go b/web/status.go
index 07f310b3d4..2874fe9d77 100644
--- a/web/status.go
+++ b/web/status.go
@@ -16,9 +16,6 @@ package web
import (
"github.com/prometheus/prometheus/appstate"
"github.com/prometheus/prometheus/retrieval"
- "github.com/prometheus/prometheus/web/blob"
- "html/template"
- "log"
"net/http"
)
@@ -40,18 +37,5 @@ func (h *StatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Status: "TODO: add status information here",
TargetPools: h.appState.TargetManager.Pools(),
}
-
- 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)
+ executeTemplate(w, "status", status)
}
diff --git a/web/templates/_base.html b/web/templates/_base.html
new file mode 100644
index 0000000000..02f80d2344
--- /dev/null
+++ b/web/templates/_base.html
@@ -0,0 +1,13 @@
+
+
+
+
+ Prometheus
+
+
+
+
+
+ {{template "content" .}}
+
+
diff --git a/web/templates/status.html b/web/templates/status.html
index 62712d5c24..a7602dab43 100644
--- a/web/templates/status.html
+++ b/web/templates/status.html
@@ -1,14 +1,5 @@
-
-
-
-
- Prometheus Status
-
-
-
-
-
- Status
+{{define "content"}}
+ Status
{{.Status}}
@@ -41,5 +32,4 @@
{{end}}
-
-
+{{end}}
diff --git a/web/web.go b/web/web.go
index e3672a707e..6c9b55e2d7 100644
--- a/web/web.go
+++ b/web/web.go
@@ -20,6 +20,8 @@ import (
"github.com/prometheus/prometheus/appstate"
"github.com/prometheus/prometheus/web/api"
"github.com/prometheus/prometheus/web/blob"
+ "html/template"
+ "log"
"net/http"
_ "net/http/pprof"
)
@@ -45,3 +47,36 @@ func StartServing(appState *appstate.ApplicationState) {
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)
+}