Skip to content

Latest commit

 

History

History
84 lines (62 loc) · 3.49 KB

README.md

File metadata and controls

84 lines (62 loc) · 3.49 KB
id
monitor

Monitor

Release Discord Test Security Linter

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

Install

This middleware supports Fiber v3.

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

Signature

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

Config

Property Type Description Default
Title string Metrics page title. Fiber Monitor
Refresh time.Duration Refresh period. 3 seconds
APIOnly bool Whether the service should expose only the montioring API. false
Next func(c *fiber.Ctx) bool Define a function to add custom fields. nil
CustomHead string Custom HTML code to Head Section(Before End). empty
FontURL string FontURL 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
ChartJsURL string ChartJsURL 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/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"))
}

Default Config

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