ghealth

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2017 License: MIT Imports: 6 Imported by: 0

README

gin-health

This middleware simplifies stats reporting via gocraft/health toolset.

Check out docs at GoDoc.

Documentation

Overview

Package ghealth provides a Gin middleware to gocraft/health performance monitoring toolkit.

By default it creates StatsD sink, falling back to stdout if error happened or StatsD server was not provided.

Recovery is supported and panics are sent as general errors with request's URI.

Example

func main() {
	// Standard router initialization
	router := gin.Default()

	// First, you need to create a new stream...

	// Simplest sink, stdout only
	hstream := ghealth.NewStream("", "", "")

	// STDOUT and JSON sinks; creates independent http server on port 5020
	hstream := ghealth.NewStream("", "", "127.0.0.1:5020")

	// StatsD and JSON sinks (StatsDSinkOptions can be nil)
	hstream := ghealth.NewStream("statsd.server:5000", &health.StatsDSinkOptions{Prefix:"yourappname"}, "127.0.0.1:5020")

	// It's a standard *health.Stream, so you can do anything you want!
	hstream.AddSink(&health.WriterSink{os.Stdout})

	router.Use(ghealth.Health(hstream))
	...
}

var someRoute gin.HandlerFunc = func(c *gin.Context) {
	// Retrieve a job object
	job := ghealth.Job(c, "some_route")

	// It's a *health.Job, read health godoc for more info :)
	job.Event("some_event")
}

At the moment it wasn't heavily tested. I'm still not sure how health implements concurrency, but as long as stream is thread-safe - ghealth should be, too.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Health

func Health(stream *health.Stream, debug bool) gin.HandlerFunc

Use this method to inject the middleware and recovery. Debug mode disables panic recovery, so all the panic messages would be logged to stderr properly.

func Job

func Job(c *gin.Context, name string) *health.Job

Job creates a new job with given name.

c: current Gin context.

name: Job's name.

func NewStream

func NewStream(statsd string, statsdOpts *health.StatsDSinkOptions, serversink string) *health.Stream

NewStream initializes health sink to statsd using supplied statsd address (IP:PORT) and appname. Falls back to stdout if none supplied. Also creates Json sink for healthd at supplied address (serversink) if not empty.

statsd: StatsD address and port.

statsdOpts: StatsD options (can be nil, use .Prefix to set an application name if needed)

serversink: Bind address for Json sink, empty if not needed.

func TimeSince

func TimeSince(t time.Time) int64

TimeSince is a little helper over time.Time.TimeSince which returns the interval in nanoseconds, suitable for feeding to job.Timing.

Types

This section is empty.

Jump to

Keyboard shortcuts

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