diff --git a/appstate/appstate.go b/appstate/appstate.go new file mode 100644 index 000000000..2435629a8 --- /dev/null +++ b/appstate/appstate.go @@ -0,0 +1,28 @@ +// 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 appstate + +import ( + "github.com/prometheus/prometheus/config" + "github.com/prometheus/prometheus/retrieval" + "github.com/prometheus/prometheus/rules" + "github.com/prometheus/prometheus/storage/metric" +) + +type ApplicationState struct { + Config *config.Config + RuleManager rules.RuleManager + Persistence metric.MetricPersistence + TargetManager retrieval.TargetManager +} diff --git a/main.go b/main.go index 39af0be2f..35f6b7600 100644 --- a/main.go +++ b/main.go @@ -15,6 +15,7 @@ package main import ( "flag" + "github.com/prometheus/prometheus/appstate" "github.com/prometheus/prometheus/config" "github.com/prometheus/prometheus/retrieval" "github.com/prometheus/prometheus/retrieval/format" @@ -73,7 +74,14 @@ func main() { log.Fatalf("Error loading rule files: %v", err) } - web.StartServing(persistence) + appState := &appstate.ApplicationState{ + Config: conf, + RuleManager: ruleManager, + Persistence: persistence, + TargetManager: targetManager, + } + + web.StartServing(appState) for { select { diff --git a/web/api/api.go b/web/api/api.go index 7aa4e891a..7c7b6155a 100644 --- a/web/api/api.go +++ b/web/api/api.go @@ -17,8 +17,8 @@ type MetricsService struct { time utility.Time } -func NewMetricsService(p metric.MetricPersistence) *MetricsService { +func NewMetricsService(persistence metric.MetricPersistence) *MetricsService { return &MetricsService{ - persistence: p, + persistence: persistence, } } diff --git a/web/static/css/graph.css b/web/static/css/graph.css new file mode 100644 index 000000000..5a84cbaab --- /dev/null +++ b/web/static/css/graph.css @@ -0,0 +1,23 @@ +body { + margin: 0; +} + +.graph_container { + font-family: Arial, Helvetica, sans-serif; +} + +.graph { + position: relative; +} + +svg { + border: 1px solid #aaa; + margin-bottom: 5px; +} + +.legend { + display: inline-block; + vertical-align: top; + margin: 0 0 0 0px; + background- +} diff --git a/web/static/css/prometheus.css b/web/static/css/prometheus.css index 52979a4c4..2a563b085 100644 --- a/web/static/css/prometheus.css +++ b/web/static/css/prometheus.css @@ -1,5 +1,4 @@ body { - margin: 0; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 14px; line-height: 20px; @@ -7,26 +6,6 @@ body { background-color: #eee; } -.graph_container { - font-family: Arial, Helvetica, sans-serif; -} - -.graph { - position: relative; -} - -svg { - border: 1px solid #aaa; - margin-bottom: 5px; -} - -.legend { - display: inline-block; - vertical-align: top; - margin: 0 0 0 0px; - background- -} - input:not([type=submit]):not([type=file]):not([type=button]) { border: 1px solid #aaa; -webkit-border-radius: 3px; diff --git a/web/static/graph.html b/web/static/graph.html index 2d64d9e6a..592f5a3c5 100644 --- a/web/static/graph.html +++ b/web/static/graph.html @@ -6,6 +6,7 @@ + diff --git a/web/static/index.html b/web/static/index.html index ce04c7bd4..df6e32cfa 100644 --- a/web/static/index.html +++ b/web/static/index.html @@ -4,6 +4,7 @@ Prometheus Expression Browser + diff --git a/web/status.go b/web/status.go new file mode 100644 index 000000000..a0403b0e4 --- /dev/null +++ b/web/status.go @@ -0,0 +1,42 @@ +// 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 ( + "github.com/prometheus/prometheus/appstate" + "html/template" + "net/http" +) + +type PrometheusStatus struct { + Status string + Config string + Rules string + Targets string +} + +type StatusHandler struct { + appState *appstate.ApplicationState +} + +func (h *StatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + status := &PrometheusStatus{ + Status: "TODO: add status information here", + Config: h.appState.Config.ToString(0), + Rules: "TODO: list rules here", + Targets: "TODO: list targets here", + } + t, _ := template.ParseFiles("web/templates/status.html") + t.Execute(w, status) +} diff --git a/web/templates/status.html b/web/templates/status.html new file mode 100644 index 000000000..8820846d7 --- /dev/null +++ b/web/templates/status.html @@ -0,0 +1,33 @@ + + + + + Prometheus Status + + + + + +

Status

+
+{{.Status}} +
+ +

Configuration

+
+
+{{.Config}}
+		
+
+ +

Rules

+
+{{.Rules}} +
+ +

Targets

+
+{{.Targets}} +
+ + diff --git a/web/web.go b/web/web.go index 021391fbe..50907dbd5 100644 --- a/web/web.go +++ b/web/web.go @@ -17,7 +17,7 @@ import ( "code.google.com/p/gorest" "flag" "github.com/prometheus/client_golang" - "github.com/prometheus/prometheus/storage/metric" + "github.com/prometheus/prometheus/appstate" "github.com/prometheus/prometheus/web/api" "net/http" _ "net/http/pprof" @@ -28,11 +28,13 @@ var ( listenAddress = flag.String("listenAddress", ":9090", "Address to listen on for web interface.") ) -func StartServing(persistence metric.MetricPersistence) { - gorest.RegisterService(api.NewMetricsService(persistence)) +func StartServing(appState *appstate.ApplicationState) { + gorest.RegisterService(api.NewMetricsService(appState.Persistence)) + exporter := registry.DefaultRegistry.YieldExporter() - http.Handle("/", gorest.Handle()) - http.Handle("/metrics.json", registry.DefaultHandler) + http.Handle("/status", &StatusHandler{appState: appState}) + http.Handle("/api/", gorest.Handle()) + http.Handle("/metrics.json", exporter) http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("web/static")))) go http.ListenAndServe(*listenAddress, nil)