diff --git a/Makefile b/Makefile index ee895f8f8..5c0e666e0 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/appstate/appstate.go b/appstate/appstate.go index 7938227b3..792529623 100644 --- a/appstate/appstate.go +++ b/appstate/appstate.go @@ -28,4 +28,5 @@ type ApplicationState struct { RuleManager rules.RuleManager Storage metric.Storage TargetManager retrieval.TargetManager + BuildInfo map[string]string } diff --git a/build_info.go b/build_info.go new file mode 100644 index 000000000..fe00fa49d --- /dev/null +++ b/build_info.go @@ -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}} +`)) diff --git a/main.go b/main.go index 85bbee144..95ab3ef54 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/web/static/css/prometheus.css b/web/static/css/prometheus.css index d46ae56b8..7e76a5b32 100644 --- a/web/static/css/prometheus.css +++ b/web/static/css/prometheus.css @@ -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; diff --git a/web/status.go b/web/status.go index 2874fe9d7..fb60905f4 100644 --- a/web/status.go +++ b/web/status.go @@ -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) } diff --git a/web/templates/status.html b/web/templates/status.html index 26b27b6a4..b8a63a69c 100644 --- a/web/templates/status.html +++ b/web/templates/status.html @@ -2,23 +2,23 @@ {{define "content"}}

Status

-
+
{{.Status}} -
+
-

Configuration

-
-
+    

Configuration

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

Rules

-
+
{{.Rules}} -
+
-

Targets

+

Targets

-
+ + +

Build Info

+
+ + + {{range $key, $value := .BuildInfo}} + + + + + {{end}} + +
{{$key}}{{$value}}
+
+ +

Startup Flags

+
+ + + {{range $key, $value := .Flags}} + + + + + {{end}} + +
{{$key}}{{$value}}
+
{{end}} diff --git a/web/web.go b/web/web.go index 721219346..5917f626e 100644 --- a/web/web.go +++ b/web/web.go @@ -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) }