mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-12 16:44:05 -08:00
Merge pull request #189 from prometheus/feature/build-info-and-startup-friendliness
Build info and startup friendliness
This commit is contained in:
commit
169a7dc26c
18
Makefile
18
Makefile
|
@ -17,16 +17,30 @@ TEST_ARTIFACTS = prometheus prometheus.build search_index
|
||||||
|
|
||||||
include Makefile.INCLUDE
|
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
|
all: test
|
||||||
|
|
||||||
advice:
|
advice:
|
||||||
go tool vet .
|
go tool vet .
|
||||||
|
|
||||||
binary: build
|
binary: build
|
||||||
go build -o prometheus.build
|
go build $(BUILDFLAGS) -o prometheus.build
|
||||||
|
|
||||||
build: preparation model web
|
build: preparation model web
|
||||||
go build .
|
go build $(BUILDFLAGS) .
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(MAKE) -C build clean
|
$(MAKE) -C build clean
|
||||||
|
|
|
@ -28,4 +28,5 @@ type ApplicationState struct {
|
||||||
RuleManager rules.RuleManager
|
RuleManager rules.RuleManager
|
||||||
Storage metric.Storage
|
Storage metric.Storage
|
||||||
TargetManager retrieval.TargetManager
|
TargetManager retrieval.TargetManager
|
||||||
|
BuildInfo map[string]string
|
||||||
}
|
}
|
||||||
|
|
51
build_info.go
Normal file
51
build_info.go
Normal 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}}
|
||||||
|
`))
|
9
main.go
9
main.go
|
@ -34,6 +34,7 @@ import (
|
||||||
var (
|
var (
|
||||||
_ = fmt.Sprintf("")
|
_ = fmt.Sprintf("")
|
||||||
|
|
||||||
|
printVersion = flag.Bool("version", false, "print version information")
|
||||||
configFile = flag.String("configFile", "prometheus.conf", "Prometheus configuration file name.")
|
configFile = flag.String("configFile", "prometheus.conf", "Prometheus configuration file name.")
|
||||||
metricsStoragePath = flag.String("metricsStoragePath", "/tmp/metrics", "Base path for metrics storage.")
|
metricsStoragePath = flag.String("metricsStoragePath", "/tmp/metrics", "Base path for metrics storage.")
|
||||||
scrapeResultsQueueCapacity = flag.Int("scrapeResultsQueueCapacity", 4096, "The size of the scrape results queue.")
|
scrapeResultsQueueCapacity = flag.Int("scrapeResultsQueueCapacity", 4096, "The size of the scrape results queue.")
|
||||||
|
@ -45,6 +46,13 @@ var (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
versionInfoTmpl.Execute(os.Stdout, BuildInfo)
|
||||||
|
|
||||||
|
if *printVersion {
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
conf, err := config.LoadFromFile(*configFile)
|
conf, err := config.LoadFromFile(*configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error loading configuration from %s: %v", *configFile, err)
|
log.Fatalf("Error loading configuration from %s: %v", *configFile, err)
|
||||||
|
@ -84,6 +92,7 @@ func main() {
|
||||||
RuleManager: ruleManager,
|
RuleManager: ruleManager,
|
||||||
Storage: ts,
|
Storage: ts,
|
||||||
TargetManager: targetManager,
|
TargetManager: targetManager,
|
||||||
|
BuildInfo: BuildInfo,
|
||||||
}
|
}
|
||||||
|
|
||||||
web.StartServing(appState)
|
web.StartServing(appState)
|
||||||
|
|
|
@ -35,6 +35,10 @@ input:not([type=submit]):not([type=file]):not([type=button]) {
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
table tbody th {
|
||||||
|
text-align: left;
|
||||||
|
}
|
||||||
|
|
||||||
input {
|
input {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
border: 1px solid gray;
|
border: 1px solid gray;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
"github.com/prometheus/prometheus/appstate"
|
"github.com/prometheus/prometheus/appstate"
|
||||||
"github.com/prometheus/prometheus/retrieval"
|
"github.com/prometheus/prometheus/retrieval"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -24,6 +25,8 @@ type PrometheusStatus struct {
|
||||||
Rules string
|
Rules string
|
||||||
Status string
|
Status string
|
||||||
TargetPools map[string]*retrieval.TargetPool
|
TargetPools map[string]*retrieval.TargetPool
|
||||||
|
BuildInfo map[string]string
|
||||||
|
Flags map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
type StatusHandler struct {
|
type StatusHandler struct {
|
||||||
|
@ -31,11 +34,19 @@ type StatusHandler struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *StatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
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{
|
status := &PrometheusStatus{
|
||||||
Config: h.appState.Config.ToString(0),
|
Config: h.appState.Config.ToString(0),
|
||||||
Rules: "TODO: list rules here",
|
Rules: "TODO: list rules here",
|
||||||
Status: "TODO: add status information here",
|
Status: "TODO: add status information here",
|
||||||
TargetPools: h.appState.TargetManager.Pools(),
|
TargetPools: h.appState.TargetManager.Pools(),
|
||||||
|
BuildInfo: h.appState.BuildInfo,
|
||||||
|
Flags: flags,
|
||||||
}
|
}
|
||||||
executeTemplate(w, "status", status)
|
executeTemplate(w, "status", status)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,23 +2,23 @@
|
||||||
|
|
||||||
{{define "content"}}
|
{{define "content"}}
|
||||||
<h2>Status</h2>
|
<h2>Status</h2>
|
||||||
<div class="grouping_box">
|
<div class="grouping_box">
|
||||||
{{.Status}}
|
{{.Status}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>Configuration</h2>
|
<h2>Configuration</h2>
|
||||||
<div class="grouping_box">
|
<div class="grouping_box">
|
||||||
<pre>
|
<pre>
|
||||||
{{.Config}}
|
{{.Config}}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>Rules</h2>
|
<h2>Rules</h2>
|
||||||
<div class="grouping_box">
|
<div class="grouping_box">
|
||||||
{{.Rules}}
|
{{.Rules}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2>Targets</h2>
|
<h2>Targets</h2>
|
||||||
<div class="grouping_box">
|
<div class="grouping_box">
|
||||||
<ul>
|
<ul>
|
||||||
{{range $job, $pool := .TargetPools}}
|
{{range $job, $pool := .TargetPools}}
|
||||||
|
@ -33,5 +33,33 @@
|
||||||
</li>
|
</li>
|
||||||
{{end}}
|
{{end}}
|
||||||
</ul>
|
</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}}
|
{{end}}
|
||||||
|
|
|
@ -56,6 +56,7 @@ func StartServing(appState *appstate.ApplicationState) {
|
||||||
exp.Handle("/static/", http.StripPrefix("/static/", new(blob.Handler)))
|
exp.Handle("/static/", http.StripPrefix("/static/", new(blob.Handler)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("listening on %s", *listenAddress)
|
||||||
go http.ListenAndServe(*listenAddress, exp.DefaultCoarseMux)
|
go http.ListenAndServe(*listenAddress, exp.DefaultCoarseMux)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue