### Install Fiberprometheus v2 Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Install the Fiber framework and the fiberprometheus middleware using go get. Ensure you are using Go 1.22 or above. ```bash go get -u github.com/gofiber/fiber/v2 go get -u github.com/ansrivas/fiberprometheus/v2 ``` -------------------------------- ### Example Usage of Fiberprometheus v2 Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Demonstrates how to integrate the fiberprometheus middleware into a Fiber application. Configure service name, metrics endpoint, and optionally skip paths or ignore status codes. ```go package main import ( "github.com/ansrivas/fiberprometheus/v2" "github.com/gofiber/fiber/v2" ) func main() { app := fiber.New() // This here will appear as a label, one can also use // fiberprometheus.NewWith(servicename, namespace, subsystem ) // or // labels := map[string]string{"custom_label1":"custom_value1", "custom_label2":"custom_value2"} // fiberprometheus.NewWithLabels(labels, namespace, subsystem ) prometheus := fiberprometheus.New("my-service-name") prometheus.RegisterAt(app, "/metrics") prometheus.SetSkipPaths([]string{"/ping"}) // Optional: Remove some paths from metrics prometheus.SetIgnoreStatusCodes([]int{401, 403, 404}) // Optional: Skip metrics for these status codes app.Use(prometheus.Middleware) app.Get("/", func(c *fiber.Ctx) error { return c.SendString("Hello World") }) app.Get("/ping", func(c *fiber.Ctx) error { return c.SendString("pong") }) app.Post("/some", func(c *fiber.Ctx) error { return c.SendString("Welcome!") }) app.Listen(":3000") } ``` -------------------------------- ### GET /metrics Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Exposes the collected Prometheus metrics for the application. ```APIDOC ## GET /metrics ### Description Exposes the Prometheus metrics endpoint for the Fiber application. This endpoint is registered using the `RegisterAt` method. ### Method GET ### Endpoint /metrics ### Response #### Success Response (200) - **Content-Type** (text/plain) - Prometheus metrics format (e.g., http_requests_total, http_request_duration_seconds, http_requests_in_progress_total) ``` -------------------------------- ### Set Skipped Paths Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Specifies a list of URL paths that should be excluded from metrics collection. For example, health check or ping endpoints. ```go func (ps *FiberPrometheus) SetSkipPaths(paths []string) ``` -------------------------------- ### Create FiberPrometheus with Custom Registry Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Initializes a new FiberPrometheus instance, allowing for a custom prometheus.Registerer, service name, namespace, subsystem, and constant labels. Namespace and subsystem are prefixed to metrics. ```go func NewWithRegistry(registry prometheus.Registerer, serviceName, namespace, subsystem string, labels map[string]string) *FiberPrometheus ``` -------------------------------- ### NewWithRegistry Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Creates a new instance of FiberPrometheus middleware with a custom registry and configuration. ```APIDOC ## NewWithRegistry ### Description Creates a new instance of FiberPrometheus middleware with the ability to pass a custom registry, serviceName, namespace, subsystem, and constant labels. ### Parameters - **registry** (prometheus.Registerer) - Required - The Prometheus registry to use. - **serviceName** (string) - Required - The name of the service. - **namespace** (string) - Required - Namespace prefix for metrics. - **subsystem** (string) - Required - Subsystem prefix for metrics. - **labels** (map[string]string) - Required - Constant labels to apply to metrics. ``` -------------------------------- ### Middleware Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 The default middleware implementation for Fiber. ```APIDOC ## Middleware ### Description Executes the default middleware logic to record metrics for the Fiber context. ``` -------------------------------- ### New FiberPrometheus Instance Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Creates a new instance of the FiberPrometheus middleware. The serviceName is used as a constant label for metrics. ```go func New(serviceName string) *FiberPrometheus ``` -------------------------------- ### New FiberPrometheus Instance with Namespace and Subsystem Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Creates a new FiberPrometheus instance with custom namespace and subsystem prefixes for metrics. The serviceName is still used as a constant label. ```go func NewWith(serviceName, namespace, subsystem string) *FiberPrometheus ``` -------------------------------- ### New FiberPrometheus Instance with Custom Labels Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Creates a new FiberPrometheus instance with custom labels, namespace, and subsystem. Labels are prefixed to the metrics. ```go func NewWithLabels(labels map[string]string, namespace, subsystem string) *FiberPrometheus ``` -------------------------------- ### New FiberPrometheus Instance with Custom Registry Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Creates a new FiberPrometheus instance using a provided Prometheus Registerer, along with service name, namespace, and subsystem. ```go func NewWithRegistry(registry prometheus.Registerer, serviceName, namespace, subsystem string, ...) *FiberPrometheus ``` -------------------------------- ### New FiberPrometheus Instance with Default Registry Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Creates a new FiberPrometheus instance utilizing the default Prometheus registry. This is available from v2.8.0 onwards. ```go func NewWithDefaultRegistry(serviceName string) *FiberPrometheus ``` -------------------------------- ### RegisterAt Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Registers the Prometheus metrics handler at a specific URL. ```APIDOC ## RegisterAt ### Description Registers the prometheus handler at a given URL path. ### Parameters - **app** (fiber.Router) - Required - The Fiber router instance. - **url** (string) - Required - The URL path to expose metrics. - **handlers** (...fiber.Handler) - Optional - Additional handlers to execute. ``` -------------------------------- ### SetSkipPaths Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Configures the middleware to skip specific request paths. ```APIDOC ## SetSkipPaths ### Description Allows setting the paths that should be skipped from the metrics collection. ### Parameters - **paths** ([]string) - Required - A slice of URL paths to skip. ``` -------------------------------- ### FiberPrometheus Middleware Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 The core middleware function for FiberPrometheus. It processes incoming requests and generates metrics. ```go func (ps *FiberPrometheus) Middleware(ctx *fiber.Ctx) error ``` -------------------------------- ### Set Ignored Status Codes Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Configures a list of HTTP status codes for which metrics should not be recorded. Useful for excluding certain responses. ```go func (ps *FiberPrometheus) SetIgnoreStatusCodes(codes []int) ``` -------------------------------- ### FiberPrometheus Struct Definition Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 The main struct for the FiberPrometheus middleware, containing internal fields for configuration and state. ```go type FiberPrometheus struct { // contains filtered or unexported fields } ``` -------------------------------- ### Register Metrics Endpoint Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Registers the metrics collection endpoint at a specified URL within the Fiber application. Additional handlers can be provided. ```go func (ps *FiberPrometheus) RegisterAt(app fiber.Router, url string, handlers ...fiber.Handler) ``` -------------------------------- ### SetIgnoreStatusCodes Source: https://pkg.go.dev/github.com/ansrivas/fiberprometheus/v2 Configures the middleware to ignore specific HTTP status codes. ```APIDOC ## SetIgnoreStatusCodes ### Description Allows ignoring specific status codes from being recorded in metrics. ### Parameters - **codes** ([]int) - Required - A slice of HTTP status codes to ignore. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.