gcrwavefront

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2020 License: MIT Imports: 8 Imported by: 6

README

gcr-wavefront

Go Report Card Godoc GitHub GitHub tag (latest SemVer)

gcr-wavefront is an HTTP middleware to emit Google Cloud Run metrics to Wavefront.

Prerequisites

To use this HTTP middleware, you'll need to have

Installation

Using go get

go get github.com/retgits/gcr-wavefront

Usage

To start, you'll need to initialize the Wavefront emitter:

// Set configuration parameters
wfconfig := &gcrwavefront.WavefrontConfig{
    Server:        "https://<INSTANCE>.wavefront.com",
    Token:         "my-api-key",
    BatchSize:     10000,
    MaxBufferSize: 50000,
    FlushInterval: 1,
    Source:        "my-app",
    MetricPrefix:  "my.awesome.app",
    PointTags:     make(map[string]string),
}

// Make sure the sender is configured and initialized
err := wfconfig.ConfigureSender()
if err != nil {
    panic(err)
}

// Wrap your handler
http.HandleFunc("/", wfconfig.WrapHandlerFunc(handler))

A complete sample app can be found in the examples folder

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

See the LICENSE file in the repository

Documentation

Index

Constants

View Source
const (
	// ErrCreateSender in case any errors occur while creating the Wavefront Direct Sender
	ErrCreateSender = "error creating wavefront sender: %s"
	// DebugServerName has the server name to set when you want to print things to the log instead of sending data to Wavefront
	DebugServerName = "debug"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type WFStatusRecorder

type WFStatusRecorder struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func (*WFStatusRecorder) Write

func (rec *WFStatusRecorder) Write(payload []byte) (int, error)

func (*WFStatusRecorder) WriteHeader

func (rec *WFStatusRecorder) WriteHeader(code int)

type WavefrontConfig

type WavefrontConfig struct {
	// Wavefront URL of the form https://<INSTANCE>.wavefront.com.
	// Setting the server to debug will print the metrics to a log instead of sending them to Wavefront
	Server string
	// Wavefront API token with direct data ingestion permission.
	Token string
	// Max batch of data sent per flush interval.
	BatchSize int
	// Max batch of data sent per flush interval.
	MaxBufferSize int
	// Interval (in seconds) at which to flush data to Wavefront.
	FlushInterval int
	// Map of Key-Value pairs (strings) associated with each data point sent to Wavefront.
	PointTags map[string]string
	// Name of the app that emits metrics.
	Source string
	// Prefix added to all metrics
	MetricPrefix string
}

WavefrontConfig configures the direct ingestion sender to Wavefront.

func (*WavefrontConfig) ConfigureSender

func (w *WavefrontConfig) ConfigureSender() error

ConfigureSender ...

func (*WavefrontConfig) WrapFastHTTPRequest added in v0.3.0

func (wc *WavefrontConfig) WrapFastHTTPRequest(f fasthttp.RequestHandler) fasthttp.RequestHandler

WrapFastHTTPRequest is the wrapper needed for use with the fasthttp project (https://github.com/valyala/fasthttp)

func (*WavefrontConfig) WrapHTTPHandle added in v0.2.0

func (wc *WavefrontConfig) WrapHTTPHandle(f httprouter.Handle) httprouter.Handle

WrapHTTPHandle is the wrapper needed for use with the httprouter project (https://github.com/julienschmidt/httprouter)

func (*WavefrontConfig) WrapHandlerFunc

func (wc *WavefrontConfig) WrapHandlerFunc(f http.HandlerFunc) http.HandlerFunc

WrapHandlerFunc is the wrapper needed for use with the net/http package

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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