Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ansrivas/fiberprometheus
prometheus middleware for Fiber
https://github.com/ansrivas/fiberprometheus
Last synced: 18 days ago
JSON representation
prometheus middleware for Fiber
- Host: GitHub
- URL: https://github.com/ansrivas/fiberprometheus
- Owner: ansrivas
- License: mit
- Created: 2020-07-02T23:57:00.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-25T04:55:18.000Z (about 2 months ago)
- Last Synced: 2024-10-15T10:18:41.828Z (about 1 month ago)
- Language: Go
- Homepage:
- Size: 176 KB
- Stars: 168
- Watchers: 4
- Forks: 38
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-fiber - ansrivas/fiberprometheus - Prometheus middleware for gofiber. (⚙️ Middlewares / 🌱 Third Party)
README
**NOTE**: 🚨 We are currently migrating this middleware to the official gofiber/contrib repo, official link etc. will be posted soon.
# fiberprometheus
Prometheus middleware for gofiber.
**Note: Requires Go 1.21 and above**
![Release](https://img.shields.io/github/release/ansrivas/fiberprometheus.svg)
[![Discord](https://img.shields.io/badge/discord-join%20channel-7289DA)](https://gofiber.io/discord)
![Test](https://github.com/ansrivas/fiberprometheus/workflows/Test/badge.svg)
![Security](https://github.com/ansrivas/fiberprometheus/workflows/Security/badge.svg)
![Linter](https://github.com/ansrivas/fiberprometheus/workflows/Linter/badge.svg)Following metrics are available by default:
```
http_requests_total
http_request_duration_seconds
http_requests_in_progress_total
http_cache_results
```### Install v2
```
go get -u github.com/gofiber/fiber/v2
go get -u github.com/ansrivas/fiberprometheus/v2
```### Example using v2
```go
package mainimport (
"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
- Hit the default url at http://localhost:3000
- Navigate to http://localhost:3000/metrics### Grafana Board
- https://grafana.com/grafana/dashboards/14331