metricmware

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: MIT Imports: 4 Imported by: 0

README

Fiber Middleware for Metric

Golang Fiber Middleware to Expose zserge/metric

Metric middleware for Fiber that servers metric created HTML pages via Fiber's HTTP server. Metric exposes application metrics with a lightweight graphical UI and integrates with expvar. It is exposed by default on /debug/metrics.

See also expvar middleware and pprof middleware.

Usage

go get github.com/pilotso11/metricmware
import "github.com/pilotso11/metricmware"

app.Use(metricmware.New())

Configuration

metricmware.Config exposes one option, which is a prefix before "/debug".

Examples

Don't forget to checkout your stats at http://localhost:8000/debug/metrics

import (
    "expvar"
    "github.com/gofiber/fiber/v2"
    expvarmw "github.com/gofiber/fiber/v2/middleware/expvar"
    "github.com/zserge/metric"
    "github.com/vade-mecum/mixfi-fix/middleware/metric"
)

app := fiber.New()
app.Use(expvarmw.New())   // Recommended if you use metric with expvar
app.Use(metricmware.New())

expvar.Publish("mycounter", metric.NewCounter("5m1s", "15m30s", "1h1m"))
expvar.Publish("mystat", metric.NewGauge("30m1m", "15m30s", "1h1m"))
expvar.Publish("mylatency", metric.NewHistogram("5m1s", "15m30s", "1h1m"))

_ = app.Listen("127.0.0.1:8000")
// In my handlers
expvar.Get("mycounter").(metric.Metric).Add(1)   // To increase the counter
expvar.Get("mystat").(metric.Metric).Add(delta)  // Update the gauge 

starTime := time.Now()
// Do some work
expvar.Get("mylatency").(metric.Metric).Add(time.Since(startTime).Seconds())

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	Next: nil,
}

Functions

func New

func New(config ...Config) fiber.Handler

New creates a new metrics middleware under [prefix]/debug/metrics using the prefix from config if specified

Types

type Config

type Config struct {
	// Next defines a function to skip this middleware when returned true.
	//
	// Optional. Default: nil
	Next func(c *fiber.Ctx) bool

	// Prefix defines a URL prefix added before "/debug/pprof".
	// Note that it should start with (but not end with) a slash.
	// Example: "/federated-fiber"
	//
	// Optional. Default: ""
	Prefix string

	// Optional metrics to expose, if not specified it will take all Metric from expvar
	Exposed *map[string]metric.Metric
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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