negronicloudwatch

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

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

Go to latest
Published: Jul 26, 2016 License: GPL-3.0 Imports: 10 Imported by: 0

README

negroni-cloudwatch

GoDoc Build Status

AWS cloudwatch middleware for negroni.

Installation

go get -u github.com/cvillecsteele/negroni-cloudwatch

Usage

package main

import (
        "fmt"
        "net/http"

        "github.com/aws/aws-sdk-go/aws"
        cw "github.com/aws/aws-sdk-go/service/cloudwatch"

        "github.com/gorilla/context"
        "github.com/codegangsta/negroni"
        ncw "github.com/cvillecsteele/negroni-cloudwatch"
)

func main() {
        r := http.NewServeMux()
        r.HandleFunc(`/`, func(w http.ResponseWriter, r *http.Request) {
                put := context.Get(req, ncw.PutMetric)
                put([]*cw.MetricDatum{
                    {
                            MetricName: aws.String("MyMetric"),
                            Dimensions: []*cw.Dimension{
                                    {
                                            Name:  aws.String("ThingOne"),
                                            Value: aws.String("something"),
                                    },
                                    {
                                            Name:  aws.String("ThingTwo"),
                                            Value: aws.String("other"),
                                    },
                            },
                            Timestamp: aws.Time(time.Now()),
                            Unit:      aws.String("Count"),
                            Value:     aws.Float64(42),
                    },
                })
                w.WriteHeader(http.StatusOK)
                fmt.Fprintf(w, "success!\n")
        })

        n := negroni.New()
        n.Use(ncw.New("us-east-1", "test"))
        n.UseHandler(r)

        n.Run(":9999")
}

Documentation

Index

Constants

View Source
const PutMetric key = 0

Variables

This section is empty.

Functions

func DefaultAfter

func DefaultAfter(m *Middleware, req *http.Request, res negroni.ResponseWriter, latency time.Duration, remoteAddr string)

DefaultAfter is the default func assigned to *Middleware.After

func DefaultBefore

func DefaultBefore(m *Middleware, req *http.Request, remoteAddr string)

DefaultBefore is the default func assigned to *Middleware.Before

Types

type AfterFunc

AfterFunc is the func type called after calling the next func in the middleware chain

type BeforeFunc

type BeforeFunc func(*Middleware, *http.Request, string)

Called before handler

type Middleware

type Middleware struct {
	// CW Service
	Service *cw.CloudWatch

	// CW namespace
	Namespace string

	// Latency metric name
	LatencyMetricName string

	Before    BeforeFunc
	After     AfterFunc
	PutMetric func(data []*cw.MetricDatum)
	// contains filtered or unexported fields
}

Middleware handler

func New

func New(region, namespace string) *Middleware

func (*Middleware) ExcludeURL

func (m *Middleware) ExcludeURL(u string) error

ExcludeURL adds a new URL u to be ignored during logging. The URL u is parsed, hence the returned error

func (*Middleware) ExcludedURLs

func (m *Middleware) ExcludedURLs() []string

ExcludedURLs returns the list of excluded URLs for this middleware

func (*Middleware) ServeHTTP

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

Jump to

Keyboard shortcuts

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