Merge pull request #189 from prometheus/feature/build-info-and-startup-friendliness

Build info and startup friendliness
This commit is contained in:
juliusv 2013-04-26 05:45:34 -07:00
commit 169a7dc26c
8 changed files with 132 additions and 13 deletions

View file

@ -17,16 +17,30 @@ TEST_ARTIFACTS = prometheus prometheus.build search_index
include Makefile.INCLUDE
REV := $(shell git rev-parse --short HEAD)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
HOSTNAME := $(shell hostname -f)
BUILD_DATE := $(shell date +%Y%m%d-%H:%M:%S)
BUILDFLAGS := -ldflags \
" -X main.buildVersion $(REV)\
-X main.buildBranch $(BRANCH)\
-X main.buildUser $(USER)@$(HOSTNAME)\
-X main.buildDate $(BUILD_DATE)\
-X main.goVersion $(GO_VERSION)\
-X main.leveldbVersion $(LEVELDB_VERSION)\
-X main.protobufVersion $(PROTOCOL_BUFFERS_VERSION)\
-X main.snappyVersion $(SNAPPY_VERSION)"
all: test
advice:
go tool vet .
binary: build
go build -o prometheus.build
go build $(BUILDFLAGS) -o prometheus.build
build: preparation model web
go build .
go build $(BUILDFLAGS) .
clean:
$(MAKE) -C build clean

View file

@ -28,4 +28,5 @@ type ApplicationState struct {
RuleManager rules.RuleManager
Storage metric.Storage
TargetManager retrieval.TargetManager
BuildInfo map[string]string
}

51
build_info.go Normal file
View file

@ -0,0 +1,51 @@
// 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 main
import (
"text/template"
)
// Build information. Populated by Makefile.
var (
buildVersion string
buildBranch string
buildUser string
buildDate string
goVersion string
leveldbVersion string
protobufVersion string
snappyVersion string
)
var BuildInfo = map[string]string{
"version": buildVersion,
"branch": buildBranch,
"user": buildUser,
"date": buildDate,
"go_version": goVersion,
"leveldb_version": leveldbVersion,
"protobuf_version": protobufVersion,
"snappy_version": snappyVersion,
}
var versionInfoTmpl = template.Must(template.New("version").Parse(
`prometheus, version {{.version}} ({{.branch}})
build user: {{.user}}
build date: {{.date}}
go version: {{.go_version}}
leveldb version: {{.leveldb_version}}
protobuf version: {{.protobuf_version}}
snappy version: {{.snappy_version}}
`))

View file

@ -34,6 +34,7 @@ import (
var (
_ = fmt.Sprintf("")
printVersion = flag.Bool("version", false, "print version information")
configFile = flag.String("configFile", "prometheus.conf", "Prometheus configuration file name.")
metricsStoragePath = flag.String("metricsStoragePath", "/tmp/metrics", "Base path for metrics storage.")
scrapeResultsQueueCapacity = flag.Int("scrapeResultsQueueCapacity", 4096, "The size of the scrape results queue.")
@ -45,6 +46,13 @@ var (
func main() {
flag.Parse()
versionInfoTmpl.Execute(os.Stdout, BuildInfo)
if *printVersion {
os.Exit(0)
}
conf, err := config.LoadFromFile(*configFile)
if err != nil {
log.Fatalf("Error loading configuration from %s: %v", *configFile, err)
@ -84,6 +92,7 @@ func main() {
RuleManager: ruleManager,
Storage: ts,
TargetManager: targetManager,
BuildInfo: BuildInfo,
}
web.StartServing(appState)

View file

@ -35,6 +35,10 @@ input:not([type=submit]):not([type=file]):not([type=button]) {
float: right;
}
table tbody th {
text-align: left;
}
input {
margin: 0;
border: 1px solid gray;

View file

@ -14,6 +14,7 @@
package web
import (
"flag"
"github.com/prometheus/prometheus/appstate"
"github.com/prometheus/prometheus/retrieval"
"net/http"
@ -24,6 +25,8 @@ type PrometheusStatus struct {
Rules string
Status string
TargetPools map[string]*retrieval.TargetPool
BuildInfo map[string]string
Flags map[string]string
}
type StatusHandler struct {
@ -31,11 +34,19 @@ type StatusHandler struct {
}
func (h *StatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
flags := map[string]string{}
flag.VisitAll(func(f *flag.Flag) {
flags[f.Name] = f.Value.String()
})
status := &PrometheusStatus{
Config: h.appState.Config.ToString(0),
Rules: "TODO: list rules here",
Status: "TODO: add status information here",
TargetPools: h.appState.TargetManager.Pools(),
BuildInfo: h.appState.BuildInfo,
Flags: flags,
}
executeTemplate(w, "status", status)
}

View file

@ -2,23 +2,23 @@
{{define "content"}}
<h2>Status</h2>
<div class="grouping_box">
<div class="grouping_box">
{{.Status}}
</div>
</div>
<h2>Configuration</h2>
<div class="grouping_box">
<pre>
<h2>Configuration</h2>
<div class="grouping_box">
<pre>
{{.Config}}
</pre>
</div>
</pre>
</div>
<h2>Rules</h2>
<div class="grouping_box">
<div class="grouping_box">
{{.Rules}}
</div>
</div>
<h2>Targets</h2>
<h2>Targets</h2>
<div class="grouping_box">
<ul>
{{range $job, $pool := .TargetPools}}
@ -33,5 +33,33 @@
</li>
{{end}}
</ul>
</div>
</div>
<h2>Build Info</h2>
<div class="grouping_box">
<table>
<tbody>
{{range $key, $value := .BuildInfo}}
<tr>
<th scope="row">{{$key}}</th>
<td>{{$value}}</td>
</tr>
{{end}}
</tbody>
</table>
</div>
<h2>Startup Flags</h2>
<div class="grouping_box">
<table>
<tbody>
{{range $key, $value := .Flags}}
<tr>
<th scope="row">{{$key}}</th>
<td>{{$value}}</td>
</tr>
{{end}}
</tbody>
</table>
</div>
{{end}}

View file

@ -56,6 +56,7 @@ func StartServing(appState *appstate.ApplicationState) {
exp.Handle("/static/", http.StripPrefix("/static/", new(blob.Handler)))
}
log.Printf("listening on %s", *listenAddress)
go http.ListenAndServe(*listenAddress, exp.DefaultCoarseMux)
}