fasthttpprom

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2020 License: MIT Imports: 7 Imported by: 0

README

fasthttp prometheus-middleware

Fasthttp fasthttp middleware for Prometheus

Export metrics for request duration request_duration and request count request_count

Example

using fasthttp/router

package main

import (
"log"

fasthttpprom "github.com/701search/fasthttp-prometheus-middleware"
"github.com/fasthttp/router"
"github.com/valyala/fasthttp"
)

func main() {

	r := router.New()
	p := fasthttpprom.NewPrometheus("")
	p.Use(r)

	r.GET("/health", func(ctx *fasthttp.RequestCtx) {
		ctx.SetStatusCode(200)
		ctx.SetBody([]byte(`{"status": "pass"}`))
		log.Println(string(ctx.Request.URI().Path()))
	})

	log.Println("main is listening on ", "8080")
	log.Fatal(fasthttp.ListenAndServe(":"+"8080", p.Handler))

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ListenerHandler added in v1.0.1

type ListenerHandler func(c *fasthttp.RequestCtx) string

ListenerHandler url label

type Prometheus

type Prometheus struct {
	MetricsPath string
	Handler     fasthttp.RequestHandler
	// contains filtered or unexported fields
}

Prometheus contains the metrics gathered by the instance and its path

func NewPrometheus

func NewPrometheus(subsystem string) *Prometheus

NewPrometheus generates a new set of metrics with a certain subsystem name

func (*Prometheus) Custom added in v1.0.1

func (p *Prometheus) Custom(r *router.Router)

Custom adds the middleware to a fasthttp

func (*Prometheus) HandlerFunc

func (p *Prometheus) HandlerFunc() fasthttp.RequestHandler

HandlerFunc is onion or wraper to handler for fasthttp listenandserve

func (*Prometheus) SetListenAddress

func (p *Prometheus) SetListenAddress(address string)

SetListenAddress for exposing metrics on address. If not set, it will be exposed at the same address of api that is being used

func (*Prometheus) SetListenAddressWithRouter

func (p *Prometheus) SetListenAddressWithRouter(listenAddress string, r *router.Router)

SetListenAddressWithRouter for using a separate router to expose metrics. (this keeps things like GET /metrics out of your content's access log).

func (*Prometheus) SetMetricsPath

func (p *Prometheus) SetMetricsPath(r *router.Router)

SetMetricsPath set metrics paths for Custom path

func (*Prometheus) Use

func (p *Prometheus) Use(r *router.Router)

Use adds the middleware to a fasthttp

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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