README
¶
negroni-cloudwatch
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 ¶
type AfterFunc func(*Middleware, *http.Request, negroni.ResponseWriter, time.Duration, string)
AfterFunc is the func type called after calling the next func in the middleware chain
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)
Click to show internal directories.
Click to hide internal directories.