metrics

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2018 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

Package metrics provides a simple dummy StatsD logging server for local development

Adapted from http://lee.hambley.name/2013/01/26/dirt-simple-statsd-server-for-local-development.html

Index

Constants

This section is empty.

Variables

View Source
var DefaultAddress = ":8125"

DefaultAddress to listen for metrics on

View Source
var DefaultOutput io.Writer = os.Stdout

DefaultOutput where to output the logs

Functions

func WithFormatter

func WithFormatter(formatter MetricFormatter) func(*server)

WithFormatter is is provided as an option to New to specify a custom formatter usage:

statsdLogger.New("0.0.0.0:8125", WithFormatter(myCustomFormatter))

func WithWriter

func WithWriter(output io.Writer) func(*server)

WithWriter is is provided as an option to New to specify a custom io.Writer to output logs usage:

statsdLogger.New("0.0.0.0:8125", WithWriter(os.Stderr))

Types

type Metric

type Metric struct {
	Name  string
	Value string
	Tags  string
}

Metric is an intermediate representation of a raw statsd metric for easier presentation

func Parse

func Parse(rawMetric string) (metric Metric)

Parse takes a raw statsd metric and returns a populated Metric

type MetricFormatter

type MetricFormatter interface {
	// Format a metric
	Format(metric Metric) string
}

MetricFormatter formats metrics as a string for logging

var DefaultFormatter MetricFormatter = colorFormatter{}

DefaultFormatter provides output format for metrics

type Server

type Server interface {
	// Listen starts server listening on provided UDP address
	Listen() error

	// Close stops the server from listening for metrics
	Close() error
}

Server listens for statsd metrics, and logs them to the console for development

func NewServer

func NewServer(address string, options ...func(*server)) (Server, error)

NewServer returns a local statsd logging server which logs to statsdLogger.DefaultOutput and is formatted with statsdLogger.DefaultFormatter

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL