logstash

package module
v0.0.0-...-5069b37 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 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/jonathansp/go-metrics-logstash

Usage

package main

import (
	"log"
	"time"

	metrics "github.com/rcrowley/go-metrics"
	"github.com/jonathansp/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 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