From dc3ffef6aac84e440519a3ad2e0425ede08ac8e6 Mon Sep 17 00:00:00 2001 From: Dylan Clendenin Date: Wed, 23 Nov 2016 10:13:18 -0800 Subject: [PATCH] manage git tag versioned releases - cross-compile binary releases - update installation instructions in README --- .gitignore | 1 + Makefile | 9 +++++++++ README.md | 9 ++------- mongodb_exporter.go | 5 +++++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 00ad5948..422c90e7 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ _testmain.go mongodb_exporter vendor/ +release/ diff --git a/Makefile b/Makefile index c7bd84dc..d98981e1 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +package = github.com/dcu/mongodb_exporter +TAG := $(shell git tag | sort -r | head -n 1) + test: go test github.com/dcu/mongodb_exporter/collector -cover -coverprofile=collector_coverage.out -short go tool cover -func=collector_coverage.out @@ -11,3 +14,9 @@ deps: build: deps go build mongodb_exporter.go +release: deps + mkdir -p release + perl -p -i -e 's/{{VERSION}}/$(TAG)/g' mongodb_exporter.go + GOOS=darwin GOARCH=amd64 go build -o release/mongodb_exporter-darwin-amd64 $(package) + GOOS=linux GOARCH=amd64 go build -o release/mongodb_exporter-linux-amd64 $(package) + perl -p -i -e 's/$(TAG)/{{VERSION}}/g' mongodb_exporter.go diff --git a/README.md b/README.md index b1899e05..95db3268 100644 --- a/README.md +++ b/README.md @@ -6,18 +6,13 @@ MongoDB exporter for prometheus.io, written in go. ## Installing -Requires Go 1.5+ - -Make sure $GOPATH/bin is in your $PATH, then: - - go get -u github.com/dcu/mongodb_exporter - mongodb_exporter -h +Download a [release](https://github.com/dcu/mongodb_exporter/releases) ## Building Requires [glide](https://github.com/Masterminds/glide) for dependency management - go get -u github.com/dcu/mongodb_exporter + git clone git@github.com:dcu/mongodb_exporter.git $GOPATH/src/github.com/dcu/mongodb_exporter cd $GOPATH/src/github.com/dcu/mongodb_exporter make build ./mongodb_exporter -h diff --git a/mongodb_exporter.go b/mongodb_exporter.go index 513c315c..337806bb 100644 --- a/mongodb_exporter.go +++ b/mongodb_exporter.go @@ -50,6 +50,7 @@ var ( mongodbCollectOplog = flag.Bool("mongodb.collect.oplog", true, "collect Mongodb Oplog status") mongodbCollectReplSet = flag.Bool("mongodb.collect.replset", true, "collect Mongodb replica set status") mongodbCollectDatabaseMetrics = flag.Bool("mongodb.collect.database", false, "collect MongoDB database metrics") + version = flag.Bool("version", false, "Print mongodb_exporter version") ) type basicAuthHandler struct { @@ -166,6 +167,10 @@ func createHTTPServerLogWrapper() *slog.Logger { func main() { flag.Parse() + if *version { + fmt.Println("mongodb_exporter version: {{VERSION}}") + return + } shared.ParseEnabledGroups(*enabledGroupsFlag) startWebServer()