logstash

package module
v0.0.0-...-8a194c8 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2018 License: MIT Imports: 8 Imported by: 0

README

go-metrics logstash Build Status GoDoc

This package provides a reporter for the go-metrics library that will post the metrics to logstash. This library is based on go-metrics-datadog.

Installation

go get -u github.com/rcrowley/go-metrics
go get -u github.com/globocom/go-metrics-logstash

Usage

package main

import (
	"log"
	"time"

	metrics "github.com/rcrowley/go-metrics"
	"github.com/globocom/go-metrics-logstash"
)

func main() {
	registry := metrics.NewRegistry()

	metrics.RegisterDebugGCStats(registry)
	metrics.RegisterRuntimeMemStats(registry)

	reporter, err := logstash.NewReporter(
		registry,               // go-metrics registry, or nil
		"127.0.0.1:1984",       // logstash UDP address,
		map[string]interface{}{ // default values to be sent at each flush
			"client": "my-app",
		}
	)
	if err != nil {
		log.Fatal(err)
	}

	go metrics.CaptureDebugGCStats(registry, time.Second * 5)
	go metrics.CaptureRuntimeMemStats(registry, time.Second * 5)
	go reporter.FlushEach(time.Second * 10)

}

License

Distributed under the MIT license. See LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Measure

type Measure map[string]interface{}

Measure is a map that represents the contract to be send to measures

func NewMeasure

func NewMeasure(name string, defaultValues map[string]interface{}) *Measure

NewMeasure creates a new Measure and adds name and default information to the structure

func (*Measure) AddCounter

func (m *Measure) AddCounter(counter metrics.Counter)

AddCounter adds a counter to the structure

func (*Measure) AddGauge

func (m *Measure) AddGauge(gauge metrics.Gauge)

AddGauge adds an int gauge to the structure

func (*Measure) AddGaugeFloat64

func (m *Measure) AddGaugeFloat64(gauge metrics.GaugeFloat64)

AddGaugeFloat64 adds an int gauge64 to the structure

func (*Measure) AddHistogram

func (m *Measure) AddHistogram(histogram metrics.Histogram, percentiles []float64)

AddHistogram adds a histogram to the structure

func (*Measure) AddMeter

func (m *Measure) AddMeter(meter metrics.Meter)

AddMeter adds a meter to the structure

func (*Measure) AddTimer

func (m *Measure) AddTimer(timer metrics.Timer, percentiles []float64)

AddTimer adds a timer to the structure

type Reporter

type Reporter struct {
	// Registry map is used to hold metrics that will be sent to logstash.
	Registry metrics.Registry
	// Conn is a UDP connection to logstash.
	Conn *net.UDPConn
	// DefaultValues are the values that will be sent in all submits.
	DefaultValues map[string]interface{}
	Version       string
	// Percentiles to be sent on histograms and timers
	Percentiles []float64
}

Reporter represents a metrics registry.

func NewReporter

func NewReporter(r metrics.Registry, addr string, defaultValues map[string]interface{}) (*Reporter, error)

NewReporter creates a new Reporter for the register r, with an UDP client to the given logstash address addr and with the given default values. If defaultValues is nil, only the metrics will be sent.

func (*Reporter) FlushEach

func (r *Reporter) FlushEach(interval time.Duration)

FlushEach is a blocking exporter function which reports metrics in the registry. Designed to be used in a goroutine: go reporter.FlushEach()

func (*Reporter) FlushOnce

func (r *Reporter) FlushOnce() error

FlushOnce submits a snapshot of the registry.

Jump to

Keyboard shortcuts

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