2015-03-09 19:14:42 +01:00
# Copyright 2015 The Prometheus Authors
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2014-04-10 01:20:52 +02:00
2016-12-29 18:52:36 +01:00
GO ?= GO15VENDOREXPERIMENT = 1 go
2017-03-22 18:20:32 +01:00
GOPATH := $( firstword $( subst :, ,$( shell $( GO) env GOPATH) ) )
2017-08-21 18:46:43 +02:00
GOARCH := $( shell $( GO) env GOARCH)
2017-10-03 22:40:22 +02:00
GOHOSTARCH := $( shell $( GO) env GOHOSTARCH)
2017-02-02 18:50:28 +01:00
2018-02-13 18:04:03 +01:00
PROMTOOL ?= $( GOPATH) /bin/promtool
2017-02-02 18:50:28 +01:00
PROMU ?= $( GOPATH) /bin/promu
STATICCHECK ?= $( GOPATH) /bin/staticcheck
pkgs = $( shell $( GO) list ./... | grep -v /vendor/)
2015-12-17 16:06:58 +01:00
2016-01-24 23:38:06 +01:00
PREFIX ?= $( shell pwd )
BIN_DIR ?= $( shell pwd )
DOCKER_IMAGE_NAME ?= node-exporter
DOCKER_IMAGE_TAG ?= $( subst /,-,$( shell git rev-parse --abbrev-ref HEAD) )
2017-08-17 11:53:04 +02:00
MACH ?= $( shell uname -m)
DOCKERFILE ?= Dockerfile
2015-12-17 16:06:58 +01:00
2018-02-19 15:44:59 +01:00
STATICCHECK_IGNORE =
2017-10-14 14:23:42 +02:00
2017-02-28 13:04:52 +01:00
i f e q ( $( OS ) , W i n d o w s _ N T )
OS_detected := Windows
e l s e
OS_detected := $( shell uname -s)
e n d i f
2015-12-17 16:06:58 +01:00
2018-02-28 18:05:35 +01:00
i f e q ( $( GOHOSTARCH ) , a m d 6 4 )
2018-04-06 18:50:26 +02:00
ifeq ( $( OS_detected) ,$( filter $( OS_detected) ,Linux FreeBSD Darwin Windows) )
2018-02-28 18:05:35 +01:00
# Only supported on amd64
test-flags := -race
endif
e n d i f
2017-02-28 13:04:52 +01:00
i f e q ( $( OS_detected ) , L i n u x )
test-e2e := test-e2e
e l s e
test-e2e := skip-test-e2e
e n d i f
2018-02-13 18:04:03 +01:00
i f e q ( $( MACH ) , p p c 6 4 l e )
e2e-out = collector/fixtures/e2e-ppc64le-output.txt
e l s e
e2e-out = collector/fixtures/e2e-output.txt
e n d i f
2017-08-21 18:46:43 +02:00
# 64bit -> 32bit mapping for cross-checking. At least for amd64/386, the 64bit CPU can execute 32bit code but not the other way around, so we don't support cross-testing upwards.
cross-test = skip-test-32bit
d e f i n e g o a r c h _ p a i r
2017-08-24 09:13:17 +02:00
ifeq ( $$ ( OS_detected) ,Linux)
ifeq ( $$ ( GOARCH) ,$1 )
GOARCH_CROSS = $2
cross-test = test-32bit
endif
endif
2017-08-21 18:46:43 +02:00
e n d e f
# By default, "cross" test with ourselves to cover unknown pairings.
$( eval $ ( call goarch_pair ,amd 64,386) )
$( eval $ ( call goarch_pair ,arm 64,arm ) )
$( eval $ ( call goarch_pair ,mips 64,mips ) )
$( eval $ ( call goarch_pair ,mips 64el ,mipsel ) )
2018-02-13 18:04:03 +01:00
all : format vet staticcheck checkmetrics build test $( cross -test ) $( test -e 2e )
2014-04-10 01:20:52 +02:00
2016-01-24 23:38:06 +01:00
style :
@echo ">> checking code style"
@! gofmt -d $( shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'
Add bcache collector (#597)
* Add bcache collector for Linux
This collector gathers metrics related to the Linux block cache
(bcache) from sysfs.
* Removed commented out code
* Use project comment style
* Add _sectors to metric name to indicate unit
* Really use project comment style
* Rename bcache.go to bcache_linux.go
* Keep collector namespace clean
Rename:
- metric -> bcacheMetric
- periodStatsToMetrics -> bcachePeriodStatsToMetric
* Shorten slice initialization
* Change label names to backing_device, cache_device
* Remove five minute metrics (keep only total)
* Include units in additional metric names
* Enable bcache collector by default
* Provide metrics in seconds, not nanoseconds
* remove metrics with label "all"
* Add fixtures, update end-to-end for bcache collector
* Move fixtures/sys into tar.gz
This changeset moves the collector/fixtures/sys directory into
collector/fixtures/sys.tar.gz and tweaks the Makefile to unpack the
tarball before tests are run.
The reason for this change is that Windows does not allow colons in a
path (colons are present in some of the bcache fixture files), nor can
it (out of the box) deal with pathnames longer than 260 characters
(which we would be increasingly likely to hit if we tried to replace
colons with longer codes that are guaranteed not the turn up in regular
file names).
* Add ttar: plain text archive, replacement for tar
This changeset adds ttar, a plain text replacement for tar, and uses it
for the sysfs fixture archive. The syntax is loosely based on tar(1).
Using a plain text archive makes it possible to review changes without
downloading and extracting the archive. Also, when working on the repo,
git diff and git log become useful again, allowing a committer to verify
and track changes over time.
The code is written in bash, because bash is available out of the box on
all major flavors of Linux and on macOS. The feature set used is
restricted to bash version 3.2 because that is what Apple is still
shipping.
The programm also works on Windows if bash is installed. Obviously, it
does not solve the Windows limitations (path length limited to 260
characters, no symbolic links) that prompted the move to an archive
format in the first place.
2017-07-07 07:20:18 +02:00
test : collector /fixtures /sys /.unpacked
2016-01-24 23:38:06 +01:00
@echo ">> running tests"
2017-10-03 22:40:22 +02:00
$( GO) test -short $( test-flags) $( pkgs)
2016-01-24 23:38:06 +01:00
2017-08-21 18:46:43 +02:00
test-32bit : collector /fixtures /sys /.unpacked
@echo ">> running tests in 32-bit mode"
@env GOARCH = $( GOARCH_CROSS) $( GO) test $( pkgs)
skip-test-32bit :
2017-08-24 09:13:17 +02:00
@echo " >> SKIP running tests in 32-bit mode: not supported on $( OS_detected) / $( GOARCH) "
2017-08-21 18:46:43 +02:00
Add bcache collector (#597)
* Add bcache collector for Linux
This collector gathers metrics related to the Linux block cache
(bcache) from sysfs.
* Removed commented out code
* Use project comment style
* Add _sectors to metric name to indicate unit
* Really use project comment style
* Rename bcache.go to bcache_linux.go
* Keep collector namespace clean
Rename:
- metric -> bcacheMetric
- periodStatsToMetrics -> bcachePeriodStatsToMetric
* Shorten slice initialization
* Change label names to backing_device, cache_device
* Remove five minute metrics (keep only total)
* Include units in additional metric names
* Enable bcache collector by default
* Provide metrics in seconds, not nanoseconds
* remove metrics with label "all"
* Add fixtures, update end-to-end for bcache collector
* Move fixtures/sys into tar.gz
This changeset moves the collector/fixtures/sys directory into
collector/fixtures/sys.tar.gz and tweaks the Makefile to unpack the
tarball before tests are run.
The reason for this change is that Windows does not allow colons in a
path (colons are present in some of the bcache fixture files), nor can
it (out of the box) deal with pathnames longer than 260 characters
(which we would be increasingly likely to hit if we tried to replace
colons with longer codes that are guaranteed not the turn up in regular
file names).
* Add ttar: plain text archive, replacement for tar
This changeset adds ttar, a plain text replacement for tar, and uses it
for the sysfs fixture archive. The syntax is loosely based on tar(1).
Using a plain text archive makes it possible to review changes without
downloading and extracting the archive. Also, when working on the repo,
git diff and git log become useful again, allowing a committer to verify
and track changes over time.
The code is written in bash, because bash is available out of the box on
all major flavors of Linux and on macOS. The feature set used is
restricted to bash version 3.2 because that is what Apple is still
shipping.
The programm also works on Windows if bash is installed. Obviously, it
does not solve the Windows limitations (path length limited to 260
characters, no symbolic links) that prompted the move to an archive
format in the first place.
2017-07-07 07:20:18 +02:00
collector/fixtures/sys/.unpacked : collector /fixtures /sys .ttar
2018-03-08 12:43:49 +01:00
@echo ">> extracting sysfs fixtures"
Add bcache collector (#597)
* Add bcache collector for Linux
This collector gathers metrics related to the Linux block cache
(bcache) from sysfs.
* Removed commented out code
* Use project comment style
* Add _sectors to metric name to indicate unit
* Really use project comment style
* Rename bcache.go to bcache_linux.go
* Keep collector namespace clean
Rename:
- metric -> bcacheMetric
- periodStatsToMetrics -> bcachePeriodStatsToMetric
* Shorten slice initialization
* Change label names to backing_device, cache_device
* Remove five minute metrics (keep only total)
* Include units in additional metric names
* Enable bcache collector by default
* Provide metrics in seconds, not nanoseconds
* remove metrics with label "all"
* Add fixtures, update end-to-end for bcache collector
* Move fixtures/sys into tar.gz
This changeset moves the collector/fixtures/sys directory into
collector/fixtures/sys.tar.gz and tweaks the Makefile to unpack the
tarball before tests are run.
The reason for this change is that Windows does not allow colons in a
path (colons are present in some of the bcache fixture files), nor can
it (out of the box) deal with pathnames longer than 260 characters
(which we would be increasingly likely to hit if we tried to replace
colons with longer codes that are guaranteed not the turn up in regular
file names).
* Add ttar: plain text archive, replacement for tar
This changeset adds ttar, a plain text replacement for tar, and uses it
for the sysfs fixture archive. The syntax is loosely based on tar(1).
Using a plain text archive makes it possible to review changes without
downloading and extracting the archive. Also, when working on the repo,
git diff and git log become useful again, allowing a committer to verify
and track changes over time.
The code is written in bash, because bash is available out of the box on
all major flavors of Linux and on macOS. The feature set used is
restricted to bash version 3.2 because that is what Apple is still
shipping.
The programm also works on Windows if bash is installed. Obviously, it
does not solve the Windows limitations (path length limited to 260
characters, no symbolic links) that prompted the move to an archive
format in the first place.
2017-07-07 07:20:18 +02:00
./ttar -C collector/fixtures -x -f collector/fixtures/sys.ttar
touch $@
test-e2e : build collector /fixtures /sys /.unpacked
2016-12-21 12:00:32 +01:00
@echo ">> running end-to-end tests"
./end-to-end-test.sh
2017-02-28 13:04:52 +01:00
skip-test-e2e :
@echo " >> SKIP running end-to-end tests on $( OS_detected) "
2018-02-13 18:04:03 +01:00
checkmetrics : $( PROMTOOL )
@echo ">> checking metrics for correctness"
./checkmetrics.sh $( PROMTOOL) $( e2e-out)
2016-01-24 23:38:06 +01:00
format :
@echo ">> formatting code"
@$( GO) fmt $( pkgs)
vet :
@echo ">> vetting code"
@$( GO) vet $( pkgs)
2017-02-02 18:50:28 +01:00
staticcheck : $( STATICCHECK )
@echo ">> running staticcheck"
2017-10-14 14:23:42 +02:00
@$( STATICCHECK) -ignore " $( STATICCHECK_IGNORE) " $( pkgs)
2017-02-02 18:50:28 +01:00
2016-08-03 21:23:02 +02:00
build : $( PROMU )
2016-01-24 23:38:06 +01:00
@echo ">> building binaries"
@$( PROMU) build --prefix $( PREFIX)
2016-08-03 21:23:02 +02:00
tarball : $( PROMU )
2016-01-24 23:38:06 +01:00
@echo ">> building release tarball"
@$( PROMU) tarball --prefix $( PREFIX) $( BIN_DIR)
docker :
2017-08-17 11:53:04 +02:00
i f e q ( $( MACH ) , p p c 6 4 l e )
$( eval DOCKERFILE = Dockerfile.ppc64le)
e n d i f
@echo " >> building docker image from $( DOCKERFILE) "
@docker build --file $( DOCKERFILE) -t " $( DOCKER_IMAGE_NAME) : $( DOCKER_IMAGE_TAG) " .
2016-01-24 23:38:06 +01:00
2017-01-24 11:19:44 +01:00
test-docker :
@echo ">> testing docker image"
./test_image.sh " $( DOCKER_IMAGE_NAME) : $( DOCKER_IMAGE_TAG) " 9100
2018-02-13 18:04:03 +01:00
$(GOPATH)/bin/promtool promtool :
@GOOS= GOARCH = $( GO) get -u github.com/prometheus/prometheus/cmd/promtool
2016-08-03 21:23:02 +02:00
$(GOPATH)/bin/promu promu :
2017-02-02 18:50:28 +01:00
@GOOS= GOARCH = $( GO) get -u github.com/prometheus/promu
$(GOPATH)/bin/staticcheck :
@GOOS= GOARCH = $( GO) get -u honnef.co/go/tools/cmd/staticcheck
2016-01-24 23:38:06 +01:00
2018-02-13 18:04:03 +01:00
.PHONY : all style format build test test -e 2e vet tarball docker promtool promu staticcheck checkmetrics
2017-03-22 22:35:32 +01:00
# Declaring the binaries at their default locations as PHONY targets is a hack
# to ensure the latest version is downloaded on every make execution.
# If this is not desired, copy/symlink these binaries to a different path and
# set the respective environment variables.
2018-02-13 18:04:03 +01:00
.PHONY : $( GOPATH ) /bin /promtool $( GOPATH ) /bin /promu $( GOPATH ) /bin /staticcheck