diff --git a/contrib_versioned_docs/version-fiberi18n_v2.x.x/README.md b/contrib_versioned_docs/version-fiberi18n_v2.x.x/README.md index 9608633168e..264208e161d 100644 --- a/contrib_versioned_docs/version-fiberi18n_v2.x.x/README.md +++ b/contrib_versioned_docs/version-fiberi18n_v2.x.x/README.md @@ -29,6 +29,7 @@ Repository for third party middlewares with dependencies. * [JWT](./jwt/README.md) * [Loadshed](./loadshed/README.md) * [NewRelic](./fibernewrelic/README.md) +* [Monitor](./monitor/README.md) * [Open Policy Agent](./opafiber/README.md) * [Otelfiber (OpenTelemetry)](./otelfiber/README.md) * [Paseto](./paseto/README.md) diff --git a/contrib_versioned_docs/version-fiberi18n_v2.x.x/fiberzap/README.md b/contrib_versioned_docs/version-fiberi18n_v2.x.x/fiberzap/README.md index 8cbf80517b6..5d077d203bd 100644 --- a/contrib_versioned_docs/version-fiberi18n_v2.x.x/fiberzap/README.md +++ b/contrib_versioned_docs/version-fiberi18n_v2.x.x/fiberzap/README.md @@ -59,6 +59,7 @@ import ( func main() { app := fiber.New() logger, _ := zap.NewProduction() + defer logger.Sync() app.Use(fiberzap.New(fiberzap.Config{ Logger: logger, @@ -103,9 +104,12 @@ import ( func main() { app := fiber.New() - log.SetLogger(fiberzap.NewLogger(fiberzap.LoggerConfig{ + logger := fiberzap.NewLogger(fiberzap.LoggerConfig{ ExtraKeys: []string{"request_id"}, - })) + }) + log.SetLogger(logger) + defer logger.Sync() + app.Use(func(c *fiber.Ctx) error { ctx := context.WithValue(c.UserContext(), "request_id", "123") c.SetUserContext(ctx) diff --git a/contrib_versioned_docs/version-fiberi18n_v2.x.x/monitor/README.md b/contrib_versioned_docs/version-fiberi18n_v2.x.x/monitor/README.md new file mode 100644 index 00000000000..0dd78fc7d93 --- /dev/null +++ b/contrib_versioned_docs/version-fiberi18n_v2.x.x/monitor/README.md @@ -0,0 +1,84 @@ +--- +id: monitor +--- + +# Monitor + +![Release](https://img.shields.io/github/v/tag/gofiber/contrib?filter=monitor*) +![Discord](https://img.shields.io/discord/704680098577514527?style=flat&label=%F0%9F%92%AC%20discord&color=00ACD7) +![Test](https://github.com/gofiber/contrib/workflows/Tests/badge.svg) +![Security](https://github.com/gofiber/contrib/workflows/Security/badge.svg) +![Linter](https://github.com/gofiber/contrib/workflows/Linter/badge.svg) + +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) + +![](https://i.imgur.com/nHAtBpJ.gif) + +## Install + +This middleware supports Fiber v3. + +``` +go get -u github.com/gofiber/fiber/v3 +go get -u github.com/gofiber/contrib/monitor +``` + +### Signature + +```go +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/chart.js@2.9/dist/Chart.bundle.min.js` | + +### Example + +```go +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 + +```go +var ConfigDefault = Config{ + Title: defaultTitle, + Refresh: defaultRefresh, + FontURL: defaultFontURL, + ChartJsURL: defaultChartJSURL, + CustomHead: defaultCustomHead, + APIOnly: false, + Next: nil, +} +``` diff --git a/contrib_versioned_docs/version-fiberi18n_v2.x.x/otelfiber/README.md b/contrib_versioned_docs/version-fiberi18n_v2.x.x/otelfiber/README.md index 5d3a215b4b4..200a05c5649 100644 --- a/contrib_versioned_docs/version-fiberi18n_v2.x.x/otelfiber/README.md +++ b/contrib_versioned_docs/version-fiberi18n_v2.x.x/otelfiber/README.md @@ -34,17 +34,18 @@ otelfiber.Middleware(opts ...otelfiber.Option) fiber.Handler You can configure the middleware using functional parameters -| Function | Argument Type | Description | Default | -| :------------------ | :-------------------------------- | :--------------------------------------------------------------------------------- | :-------------------------------------------------------------------- | -| `WithNext` | `func(*fiber.Ctx) bool` | Define a function to skip this middleware when returned true .| nil | -| `WithTracerProvider` | `oteltrace.TracerProvider` | Specifies a tracer provider to use for creating a tracer. | nil - the global tracer provider is used | -| `WithMeterProvider` | `otelmetric.MeterProvider` | Specifies a meter provider to use for reporting. | nil - the global meter provider is used | -| `WithPort` | `int` | Specifies the value to use when setting the `net.host.port` attribute on metrics/spans. | Defaults to (`80` for `http`, `443` for `https`) | -| `WithPropagators` | `propagation.TextMapPropagator` | Specifies propagators to use for extracting information from the HTTP requests. | If none are specified, global ones will be used | -| `WithServerName` | `string` | Specifies the value to use when setting the `http.server_name` attribute on metrics/spans. | - | -| `WithSpanNameFormatter` | `func(*fiber.Ctx) string` | Takes a function that will be called on every request and the returned string will become the span Name. | Default formatter returns the route pathRaw | -| `WithCustomAttributes` | `func(*fiber.Ctx) []attribute.KeyValue` | Define a function to add custom attributes to the span. | nil | -| `WithCollectClientIP` | `bool` | Specifies whether to collect the client's IP address from the request. | true | +| Function | Argument Type | Description | Default | +| :------------------------ | :-------------------------------- | :--------------------------------------------------------------------------------- | :-------------------------------------------------------------------- | +| `WithNext` | `func(*fiber.Ctx) bool` | Define a function to skip this middleware when returned true .| nil | +| `WithTracerProvider` | `oteltrace.TracerProvider` | Specifies a tracer provider to use for creating a tracer. | nil - the global tracer provider is used | +| `WithMeterProvider` | `otelmetric.MeterProvider` | Specifies a meter provider to use for reporting. | nil - the global meter provider is used | +| `WithPort` | `int` | Specifies the value to use when setting the `net.host.port` attribute on metrics/spans. | Defaults to (`80` for `http`, `443` for `https`) | +| `WithPropagators` | `propagation.TextMapPropagator` | Specifies propagators to use for extracting information from the HTTP requests. | If none are specified, global ones will be used | +| `WithServerName` | `string` | Specifies the value to use when setting the `http.server_name` attribute on metrics/spans. | - | +| `WithSpanNameFormatter` | `func(*fiber.Ctx) string` | Takes a function that will be called on every request and the returned string will become the span Name. | Default formatter returns the route pathRaw | +| `WithCustomAttributes` | `func(*fiber.Ctx) []attribute.KeyValue` | Define a function to add custom attributes to the span. | nil | +| `WithCustomMetricAttributes` | `func(*fiber.Ctx) []attribute.KeyValue` | Define a function to add custom attributes to the metrics. | nil | +| `WithCollectClientIP` | `bool` | Specifies whether to collect the client's IP address from the request. | true | ## Usage diff --git a/contrib_versioned_docs/version-fiberi18n_v2.x.x/socketio/README.md b/contrib_versioned_docs/version-fiberi18n_v2.x.x/socketio/README.md index 6e64c79cb34..c4830c3161c 100644 --- a/contrib_versioned_docs/version-fiberi18n_v2.x.x/socketio/README.md +++ b/contrib_versioned_docs/version-fiberi18n_v2.x.x/socketio/README.md @@ -1,3 +1,4 @@ +--- id: socketio --- diff --git a/contrib_versioned_docs/version-fiberi18n_v2.x.x/websocket/README.md b/contrib_versioned_docs/version-fiberi18n_v2.x.x/websocket/README.md index 3c7214ab0ba..fef6219e258 100644 --- a/contrib_versioned_docs/version-fiberi18n_v2.x.x/websocket/README.md +++ b/contrib_versioned_docs/version-fiberi18n_v2.x.x/websocket/README.md @@ -142,4 +142,12 @@ cfg := Config{ app.Get("/ws/:id", websocket.New(func(c *websocket.Conn) {}, cfg)) -``` \ No newline at end of file +``` + +## Note for WebSocket subprotocols + +The config `Subprotocols` only helps you negotiate subprotocols and sets a `Sec-Websocket-Protocol` header if it has a suitable subprotocol. For more about negotiates process, check the comment for `Subprotocols` in [fasthttp.Upgrader](https://pkg.go.dev/github.com/fasthttp/websocket#Upgrader) . + +All connections will be sent to the handler function no matter whether the subprotocol negotiation is successful or not. You can get the selected subprotocol from `conn.Subprotocol()`. + +If a connection includes the `Sec-Websocket-Protocol` header in the request but the protocol negotiation fails, the browser will immediately disconnect the connection after receiving the upgrade response. diff --git a/contrib_versioned_sidebars/version-fiberi18n_v2.x.x-sidebars.json b/contrib_versioned_sidebars/version-fiberi18n_v2.x.x-sidebars.json index caea0c03ba6..cbf35feb3b7 100644 --- a/contrib_versioned_sidebars/version-fiberi18n_v2.x.x-sidebars.json +++ b/contrib_versioned_sidebars/version-fiberi18n_v2.x.x-sidebars.json @@ -1,5 +1,5 @@ { - "tutorialSidebar": [ + "left_sidebar": [ { "type": "autogenerated", "dirName": "."