Skip to content

Commit

Permalink
Add exporter version metric
Browse files Browse the repository at this point in the history
Add a standard `process_exporter_build_info` metric to allow monitoring
exporter rollouts. Use the Prometheus common library version handler.

Signed-off-by: Ben Kochie <superq@gmail.com>
  • Loading branch information
SuperQ committed Nov 5, 2020
1 parent fce9424 commit 90d7869
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,20 @@ pkgs = $(shell go list ./...)
PREFIX ?= $(shell pwd)
BIN_DIR ?= $(shell pwd)
DOCKER_IMAGE_NAME ?= ncabatoff/process-exporter
TAG_VERSION ?= $(shell git describe --tags --abbrev=0)

BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)
BUILDDATE ?= $(shell date --iso-8601=seconds)
BUILDUSER ?= $(shell whoami)@$(shell hostname)
REVISION ?= $(shell git rev-parse HEAD)
TAG_VERSION ?= $(shell git describe --tags --abbrev=0)

VERSION_LDFLAGS := \
-X github.com/prometheus/common/version.Branch=$(BRANCH) \
-X github.com/prometheus/common/version.BuildDate=$(BUILDDATE) \
-X github.com/prometheus/common/version.BuildUser=$(BUILDUSER) \
-X github.com/prometheus/common/version.Revision=$(REVISION) \
-X main.version=$(TAG_VERSION)

SMOKE_TEST = -config.path packaging/conf/all.yaml -once-to-stdout-delay 1s |grep -q 'namedprocess_namegroup_memory_bytes{groupname="process-exporte",memtype="virtual"}'

all: format vet test build smoke
Expand All @@ -26,7 +39,7 @@ vet:

build:
@echo ">> building code"
cd cmd/process-exporter; CGO_ENABLED=0 go build -ldflags "-X main.version=$(TAG_VERSION)" -o ../../process-exporter -a -tags netgo
cd cmd/process-exporter; CGO_ENABLED=0 go build -ldflags "$(VERSION_LDFLAGS)" -o ../../process-exporter -a -tags netgo

smoke:
@echo ">> smoke testing process-exporter"
Expand Down
8 changes: 7 additions & 1 deletion cmd/process-exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/ncabatoff/process-exporter/proc"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
promVersion "github.com/prometheus/common/version"
)

// Version is set at build time use ldflags.
Expand Down Expand Up @@ -276,6 +277,11 @@ func (nmr *nameMapperRegex) MatchAndName(nacl common.ProcAttributes) (bool, stri
return false, ""
}

func init() {
promVersion.Version = version
prometheus.MustRegister(promVersion.NewCollector("process_exporter"))
}

func main() {
var (
listenAddress = flag.String("web.listen-address", ":9256",
Expand Down Expand Up @@ -310,7 +316,7 @@ func main() {
flag.Parse()

if *showVersion {
fmt.Printf("process-exporter version %s\n", version)
fmt.Printf("%s\n", promVersion.Print("process-exporter"))
os.Exit(0)
}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/ncabatoff/go-seq v0.0.0-20180805175032-b08ef85ed833
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/prometheus/client_golang v1.8.0
github.com/prometheus/common v0.14.0
github.com/prometheus/procfs v0.2.0
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b
gopkg.in/yaml.v2 v2.3.0
Expand Down

0 comments on commit 90d7869

Please # to comment.