Skip to content
This repository has been archived by the owner on Apr 7, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3 from carlpett/promu
Browse files Browse the repository at this point in the history
Add Promu+CircleCI and versioning
  • Loading branch information
carlpett authored Jul 30, 2017
2 parents acf7119 + 7722f8b commit db6ce6e
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .promu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
verbose: true
go:
version: 1.8
cgo: false
repository:
path: github.com/carlpett/stream_exporter
build:
flags: -a -tags netgo
ldflags: |
-s
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Version={{.Version}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Revision={{.Revision}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.Branch={{.Branch}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildUser={{user}}@{{host}}
-X {{repoPath}}/vendor/github.com/prometheus/common/version.BuildDate={{date "20060102-15:04:05"}}
tarball:
prefix: .
crossbuild:
platforms:
# Only build common platforms for now to keep build times short. Easy to add more on request.
- linux/amd64
- windows/amd64
45 changes: 45 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
GO := go
FIRST_GOPATH := $(firstword $(subst :, ,$(GOPATH)))
PROMU := $(FIRST_GOPATH)/bin/promu
pkgs = $(shell $(GO) list ./... | grep -v /vendor/)

PREFIX ?= $(shell pwd)/.build
BIN_DIR ?= $(shell pwd)

ifdef DEBUG
bindata_flags = -debug
endif

all: format build

style:
@echo ">> checking code style"
@! gofmt -d $(shell find . -path ./vendor -prune -o -name '*.go' -print) | grep '^'

format:
@echo ">> formatting code"
@$(GO) fmt $(pkgs)

vet:
@echo ">> vetting code"
@$(GO) vet $(pkgs)

test:
@echo ">> testing code"
@$(GO) test $(pkgs)

build: promu
@echo ">> building binaries"
@$(PROMU) build --prefix $(PREFIX)

tarball: promu
@echo ">> building release tarball"
@$(PROMU) tarball --prefix $(PREFIX) $(BIN_DIR)

promu:
@GOOS=$(shell uname -s | tr A-Z a-z) \
GOARCH=$(subst x86_64,amd64,$(patsubst i%86,386,$(shell uname -m))) \
$(GO) get -u github.com/prometheus/promu


.PHONY: all style format build vet tarball docker promu
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# Stream Exporter

[![CircleCI](https://circleci.com/gh/carlpett/stream_exporter.svg?style=shield)](https://circleci.com/gh/carlpett/stream_exporter)

A [Prometheus](https://prometheus.io) exporter for extracting metrics from streaming sources of text, such as logs written to a socket, or tailing a file.
Extraction into metrics is done using regular expressions, on a per-line basis. Capture groups in the regular expression are used as labels in the metrics. All Prometheus metric types are supported, and fully configurable.

Expand Down
51 changes: 51 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
machine:
environment:
REPO_PATH: github.com/carlpett/stream_exporter
DOCKER_TEST_IMAGE_NAME: quay.io/prometheus/golang-builder:1.8-base
pre:
- sudo curl -L -o /usr/bin/docker 'https://s3-external-1.amazonaws.com/circle-downloads/docker-1.9.1-circleci'
- sudo chmod 0755 /usr/bin/docker
- sudo curl -L 'https://github.com/aktau/github-release/releases/download/v0.6.2/linux-amd64-github-release.tar.bz2' | tar xvjf - --strip-components 3 -C $HOME/bin
services:
- docker

dependencies:
pre:
- make promu
- docker info
- git describe --always | sed -r 's/^v//' | tee VERSION
override:
- promu crossbuild
- ln -s .build/linux-amd64/stream_exporter stream_exporter
- |
if [ -n "$CIRCLE_TAG" ]; then
make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME DOCKER_IMAGE_TAG=$CIRCLE_TAG
else
make docker DOCKER_IMAGE_NAME=$DOCKER_IMAGE_NAME
fi
post:
- mkdir $CIRCLE_ARTIFACTS/binaries/ && cp -a .build/* $CIRCLE_ARTIFACTS/binaries/
- docker images

test:
override:
- docker run --rm -t -v "$(pwd):/app" "${DOCKER_TEST_IMAGE_NAME}" -i "${REPO_PATH}" -T

deployment:
hub_branch:
branch: master
owner: carlpett
hub_tag:
tag: /^v[0-9]+(\.[0-9]+){2}(-.+|[^-.]*)$/
owner: carlpett
commands:
- promu crossbuild tarballs
- promu checksum .tarballs
- promu release .tarballs
- mkdir $CIRCLE_ARTIFACTS/releases/ && cp -a .tarballs/* $CIRCLE_ARTIFACTS/releases/
#- docker login -e $DOCKER_EMAIL -u $DOCKER_LOGIN -p $DOCKER_PASSWORD
#- |
# if [[ "$CIRCLE_TAG" =~ ^v[0-9]+(\.[0-9]+){2}$ ]]; then
# docker tag "$DOCKER_IMAGE_NAME:$CIRCLE_TAG" "$DOCKER_IMAGE_NAME:latest"
# fi
#- docker push $DOCKER_IMAGE_NAME
8 changes: 8 additions & 0 deletions exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/log"
"github.com/prometheus/common/version"

"github.com/carlpett/stream_exporter/input"
"github.com/carlpett/stream_exporter/linemetrics"
Expand Down Expand Up @@ -40,6 +41,7 @@ var (

var (
configFilePath = flag.String("config", "stream_exporter.yaml", "Path to config file")
showVersion = flag.Bool("version", false, "Print version")

inputType = flag.String("input.type", "", "What input module to use")
listInputTypes = flag.Bool("input.print", false, "Print available input modules and exit")
Expand All @@ -56,6 +58,12 @@ var startupTasks = make(map[string]startupTask, 0)
func main() {
flag.Parse()

if *showVersion {
fmt.Printf(version.Print("stream_exporter"))
os.Exit(0)
}
prometheus.MustRegister(version.NewCollector("stream_exporter"))

// Startup tasks can be registered to perform (typically os-specific) initialization
for taskName, task := range startupTasks {
log.Debugf("Executing startup task '%s'", taskName)
Expand Down
Binary file added stream_exporter.exe
Binary file not shown.
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.

6 changes: 6 additions & 0 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
"revision": "dd586c1c5abb0be59e60f942c22af711a2008cb4",
"revisionTime": "2016-05-03T22:05:32Z"
},
{
"checksumSHA1": "91KYK0SpvkaMJJA2+BcxbVnyRO0=",
"path": "github.com/prometheus/common/version",
"revision": "e1c8772d083ee69ce07a4bf93b76131b7786b300",
"revisionTime": "2017-07-30T07:43:01Z"
},
{
"checksumSHA1": "6gusrsr0iRPTOBie4dn2MG2v9OI=",
"path": "github.com/prometheus/procfs",
Expand Down

0 comments on commit db6ce6e

Please sign in to comment.