negronistatsd

package module
v0.0.0-...-c08331d Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2017 License: Apache-2.0 Imports: 7 Imported by: 0

README

negroni-statsd

GoDoc

Statsd middleware for Negroni.

At jobandtalent we use statsd for tracking a lot of event that happen with our service, this middleware will help you to track some of those that can be globally tracked. At the moment we are tracking two things:

  • time spent in a request. We will track the time between the requests get to the middleware until it cames back. Please, check the lavarel documentation to see how middlewares work on Negroni.

    For example, a request to /api/users will be tracked (using jt.yourservice as prefix) with the key: jt.yourservice.api.users.

  • status codes of the responses. This stat is just a counter of the status code received and it will be tracked as: jt.yourservice.request.200, or 201, etc...

Take care of...

  • All the requests sent to statsd are going to be sent using UDP so you can loss some of them in favour of performance.
  • The requests are going to be sent asynchronously without any waiting group, or similar. This means that if you stop your service ungracefully it's possible that some of them were not sent yet.

Using it

package main

import (
    "github.com/codegangsta/negroni"
    "github.com/jobandtalent/negroni-statsd"
)

func main() {
    statsdURI := "localhost:1234"
    prefix := "jt.yourservice"
    n := negroni.New(negronistatsd.NewMiddleware(statsdURI, prefix))
    ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Middleware

type Middleware struct {
	// contains filtered or unexported fields
}

Middleware stores the prefix and the statsd client

func NewMiddleware

func NewMiddleware(uri, prefix string) *Middleware

NewMiddleware returns a middleware struct with a configured statsd client

func (Middleware) ServeHTTP

func (m Middleware) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)

func (Middleware) SetFilter

func (m Middleware) SetFilter(f func(string) (bool, string))

SetFilter - filter what should be sent to metrics

func (Middleware) SetGobalMetrics

func (m Middleware) SetGobalMetrics(s string, global bool)

SetGobalMetrics - if global number of req is recorded

Jump to

Keyboard shortcuts

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