Skip to main content
Version: v3_casbin_v2.x.x

Monitor

Release Discord Test

Monitor middleware for Fiber that reports server metrics, inspired by express-status-monitor

Compatible with Fiber v3.

Go version support

We only support the latest two versions of Go. Visit https://go.dev/doc/devel/release for more information.

Install

go get -u github.com/gofiber/fiber/v3
go get -u github.com/gofiber/contrib/v3/monitor

Signature

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

Config

PropertyTypeDescriptionDefault
TitlestringMetrics page title.Fiber Monitor
Refreshtime.DurationRefresh period.3 seconds
APIOnlyboolWhether the service should expose only the montioring API.false
Nextfunc(c fiber.Ctx) boolDefine a function to skip this middleware when returned true.nil
CustomHeadstringCustom HTML code to Head Section(Before End).empty
FontURLstringFontURL for specilt font resource path or URL. also you can use relative path.https://fonts.googleapis.com/css2?family=Roboto:wght@400;900&display=swap
ChartJsURLstringChartJsURL for specilt chartjs library, path or URL, also you can use relative path.https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.bundle.min.js

Example

package main

import (
"log"

"github.com/gofiber/fiber/v3"
"github.com/gofiber/contrib/v3/monitor"
)

func main() {
app := fiber.New()

// Initialize default config (Assign the middleware to /metrics)
app.Get("/metrics", monitor.New())

// Or extend your config for customization
// Assign the middleware to /metrics
// and change the Title to `MyService Metrics Page`
app.Get("/metrics", monitor.New(monitor.Config{Title: "MyService Metrics Page"}))

log.Fatal(app.Listen(":3000"))
}

Counting all application requests

The dashboard's "Total Requests" metric counts every request that passes through the monitor handler. When the middleware is mounted on a single route (as in the example above), it only counts hits on the monitor endpoint itself. To make the counter reflect the traffic of the whole application, mount it app-wide and use Next to limit the dashboard to a dedicated path:

app.Use(monitor.New(monitor.Config{
Next: func(c fiber.Ctx) bool {
// Requests to all other paths are counted and passed through.
return c.Path() != "/metrics"
},
}))

Default Config

var ConfigDefault = Config{
Title: defaultTitle,
Refresh: defaultRefresh,
FontURL: defaultFontURL,
ChartJsURL: defaultChartJSURL,
CustomHead: defaultCustomHead,
APIOnly: false,
Next: nil,
}