Capture build information and print with -version

This commit is contained in:
Bernerd Schaefer 2013-04-25 11:47:48 +02:00
parent 3ff916d209
commit 033533c4c5
3 changed files with 61 additions and 2 deletions

View File

@ -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)
BUILD_DATE := $(shell date)
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

38
build_info.go Normal file
View File

@ -0,0 +1,38 @@
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 ( 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,12 @@ var (
func main() { func main() {
flag.Parse() flag.Parse()
if *printVersion {
versionInfoTmpl.Execute(os.Stdout, BuildInfo)
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)