Monitoring

Using the monitoring middleware of Fiber, you can report the server's metrics, inspired by express-status-monitor, which can monitor CPU, memory, request response time, concurrent connection count, and more in real time.

Note: The Monitor is still in the testing phase, and the API may change in the future!

Signature

func New() fiber.Handler

Example

Import the middleware package of the Fiber web framework

import (
  "github.com/gofiber/fiber/v2"
  "github.com/gofiber/fiber/v2/middleware/monitor"
)

After initializing your Fiber application, you can use the following options:

// Initialize with default configuration (assign middleware to /metrics)
app.Get("/metrics", monitor.New())

// Or extend with custom configuration
// Assign middleware to /metrics
// and change the title to "MyService Metrics Page"
app.Get("/metrics", monitor.New(monitor.Config{Title: "MyService Metrics Page"}))

You can also access the API endpoint using curl -X GET -H "Accept: application/json" http://localhost:3000/metrics, which will return:

{"pid":{ "cpu":0.4568381746582226, "ram":20516864,   "conns":3 },
 "os": { "cpu":8.759124087593099,  "ram":3997155328, "conns":44,
    "total_ram":8245489664, "load_avg":0.51 }}

Configuration

Property Type Description Default
Title string Title of the metrics page "Fiber Monitor"
Refresh time.Duration Refresh period 3 seconds
APIOnly bool Whether the service only exposes monitoring API false
Next func(*fiber.Ctx) bool Next defines a function that skips this middleware when returning true nil
CustomHead string Custom HTML code to add to the header (ending before) Empty
FontURL string Font resource path or URL specified by FontURL https://fonts.googleapis.com/css2?family=Roboto:wght@400;900&display=swap
ChartJsURL string ChartJS library path or URL specified by ChartJsURL https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.bundle.min.js

Default Configuration

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