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 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.
Types ¶
This section is empty.