{"id":13794170,"url":"https://github.com/zsais/go-gin-prometheus","last_synced_at":"2025-05-14T23:07:39.234Z","repository":{"id":1312585,"uuid":"41768079","full_name":"zsais/go-gin-prometheus","owner":"zsais","description":"Gin Web Framework Prometheus metrics exporter","archived":false,"fork":false,"pushed_at":"2024-08-11T18:27:57.000Z","size":39,"stargazers_count":452,"open_issues_count":21,"forks_count":133,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T10:14:08.616Z","etag":null,"topics":["gin-gonic","go","middleware","prometheus"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zsais.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-09-01T23:08:26.000Z","updated_at":"2025-04-11T08:57:14.000Z","dependencies_parsed_at":"2024-11-15T22:55:25.279Z","dependency_job_id":"fa65e71b-bbc8-4408-9002-5c529afcec9c","html_url":"https://github.com/zsais/go-gin-prometheus","commit_stats":{"total_commits":31,"total_committers":16,"mean_commits":1.9375,"dds":0.8709677419354839,"last_synced_commit":"2199a42d96c1d40f249909ed2f27d42449c7fc94"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zsais%2Fgo-gin-prometheus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zsais%2Fgo-gin-prometheus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zsais%2Fgo-gin-prometheus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zsais%2Fgo-gin-prometheus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zsais","download_url":"https://codeload.github.com/zsais/go-gin-prometheus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243362,"owners_count":22038046,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gin-gonic","go","middleware","prometheus"],"created_at":"2024-08-03T23:00:36.759Z","updated_at":"2025-05-14T23:07:34.225Z","avatar_url":"https://github.com/zsais.png","language":"Go","funding_links":[],"categories":["Go","metrics"],"sub_categories":[],"readme":"# go-gin-prometheus\n[![](https://godoc.org/github.com/zsais/go-gin-prometheus?status.svg)](https://godoc.org/github.com/zsais/go-gin-prometheus) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\nGin Web Framework Prometheus metrics exporter\n\n## Installation\n\n`$ go get github.com/zsais/go-gin-prometheus`\n\n## Usage\n\n```go\npackage main\n\nimport (\n\t\"github.com/gin-gonic/gin\"\n\t\"github.com/zsais/go-gin-prometheus\"\n)\n\nfunc main() {\n\tr := gin.New()\n\n\tp := ginprometheus.NewPrometheus(\"gin\")\n\tp.Use(r)\n\n\tr.GET(\"/\", func(c *gin.Context) {\n\t\tc.JSON(200, \"Hello world!\")\n\t})\n\n\tr.Run(\":29090\")\n}\n```\n\nSee the [example.go file](https://github.com/zsais/go-gin-prometheus/blob/master/example/example.go)\n\n## Preserving a low cardinality for the request counter\n\nThe request counter (`requests_total`) has a `url` label which,\nalthough desirable, can become problematic in cases where your\napplication uses templated routes expecting a great number of\nvariations, as Prometheus explicitly recommends against metrics having\nhigh cardinality dimensions:\n\nhttps://prometheus.io/docs/practices/naming/#labels\n\nIf you have for instance a `/customer/:name` templated route and you\ndon't want to generate a time series for every possible customer name,\nyou could supply this mapping function to the middleware:\n\n```go\npackage main\n\nimport (\n\t\"github.com/gin-gonic/gin\"\n\t\"github.com/zsais/go-gin-prometheus\"\n)\n\nfunc main() {\n\tr := gin.New()\n\n\tp := ginprometheus.NewPrometheus(\"gin\")\n\n\tp.ReqCntURLLabelMappingFn = func(c *gin.Context) string {\n\t\turl := c.Request.URL.Path\n\t\tfor _, p := range c.Params {\n\t\t\tif p.Key == \"name\" {\n\t\t\t\turl = strings.Replace(url, p.Value, \":name\", 1)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\treturn url\n\t}\n\n\tp.Use(r)\n\n\tr.GET(\"/\", func(c *gin.Context) {\n\t\tc.JSON(200, \"Hello world!\")\n\t})\n\n\tr.Run(\":29090\")\n}\n```\n\nwhich would map `/customer/alice` and `/customer/bob` to their\ntemplate `/customer/:name`, and thus preserve a low cardinality for\nour metrics.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzsais%2Fgo-gin-prometheus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzsais%2Fgo-gin-prometheus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzsais%2Fgo-gin-prometheus/lists"}