8000 GitHub - ansrivas/fiberprometheus: prometheus middleware for Fiber
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

ansrivas/fiberprometheus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
< 8000 svg aria-hidden="true" focusable="false" class="octicon octicon-file color-fg-muted" viewBox="0 0 16 16" width="16" height="16" fill="currentColor" display="inline-block" overflow="visible" style="vertical-align:text-bottom">
 
 

Repository files navigation

NOTE: 🚨 We are currently migrating this middleware to the official gofiber/contrib repo, official link etc. will be posted soon.

fiberprometheus

Prometheus middleware for Fiber.

Note: Requires Go 1.22 and above

Release Discord Test Security Linter

Following metrics are available by default:

http_requests_total
http_request_duration_seconds
http_requests_in_progress_total

Install v2

go get -u github.com/gofiber/fiber/v2
go get -u github.com/ansrivas/fiberprometheus/v2

Example using v2

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
  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")
}

Result

Grafana Dashboard

0