2017-08-03 18:54:05 +00:00
|
|
|
PREFIX := /usr/local
|
2017-06-27 20:24:06 +00:00
|
|
|
VERSION := $(shell git describe --exact-match --tags 2>/dev/null)
|
|
|
|
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
|
|
|
COMMIT := $(shell git rev-parse --short HEAD)
|
2018-02-02 20:25:59 +00:00
|
|
|
GOFILES ?= $(shell git ls-files '*.go')
|
2018-03-28 00:30:51 +00:00
|
|
|
GOFMT ?= $(shell gofmt -l $(filter-out plugins/parsers/influx/machine.go, $(GOFILES)))
|
2018-04-10 22:35:58 +00:00
|
|
|
BUILDFLAGS ?=
|
2018-02-01 23:05:39 +00:00
|
|
|
|
2015-11-20 22:23:48 +00:00
|
|
|
ifdef GOBIN
|
|
|
|
PATH := $(GOBIN):$(PATH)
|
|
|
|
else
|
|
|
|
PATH := $(subst :,/bin:,$(GOPATH))/bin:$(PATH)
|
2015-09-10 17:01:08 +00:00
|
|
|
endif
|
2015-08-04 20:52:44 +00:00
|
|
|
|
2017-08-10 23:33:31 +00:00
|
|
|
LDFLAGS := $(LDFLAGS) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH)
|
2017-06-27 20:24:06 +00:00
|
|
|
ifdef VERSION
|
|
|
|
LDFLAGS += -X main.version=$(VERSION)
|
|
|
|
endif
|
|
|
|
|
2017-08-09 18:47:55 +00:00
|
|
|
all:
|
|
|
|
$(MAKE) deps
|
|
|
|
$(MAKE) telegraf
|
2017-08-03 18:54:05 +00:00
|
|
|
|
|
|
|
deps:
|
2018-02-01 23:05:39 +00:00
|
|
|
go get -u github.com/golang/lint/golint
|
2018-06-19 18:55:38 +00:00
|
|
|
go get -u github.com/golang/dep/cmd/dep
|
|
|
|
dep ensure
|
2017-08-03 18:54:05 +00:00
|
|
|
|
|
|
|
telegraf:
|
2018-05-04 21:08:23 +00:00
|
|
|
go build -ldflags "$(LDFLAGS)" ./cmd/telegraf
|
2015-12-04 18:44:56 +00:00
|
|
|
|
2017-08-03 18:54:05 +00:00
|
|
|
go-install:
|
2017-08-07 22:47:20 +00:00
|
|
|
go install -ldflags "-w -s $(LDFLAGS)" ./cmd/telegraf
|
2016-01-29 18:02:54 +00:00
|
|
|
|
2017-08-03 18:54:05 +00:00
|
|
|
install: telegraf
|
|
|
|
mkdir -p $(DESTDIR)$(PREFIX)/bin/
|
2018-06-13 01:37:50 +00:00
|
|
|
cp telegraf $(DESTDIR)$(PREFIX)/bin/
|
2015-08-04 20:52:44 +00:00
|
|
|
|
2017-08-03 18:54:05 +00:00
|
|
|
test:
|
|
|
|
go test -short ./...
|
|
|
|
|
2018-02-01 23:05:39 +00:00
|
|
|
fmt:
|
2018-03-28 00:30:51 +00:00
|
|
|
@gofmt -w $(filter-out plugins/parsers/influx/machine.go, $(GOFILES))
|
2018-02-01 23:05:39 +00:00
|
|
|
|
|
|
|
fmtcheck:
|
|
|
|
@echo '[INFO] running gofmt to identify incorrectly formatted code...'
|
2018-04-10 22:35:58 +00:00
|
|
|
@if [ ! -z "$(GOFMT)" ]; then \
|
2018-02-01 23:05:39 +00:00
|
|
|
echo "[ERROR] gofmt has found errors in the following files:" ; \
|
|
|
|
echo "$(GOFMT)" ; \
|
|
|
|
echo "" ;\
|
|
|
|
echo "Run make fmt to fix them." ; \
|
|
|
|
exit 1 ;\
|
|
|
|
fi
|
|
|
|
@echo '[INFO] done.'
|
|
|
|
|
2017-08-03 18:54:05 +00:00
|
|
|
test-windows:
|
2018-06-22 00:46:58 +00:00
|
|
|
go test -short ./plugins/inputs/ping/...
|
|
|
|
go test -short ./plugins/inputs/win_perf_counters/...
|
|
|
|
go test -short ./plugins/inputs/win_services/...
|
|
|
|
go test -short ./plugins/inputs/procstat/...
|
|
|
|
go test -short ./plugins/inputs/ntpq/...
|
2017-08-03 18:54:05 +00:00
|
|
|
|
2018-02-01 23:05:39 +00:00
|
|
|
# vet runs the Go source code static analysis tool `vet` to find
|
|
|
|
# any common errors.
|
|
|
|
vet:
|
2018-03-28 00:30:51 +00:00
|
|
|
@echo 'go vet $$(go list ./... | grep -v ./plugins/parsers/influx)'
|
2018-04-10 22:35:58 +00:00
|
|
|
@go vet $$(go list ./... | grep -v ./plugins/parsers/influx) ; if [ $$? -ne 0 ]; then \
|
2018-02-01 23:05:39 +00:00
|
|
|
echo ""; \
|
|
|
|
echo "go vet has found suspicious constructs. Please remediate any reported errors"; \
|
|
|
|
echo "to fix them before submitting code for review."; \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
|
|
|
|
2018-04-02 21:13:15 +00:00
|
|
|
test-ci: fmtcheck vet
|
2018-04-10 22:35:58 +00:00
|
|
|
go test -short ./...
|
2018-04-02 21:13:15 +00:00
|
|
|
|
|
|
|
test-all: fmtcheck vet
|
2017-08-03 18:54:05 +00:00
|
|
|
go test ./...
|
2015-12-21 19:49:56 +00:00
|
|
|
|
2016-02-18 04:57:33 +00:00
|
|
|
package:
|
2017-09-22 23:49:28 +00:00
|
|
|
./scripts/build.py --package --platform=all --arch=all
|
2017-11-07 21:54:36 +00:00
|
|
|
|
2017-08-03 18:54:05 +00:00
|
|
|
clean:
|
2018-02-01 23:05:39 +00:00
|
|
|
rm -f telegraf
|
|
|
|
rm -f telegraf.exe
|
2016-01-29 18:02:54 +00:00
|
|
|
|
2017-09-22 23:49:28 +00:00
|
|
|
docker-image:
|
|
|
|
./scripts/build.py --package --platform=linux --arch=amd64
|
|
|
|
cp build/telegraf*$(COMMIT)*.deb .
|
|
|
|
docker build -f scripts/dev.docker --build-arg "package=telegraf*$(COMMIT)*.deb" -t "telegraf-dev:$(COMMIT)" .
|
|
|
|
|
2018-03-28 00:30:51 +00:00
|
|
|
plugins/parsers/influx/machine.go: plugins/parsers/influx/machine.go.rl
|
|
|
|
ragel -Z -G2 $^ -o $@
|
|
|
|
|
2018-07-02 23:34:40 +00:00
|
|
|
static:
|
|
|
|
@echo "Building static linux binary..."
|
|
|
|
@CGO_ENABLED=0 \
|
|
|
|
GOOS=linux \
|
|
|
|
GOARCH=amd64 \
|
|
|
|
go build -ldflags "$(LDFLAGS)" ./cmd/telegraf
|
|
|
|
|
|
|
|
plugin-%:
|
|
|
|
@echo "Starting dev environment for $${$(@)} input plugin..."
|
|
|
|
@docker-compose -f plugins/inputs/$${$(@)}/dev/docker-compose.yml up
|
|
|
|
|
|
|
|
.PHONY: deps telegraf install test test-windows lint vet test-all package clean docker-image fmtcheck uint64 static
|