Skip to content

Commit

Permalink
Use prometheus/common/version for versioning and exposing metric
Browse files Browse the repository at this point in the history
  • Loading branch information
carlpett committed Oct 12, 2017
1 parent 9679932 commit 1e11137
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 10 deletions.
13 changes: 10 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ GOTOOLS=github.com/mitchellh/gox/...
NAME=cloudmonitor_exporter

VERSION=0.1.5
BUILD_TIME=`date '+%F-%T%z'`

LDFLAGS=-ldflags "-X main.version=${VERSION} -X main.buildtime=${BUILD_TIME}"
COMMIT=$(shell git rev-parse HEAD)
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
BUILDER=$(shell whoami)@$(shell hostname)
BUILD_DATE=$(shell date '+%F-%T%z')
VERSION_PATH=github.com/ExpressenAB/cloudmonitor_exporter/vendor/github.com/prometheus/common/version
LDFLAGS=-ldflags "-X ${VERSION_PATH}.Version=${VERSION} \
-X ${VERSION_PATH}.Revision=${COMMIT} \
-X ${VERSION_PATH}.Branch=${BRANCH} \
-X ${VERSION_PATH}.BuildUser=${BUILDER} \
-X ${VERSION_PATH}.BuildDate=${BUILD_DATE}"

all: tools build

Expand Down
9 changes: 3 additions & 6 deletions cloudmonitor_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"github.com/avct/user-agent-surfer"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/version"
"log"
"net"
"net/http"
Expand All @@ -18,11 +19,6 @@ import (
"time"
)

var (
version string
buildtime string
)

var (
listenAddress = flag.String("exporter.address", ":9143", "The address on which to expose the web interface and generated Prometheus metrics.")
namespace = flag.String("exporter.namespace", "cloudmonitor", "The prometheus namespace.")
Expand Down Expand Up @@ -540,7 +536,7 @@ func main() {

flag.Parse()

log.Printf("Cloudmonitor-exporter v%s\n", version+"("+buildtime+")")
log.Printf("Cloudmonitor-exporter %s\n", version.Print("cloudmonitor_exporter"))
if *showVersion {
return
}
Expand All @@ -552,6 +548,7 @@ func main() {
log.Printf("logging to %s", *accesslog)
}

prometheus.MustRegister(version.NewCollector("cloudmonitor_exporter"))
prometheus.MustRegister(exporter)

http.Handle(*metricsEndpoint, prometheus.Handler())
Expand Down
89 changes: 89 additions & 0 deletions vendor/github.com/prometheus/common/version/info.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
"revision": "49fee292b27bfff7f354ee0f64e1bc4850462edf",
"revisionTime": "2017-02-20T10:38:46Z"
},
{
"checksumSHA1": "91KYK0SpvkaMJJA2+BcxbVnyRO0=",
"path": "github.com/prometheus/common/version",
"revision": "bc8b88226a1210b016e9993b1d75f858c9c8f778",
"revisionTime": "2017-08-30T19:05:55Z"
},
{
"checksumSHA1": "cD4xn1qxbkiuXqUExpdnDroCTrY=",
"path": "github.com/prometheus/procfs",
Expand All @@ -69,5 +75,5 @@
"revisionTime": "2017-02-16T22:32:56Z"
}
],
"rootPath": "cloudmonitor_exporter"
"rootPath": "github.com/ExpressenAB/cloudmonitor_exporter"
}

0 comments on commit 1e11137

Please sign in to comment.