mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-24 12:13:13 -08:00
Capture build information and print with -version
This commit is contained in:
parent
3ff916d209
commit
033533c4c5
18
Makefile
18
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)
|
||||
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
|
||||
|
||||
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
|
||||
|
|
38
build_info.go
Normal file
38
build_info.go
Normal 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}}
|
||||
`))
|
7
main.go
7
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,12 @@ var (
|
|||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
if *printVersion {
|
||||
versionInfoTmpl.Execute(os.Stdout, BuildInfo)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
conf, err := config.LoadFromFile(*configFile)
|
||||
if err != nil {
|
||||
log.Fatalf("Error loading configuration from %s: %v", *configFile, err)
|
||||
|
|
Loading…
Reference in a new issue