monitor

package
v2.34.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2022 License: MIT Imports: 12 Imported by: 214

README

Monitor

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

Warning: Monitor is still in beta, API might change in the future!

Signatures
func New() fiber.Handler
Examples

Import the middleware package and assign it to a route.

package main

import (
	"log"

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

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

	app.Get("/metrics", monitor.New(monitor.Config{Title: "MyService Metrics Page"}))

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

You can also access the API endpoint with curl -X GET -H "Accept: application/json" http://localhost:3000/metrics which returns:

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

Config

// Config defines the config for middleware.
type Config struct {
	// Metrics page title
	//
	// Optional. Default: "Fiber Monitor"
	Title string

	// Refresh period
	//
	// Optional. Default: 3 seconds
	Refresh time.Duration

	// To disable serving HTML, you can make true this option.
	//
	// Optional. Default: false
	APIOnly bool

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

Default Config

var ConfigDefault = Config{
	Title:   "Fiber Monitor",
	Refresh: 3 * time.Second,
	APIOnly: false,
	Next:    nil,
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	Title:   defaultTitle,
	Refresh: defaultRefresh,
	APIOnly: false,
	Next:    nil,
	// contains filtered or unexported fields
}

Functions

func New

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

New creates a new middleware handler

Types

type Config added in v2.19.0

type Config struct {
	// Metrics page title
	//
	// Optional. Default: "Fiber Monitor"
	Title string

	// Refresh period
	//
	// Optional. Default: 3 seconds
	Refresh time.Duration

	// Whether the service should expose only the monitoring API.
	//
	// Optional. Default: false
	APIOnly bool

	// Next defines a function to skip this middleware when returned true.
	//
	// Optional. Default: nil
	Next func(c *fiber.Ctx) bool
	// contains filtered or unexported fields
}

Config defines the config for middleware.

Jump to

Keyboard shortcuts

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