Beginnings of a Prometheus status page.

This commit is contained in:
Julius Volz 2013-02-12 13:15:40 +01:00
parent c3d31febd6
commit 23374788d3
10 changed files with 146 additions and 29 deletions

28
appstate/appstate.go Normal file
View file

@ -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
}

10
main.go
View file

@ -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 {

View file

@ -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,
}
}

23
web/static/css/graph.css Normal file
View file

@ -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-
}

View file

@ -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;

View file

@ -6,6 +6,7 @@
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.15/jquery-ui.min.js"></script>
<link type="text/css" rel="stylesheet" href="css/prometheus.css">
<link type="text/css" rel="stylesheet" href="css/graph.css">
<!-- copy all these CSSen/JSen to our own location -->
<link type="text/css" rel="stylesheet" href="http://code.shutterstock.com/rickshaw/rickshaw.min.css">

View file

@ -4,6 +4,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Prometheus Expression Browser</title>
<link type="text/css" rel="stylesheet" href="css/prometheus.css">
<link type="text/css" rel="stylesheet" href="css/graph.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="js/exprBrowser.js"></script>
</head>

42
web/status.go Normal file
View file

@ -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)
}

33
web/templates/status.html Normal file
View file

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<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">
{{.Status}}
</div>
<h2>Configuration</h2>
<div class="grouping_box">
<pre>
{{.Config}}
</pre>
</div>
<h2>Rules</h2>
<div class="grouping_box">
{{.Rules}}
</div>
<h2>Targets</h2>
<div class="grouping_box">
{{.Targets}}
</div>
</body>
</html>

View file

@ -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)