Skip to content

Commit

Permalink
Update packaging and add vendoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
wrouesnel committed Feb 24, 2017
1 parent 5c26a21 commit 26ae92b
Show file tree
Hide file tree
Showing 381 changed files with 158,149 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- 1.5.1
- 1.7

addons:
apt:
Expand Down
30 changes: 30 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

GO_SRC := $(shell find -type f -name '*.go' ! -path '*/vendor/*')
GO_PKG := $(shell find -type d ! -path '*/vendor/*' ! -path '.*')
VERSION ?= $(shell git describe --long --dirty)

all: style vet test tail_exporter.x86_64

tail_exporter.x86_64: $(GO_SRC)
GOOS=linux GOARCH=amd64 go build -a \
-ldflags "-extldflags '-static' -X main.Version=$(shell git describe --long --dirty)" \
-o tail_exporter.x86_64 .

vet:
go vet

# Check code conforms to go fmt
style:
! gofmt -s -l $(GO_SRC) 2>&1 | read 2>/dev/null

test:
go test -v -covermode=count -coverprofile=cover.out

lint:
golint $(GO_PKG)

# Format the code
fmt:
gofmt -s -w $(GO_SRC)

.PHONY: test vet
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
[![Build Status](https://travis-ci.org/wrouesnel/tail_exporter.svg)](https://travis-ci.org/wrouesnel/tail_exporter)
[![Coverage Status](https://coveralls.io/repos/github/wrouesnel/tail_exporter/badge.svg?branch=master)](https://coveralls.io/github/wrouesnel/tail_exporter?branch=master)
[![Go Report Card](https://goreportcard.com/badge/github.com/wrouesnel/tail_exporter)](https://goreportcard.com/report/github.com/wrouesnel/tail_exporter)

# Tail Exporter

Expand All @@ -13,3 +15,19 @@ It links against the libpcre library for faster regex'ing.
The configuration file is based on YAML. Prometheus metrics are required to
have a consistent set of labels, but metrics may be repeated in the config file
to allow multiple regexes to populate different timeseries.

## Example
Counting mail processing stages from exim:
```yaml
metric_configs:
- name: exim_mail_count
help: counter of mail processing results
type: counter
regex: '^METRICS: uuid=(\S+) result=(\S+)'
labels:
- name: uuid
value: $1
- name: result
value: $2
value: increment
```
10 changes: 0 additions & 10 deletions build

This file was deleted.

71 changes: 38 additions & 33 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package config

import (
"gopkg.in/yaml.v2"
"strings"
"strconv"
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"

"strconv"
"strings"
)

// Load parses the YAML input s into a Config.
Expand Down Expand Up @@ -45,13 +44,15 @@ type Config struct {

// Metric type definitions
type MetricType int

const (
METRIC_UNTYPED MetricType = iota
METRIC_GAUGE MetricType = iota
METRIC_GAUGE MetricType = iota
METRIC_COUNTER MetricType = iota
)

type ErrorInvalidMetricType struct {}
type ErrorInvalidMetricType struct{}

func (this ErrorInvalidMetricType) Error() string {
return "Metric type must be 'gauge' or 'counter'"
}
Expand Down Expand Up @@ -85,15 +86,16 @@ func (this *MetricType) MarshalYAML() (interface{}, error) {
}

type MetricParser struct {
Name string `yaml:"name,omitempty"`
Type MetricType `yaml:"type,omitempty"`
Help string `yaml:"help,omitempty"`
Regex Regexp `yaml:"regex,omitempty"`
Labels []LabelDef `yaml:"labels,omitempty"`
Value ValueDef `yaml:"value,omitempty"`
Name string `yaml:"name,omitempty"`
Type MetricType `yaml:"type,omitempty"`
Help string `yaml:"help,omitempty"`
Regex Regexp `yaml:"regex,omitempty"`
Labels []LabelDef `yaml:"labels,omitempty"`
Value ValueDef `yaml:"value,omitempty"`
}

type MetricParserErrorNoHelp struct {}
type MetricParserErrorNoHelp struct{}

func (this MetricParserErrorNoHelp) Error() string {
return "Metric help field cannot be empty."
}
Expand All @@ -112,14 +114,14 @@ func (this *MetricParser) UnmarshalYAML(unmarshal func(interface{}) error) error
}

type LabelDef struct {
Name string `yaml:"name,omitempty"`
Name string `yaml:"name,omitempty"`
Value LabelValueDef `yaml:"value,omitempty"`

// Optional parameters get loaded into this map.
optional map[string]string `yaml:",inline"`

// Optional parameter: specify a default value for a missing key
Default string
Default string
HasDefault bool
}

Expand All @@ -146,17 +148,18 @@ func (this *LabelDef) MarshalYAML() (interface{}, error) {
}

type LabelValueType int

const (
LVALUE_LITERAL LabelValueType = iota
LVALUE_CAPTUREGROUP LabelValueType = iota
LVALUE_LITERAL LabelValueType = iota
LVALUE_CAPTUREGROUP LabelValueType = iota
LVALUE_CAPTUREGROUP_NAMED LabelValueType = iota
)

// Defines a type which sets ascii label values
type LabelValueDef struct {
FieldType LabelValueType
Literal string
CaptureGroup int
FieldType LabelValueType
Literal string
CaptureGroup int
CaptureGroupName string
}

Expand All @@ -169,12 +172,12 @@ func (this *LabelValueDef) UnmarshalYAML(unmarshal func(interface{}) error) erro

if strings.HasPrefix(s, "$") {
// If we can match a number, assume a numbered group. If we can't, then
// assume we are refering to a capture group name. If the name is invalid
// assume we are referring to a capture group name. If the name is invalid
// then we'll fail to match but there's no easy way cross-validate with the
// PCRE module just yet.
str := strings.Trim(s, "$")
val, err := strconv.ParseInt(str, 10, 32)
if err != nil{
if err != nil {
this.FieldType = LVALUE_CAPTUREGROUP_NAMED
this.CaptureGroupName = str
} else {
Expand All @@ -200,19 +203,20 @@ func (this *LabelValueDef) MarshalYAML() (interface{}, error) {

// Value definitions for label and value fields
type ValueType int

const (
VALUE_LITERAL ValueType = iota
VALUE_CAPTUREGROUP ValueType = iota
VALUE_LITERAL ValueType = iota
VALUE_CAPTUREGROUP ValueType = iota
VALUE_CAPTUREGROUP_NAMED ValueType = iota
VALUE_INC ValueType = iota
VALUE_SUB ValueType = iota
VALUE_INC ValueType = iota
VALUE_SUB ValueType = iota
)

// Definition for numeric values which will be assigned to metrics
// ValueDef is the definition for numeric values which will be assigned to metrics
type ValueDef struct {
FieldType ValueType
Literal float64
CaptureGroup int
FieldType ValueType
Literal float64
CaptureGroup int
CaptureGroupName string
}

Expand All @@ -230,7 +234,7 @@ func (this *ValueDef) UnmarshalYAML(unmarshal func(interface{}) error) error {
// PCRE module just yet.
str := strings.Trim(s, "$")
val, err := strconv.ParseInt(str, 10, 32)
if err != nil{
if err != nil {
this.FieldType = VALUE_CAPTUREGROUP_NAMED
this.CaptureGroupName = str
} else {
Expand All @@ -246,14 +250,15 @@ func (this *ValueDef) UnmarshalYAML(unmarshal func(interface{}) error) error {
this.FieldType = VALUE_LITERAL

val, err := strconv.ParseFloat(s, 64)
if err != nil{
if err != nil {
return nil
}
this.Literal = val
}
return nil
}

// MarshalYAML implements the yaml.Marshaler interface
func (this *ValueDef) MarshalYAML() (interface{}, error) {
switch this.FieldType {
case VALUE_CAPTUREGROUP:
Expand All @@ -267,4 +272,4 @@ func (this *ValueDef) MarshalYAML() (interface{}, error) {
default:
return this.Literal, nil
}
}
}
21 changes: 13 additions & 8 deletions config/regexp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
package config

import (
"github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre"
"strings"
"fmt"
"github.com/glenn-brown/golang-pkg-pcre/src/pkg/pcre"
"gopkg.in/yaml.v2"
"strings"
)

// Regex fields which fail to parse are parsed again against this to allow using
// the full PCRE library.
// flaggedRegex fields which fail to parse are parsed again against this to
// allow using the full PCRE library.
type flaggedRegex struct {
regex string `yaml:"expr"`
flags string `yaml:"flags,omitempty"`
regex string `yaml:"expr"`
flags string `yaml:"flags,omitempty"`
}

// Regexp encapsulates a regexp.Regexp and makes it YAML marshallable.
Expand All @@ -22,16 +22,21 @@ type Regexp struct {
original flaggedRegex
}

// RegexpCompileError wraps the pcre Compile error
type RegexpCompileError struct {
*pcre.CompileError
}

func (this RegexpCompileError) Error() string {
return this.CompileError.String()
}

// RegexpFlagsError provides a useful error message when bad flags are found
// for the supplied regexp
type RegexpFlagsError struct {
badflag string
}

func (this RegexpFlagsError) Error() string {
return fmt.Sprintf("Invalid regex flag specificed: %s", this.badflag)
}
Expand Down Expand Up @@ -106,7 +111,7 @@ func NewRegexp(s flaggedRegex) (*Regexp, error) {
return nil, err
}

regex, cerr := pcre.Compile(s.regex,flags)
regex, cerr := pcre.Compile(s.regex, flags)
if cerr != nil {
return nil, RegexpCompileError{cerr}
}
Expand Down Expand Up @@ -155,4 +160,4 @@ func (re *Regexp) MarshalYAML() (interface{}, error) {
return re.original, nil
}
return nil, nil
}
}
Loading

0 comments on commit 26ae92b

Please sign in to comment.