github.com/gofiber/fiber/v2@v2.47.0/docs/api/middleware/monitor.md (about)

     1  ---
     2  id: monitor
     3  title: Monitor
     4  ---
     5  
     6  Monitor middleware for [Fiber](https://github.com/gofiber/fiber) that reports server metrics, inspired by [express-status-monitor](https://github.com/RafalWilinski/express-status-monitor)
     7  
     8  :::caution
     9  
    10  Monitor is still in beta, API might change in the future!
    11  
    12  :::
    13  
    14  ![](https://i.imgur.com/nHAtBpJ.gif)
    15  
    16  ### Signatures
    17  ```go
    18  func New() fiber.Handler
    19  ```
    20  
    21  ### Examples
    22  Import the middleware package that is part of the Fiber web framework
    23  
    24  ```go
    25  import (
    26    "github.com/gofiber/fiber/v2"
    27    "github.com/gofiber/fiber/v2/middleware/monitor"
    28  )
    29  ```
    30  
    31  After you initiate your Fiber app, you can use the following possibilities:
    32  ```go
    33  // Initialize default config (Assign the middleware to /metrics)
    34  app.Get("/metrics", monitor.New())
    35  
    36  // Or extend your config for customization
    37  // Assign the middleware to /metrics
    38  // and change the Title to `MyService Metrics Page`
    39  app.Get("/metrics", monitor.New(monitor.Config{Title: "MyService Metrics Page"}))
    40  ```
    41  You can also access the API endpoint with
    42  `curl -X GET -H "Accept: application/json" http://localhost:3000/metrics` which returns:
    43  ```json
    44  {"pid":{ "cpu":0.4568381746582226, "ram":20516864,   "conns":3 },
    45   "os": { "cpu":8.759124087593099,  "ram":3997155328, "conns":44,
    46      "total_ram":8245489664, "load_avg":0.51 }}
    47  ```
    48  
    49  ## Config
    50  
    51  ```go
    52  // Config defines the config for middleware.
    53  type Config struct {
    54  	// Metrics page title
    55  	//
    56  	// Optional. Default: "Fiber Monitor"
    57  	Title string
    58  
    59  	// Refresh period
    60  	//
    61  	// Optional. Default: 3 seconds
    62  	Refresh time.Duration
    63  
    64  	// Whether the service should expose only the monitoring API.
    65  	//
    66  	// Optional. Default: false
    67  	APIOnly bool
    68  
    69  	// Next defines a function to skip this middleware when returned true.
    70  	//
    71  	// Optional. Default: nil
    72  	Next func(c *fiber.Ctx) bool
    73  
    74  	// Custom HTML Code to Head Section(Before End)
    75  	//
    76  	// Optional. Default: empty
    77  	CustomHead string
    78  
    79  	// FontURL for specify font resource path or URL . also you can use relative path
    80  	//
    81  	// Optional. Default: https://fonts.googleapis.com/css2?family=Roboto:wght@400;900&display=swap
    82  	FontURL string
    83  
    84  	// ChartJsURL for specify ChartJS library  path or URL . also you can use relative path
    85  	//
    86  	// Optional. Default: https://cdn.jsdelivr.net/npm/chart.js@2.9/dist/Chart.bundle.min.js
    87  	ChartJsURL string
    88  
    89  	index string
    90  }
    91  ```
    92  
    93  ## Default Config
    94  
    95  ```go
    96  var ConfigDefault = Config{
    97  	Title:      defaultTitle,
    98  	Refresh:    defaultRefresh,
    99  	FontURL:    defaultFontURL,
   100  	ChartJsURL: defaultChartJSURL,
   101  	CustomHead: defaultCustomHead,
   102  	APIOnly:    false,
   103  	Next:       nil,
   104  	index: newIndex(viewBag{
   105  		defaultTitle,
   106  		defaultRefresh,
   107  		defaultFontURL,
   108  		defaultChartJSURL,
   109  		defaultCustomHead,
   110  	}),
   111  }
   112  ```