84

GitHub - amalfra/gin-statsd: A Gin middleware for reporting to statsd daemon

 5 years ago
source link: https://github.com/amalfra/gin-statsd
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

gin-statsd

GitHub release Build Status GoDoc Go Report Card

A Gin middleware for reporting to statsd daemon.

Installation

You can download the middleware using

go get github.com/amalfra/gin-statsd

Usage

Next, import the package

import (
  statsdMiddleware "github.com/amalfra/gin-statsd/middleware"
)
  1. Attach middleware to all routes
  r := gin.New()
  r.Use(statsdMiddleware.New(statsdMiddleware.Options{}))

or

  1. Attach middleware to specific route
  r := gin.New()
  r.GET("/", statsdMiddleware.New(statsdMiddleware.Options{}), func(c *gin.Context) {})

By default, the middleware will send status_code and response_time stats. All stats are namespaced under statsdKey key by default. This can be configured using options.

Configuring using Options

The middleware allows configuring using Options struct. The struct with config should be passed when initializing with New method. Supported configurations are:

  • Host - statsd daemon's host; defaults to 127.0.0.1
  • Port - statsd daemon's port; defaults to 8125
  • RequestKey - the namespace for stats; defaults to statsdKey

Configuring namespace:

  r := gin.New()
  r.Use(statsdMiddleware.New(statsdMiddleware.Options{RequestKey: "myNamespace"}))

Configuring statsd host and port:

  r := gin.New()
  r.Use(statsdMiddleware.New(statsdMiddleware.Options{Host: "myhost.statsd", Port: 8089}))

Development

Questions, problems or suggestions? Please post them on the issue tracker.

You can contribute changes by forking the project and submitting a pull request. Feel free to contribute ?

UNDER MIT LICENSE

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK