restprometheus

package module
v0.0.0-...-9bc87d6 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2016 License: MIT Imports: 5 Imported by: 0

README

go-json-rest-prometheus

Prometheus middleware for go-json-rest

This is heavily influenced by negroni-prometheus. I wanted to have the same functionality on go-json-rest.

###A note on the Handler. go-json-rest rest.HandlerFunc it not compatible with http.HandlerFunc because the ResponseWriter is different (see this issue https://github.com/ant0ine/go-json-rest/issues/192 so the Handler definition on the endpoint is awkward.

Example

This example can be found in the example directory.

package main

import (
	"log"
	"net/http"

	"github.com/ant0ine/go-json-rest/rest"
	"github.com/prometheus/client_golang/prometheus"
	"github.com/telmo/go-json-rest-prometheus"
)

func main() {
	api := rest.NewApi()
	api.Use(&restprometheus.PromMiddleware{})
	api.Use(rest.DefaultDevStack...)
	router, err := rest.MakeRouter(
		rest.Get("/metrics", func(w rest.ResponseWriter, r *rest.Request) {
			prometheus.InstrumentHandler("prometheus", prometheus.Handler())(w.(http.ResponseWriter), r.Request)
		}),
	)
	if err != nil {
		log.Fatal(err)
	}
	api.SetApp(router)
	log.Fatal(http.ListenAndServe(":8080", api.MakeHandler()))
}
Thanks/Contributors
  • hydroflame - For his help converting http.HandlerFunc to rest.HandlerFunc and all the go magic I am learning from him
TODO
  • Add custom bucket definitions
  • Learn more go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PromMiddleware

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

Middleware is a handler that exposes prometheus metrics for the number of requests, the latency and the response size, partitioned by status code, method and HTTP path.

func (*PromMiddleware) MiddlewareFunc

func (mw *PromMiddleware) MiddlewareFunc(h rest.HandlerFunc) rest.HandlerFunc

NewMiddleware returns a new prometheus Middleware handler.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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