diff --git a/web/handler.go b/web/handler.go
new file mode 100644
index 000000000..75b411eb7
--- /dev/null
+++ b/web/handler.go
@@ -0,0 +1,26 @@
+// Copyright 2013 Prometheus Team
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package web
+
+import (
+ "net/http"
+)
+
+func graphHandler(w http.ResponseWriter, r *http.Request) {
+ executeTemplate(w, "graph", nil)
+}
+
+func consoleHandler(w http.ResponseWriter, r *http.Request) {
+ executeTemplate(w, "console", nil)
+}
diff --git a/web/static/css/prometheus.css b/web/static/css/prometheus.css
index 96a8ca84b..da245fd77 100644
--- a/web/static/css/prometheus.css
+++ b/web/static/css/prometheus.css
@@ -2,8 +2,8 @@ body {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 14px;
line-height: 20px;
- color: #333333;
- background-color: #eee;
+ color: #333;
+ background-color: #f2f2f2;
margin: 0px;
padding: 0px;
}
@@ -49,3 +49,15 @@ input[name=end_input], input[name=range_input] {
margin-left: -4px;
margin-right: -4px;
}
+
+#navigation {
+ font-size: 20pt;
+ background-color: #333;
+ color: #F2F2F2;
+ line-height: 120%;
+}
+
+#navigation a { padding-right: 1em; text-decoration: none }
+#navigation a:visited { color: #F2F2F2 }
+#navigation a:active { color: #F60 }
+#navigation a:hover { color: #06C }
diff --git a/web/static/graph.html b/web/static/graph.html
deleted file mode 100644
index ca2ad0eda..000000000
--- a/web/static/graph.html
+++ /dev/null
@@ -1,79 +0,0 @@
-
-
-
-
- Prometheus Expression Browser
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/web/static/js/graph.js b/web/static/js/graph.js
index e2bc92fce..4a6163d85 100644
--- a/web/static/js/graph.js
+++ b/web/static/js/graph.js
@@ -20,6 +20,7 @@
var Prometheus = Prometheus || {};
var graphs = [];
+var graphTemplate;
Prometheus.Graph = function(element, options) {
this.el = element;
@@ -57,9 +58,8 @@ Prometheus.Graph.prototype.initialize = function() {
self.options['stacked_checked'] = self.options['stacked'] ? "checked" : "";
// Draw graph controls and container from Handlebars template.
- var source = $("#graph_template").html();
- var template = Handlebars.compile(source);
- var graphHtml = template(self.options);
+
+ var graphHtml = graphTemplate(self.options);
self.el.append(graphHtml);
// Get references to all the interesting elements in the graph container and
@@ -428,15 +428,20 @@ function init() {
cache: false
});
- var options = parseGraphOptionsFromUrl();
- if (options.length == 0) {
- options.push({});
- }
- for (var i = 0; i < options.length; i++) {
- addGraph(options[i]);
- }
-
- $("#add_graph").click(function() { addGraph({}); });
+ $.ajax({
+ url: "/static/js/graph_template.handlebar",
+ success: function(data) {
+ graphTemplate = Handlebars.compile(data);
+ var options = parseGraphOptionsFromUrl();
+ if (options.length == 0) {
+ options.push({});
+ }
+ for (var i = 0; i < options.length; i++) {
+ addGraph(options[i]);
+ }
+ $("#add_graph").click(function() { addGraph({}); });
+ }
+ })
}
$(init);
diff --git a/web/static/js/graph_template.handlebar b/web/static/js/graph_template.handlebar
new file mode 100644
index 000000000..e24277197
--- /dev/null
+++ b/web/static/js/graph_template.handlebar
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+
diff --git a/web/status.go b/web/status.go
index 07f310b3d..2874fe9d7 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 000000000..79c1b23f8
--- /dev/null
+++ b/web/templates/_base.html
@@ -0,0 +1,19 @@
+
+
+
+
+ Prometheus
+
+
+ {{template "head" .}}
+
+
+
+
+ {{template "content" .}}
+
+
diff --git a/web/static/index.html b/web/templates/console.html
similarity index 55%
rename from web/static/index.html
rename to web/templates/console.html
index df6e32cfa..c97356e01 100644
--- a/web/static/index.html
+++ b/web/templates/console.html
@@ -1,15 +1,8 @@
-
-
-
-
- Prometheus Expression Browser
-
-
-
+{{define "head"}}
-
+{{end}}
-
+{{define "content"}}
-
-
+{{end}}
diff --git a/web/templates/graph.html b/web/templates/graph.html
new file mode 100644
index 000000000..2181bb0ca
--- /dev/null
+++ b/web/templates/graph.html
@@ -0,0 +1,30 @@
+{{define "head"}}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+{{end}}
+
+{{define "content"}}
+
+
+
+{{end}}
diff --git a/web/templates/status.html b/web/templates/status.html
index 62712d5c2..722d9dc4a 100644
--- a/web/templates/status.html
+++ b/web/templates/status.html
@@ -1,14 +1,7 @@
-
-
-
-
- Prometheus Status
-
-
-
+{{define "head"}}{{end}}
-
- Status
+{{define "content"}}
+ Status
{{.Status}}
@@ -41,5 +34,4 @@
{{end}}
-
-
+{{end}}
diff --git a/web/web.go b/web/web.go
index f754a5b96..2a25f9d9c 100644
--- a/web/web.go
+++ b/web/web.go
@@ -16,10 +16,14 @@ package web
import (
"code.google.com/p/gorest"
"flag"
+ "fmt"
"github.com/prometheus/client_golang"
+ "github.com/prometheus/client_golang/exp"
"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"
)
@@ -33,14 +37,50 @@ var (
func StartServing(appState *appstate.ApplicationState) {
gorest.RegisterService(api.NewMetricsService(appState))
- http.Handle("/status", &StatusHandler{appState: appState})
- http.Handle("/api/", gorest.Handle())
- http.Handle("/metrics.json", registry.DefaultHandler)
+ exp.Handle("/", &StatusHandler{appState: appState})
+ exp.HandleFunc("/graph", graphHandler)
+ exp.HandleFunc("/console", consoleHandler)
+
+ exp.Handle("/api/", gorest.Handle())
+ exp.Handle("/metrics.json", registry.DefaultHandler)
if *useLocalAssets {
- http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static"))))
+ exp.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static"))))
} else {
- http.Handle("/static/", http.StripPrefix("/static/", new(blob.Handler)))
+ exp.Handle("/static/", http.StripPrefix("/static/", new(blob.Handler)))
}
- go http.ListenAndServe(*listenAddress, nil)
+ go http.ListenAndServe(*listenAddress, exp.DefaultCoarseMux)
+}
+
+func getTemplate(name string) (t *template.Template, err error) {
+ if *useLocalAssets {
+ return template.ParseFiles("web/templates/_base.html", fmt.Sprintf("web/templates/%s.html", name))
+ }
+
+ 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("Error preparing layout template: %s", err)
+ return
+ }
+ tpl.Execute(w, data)
}