[PR #678] [CLOSED] [WIP] Expose prometheus metrics with gitea #15524

Closed
opened 2025-11-02 11:48:34 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-gitea/gitea/pull/678
Author: @metalmatze
Created: 1/15/2017
Status: Closed

Base: masterHead: feature/metrics


📝 Commits (3)

  • 1a243ee Create prometheus statistic exporter with /metrics route
  • c089294 Add all missing metrics to prometheus Collector
  • 807d185 Vendor all prometheus dependencies

📊 Changes

74 files changed (+14693 additions, -1 deletions)

View changed files

📝 cmd/web.go (+13 -1)
modules/metrics/statistic.go (+294 -0)
vendor/github.com/beorn7/perks/LICENSE (+20 -0)
vendor/github.com/beorn7/perks/quantile/exampledata.txt (+2388 -0)
vendor/github.com/beorn7/perks/quantile/stream.go (+292 -0)
vendor/github.com/matttproud/golang_protobuf_extensions/LICENSE (+201 -0)
vendor/github.com/matttproud/golang_protobuf_extensions/NOTICE (+1 -0)
vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/Makefile (+7 -0)
vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go (+75 -0)
vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go (+16 -0)
vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go (+46 -0)
vendor/github.com/prometheus/client_golang/LICENSE (+201 -0)
vendor/github.com/prometheus/client_golang/NOTICE (+23 -0)
vendor/github.com/prometheus/client_golang/prometheus/README.md (+1 -0)
vendor/github.com/prometheus/client_golang/prometheus/collector.go (+75 -0)
vendor/github.com/prometheus/client_golang/prometheus/counter.go (+164 -0)
vendor/github.com/prometheus/client_golang/prometheus/desc.go (+200 -0)
vendor/github.com/prometheus/client_golang/prometheus/doc.go (+181 -0)
vendor/github.com/prometheus/client_golang/prometheus/expvar_collector.go (+119 -0)
vendor/github.com/prometheus/client_golang/prometheus/fnv.go (+29 -0)

...and 54 more files

📄 Description

We already have metrics displayed on the admin dashboard. But I want to be able to create metrics from them. A lot more metrics can be added in the future. I think about things like: pushes & pulls or whatever comes to mind.

Prometheus is the way to go with metrics in 2016 and of course in 2017.
After being added to Kubernetes, Docker and now Gitlab. I want to have metrics in Gitea too.

Metrics from the dashboard below are exposed like the following:
screenshot from 2017-01-15 22-16-17

# HELP gitea_accesses Number of Accesses
# TYPE gitea_accesses gauge
gitea_accesses 0
# HELP gitea_actions Number of Actions
# TYPE gitea_actions gauge
gitea_actions 3
# HELP gitea_attachments Number of Attachments
# TYPE gitea_attachments gauge
gitea_attachments 0
# HELP gitea_comments Number of Comments
# TYPE gitea_comments gauge
gitea_comments 0
# HELP gitea_follows Number of Follows
# TYPE gitea_follows gauge
gitea_follows 0
# HELP gitea_hooktasks Number of HookTasks
# TYPE gitea_hooktasks gauge
gitea_hooktasks 0
# HELP gitea_issues Number of Issues
# TYPE gitea_issues gauge
gitea_issues 0
# HELP gitea_labels Number of Labels
# TYPE gitea_labels gauge
gitea_labels 0
# HELP gitea_loginsources Number of LoginSources
# TYPE gitea_loginsources gauge
gitea_loginsources 0
# HELP gitea_milestones Number of Milestones
# TYPE gitea_milestones gauge
gitea_milestones 0
# HELP gitea_mirrors Number of Mirrors
# TYPE gitea_mirrors gauge
gitea_mirrors 0
# HELP gitea_oauths Number of Oauths
# TYPE gitea_oauths gauge
gitea_oauths 0
# HELP gitea_organizations Number of Organizations
# TYPE gitea_organizations gauge
gitea_organizations 1
# HELP gitea_publickeys Number of PublicKeys
# TYPE gitea_publickeys gauge
gitea_publickeys 0
# HELP gitea_releases Number of Releases
# TYPE gitea_releases gauge
gitea_releases 0
# HELP gitea_repositories Number of Repositories
# TYPE gitea_repositories gauge
gitea_repositories 1
# HELP gitea_stars Number of Stars
# TYPE gitea_stars gauge
gitea_stars 0
# HELP gitea_teams Number of Teams
# TYPE gitea_teams gauge
gitea_teams 1
# HELP gitea_updatetasks Number of UpdateTasks
# TYPE gitea_updatetasks gauge
gitea_updatetasks 0
# HELP gitea_users Number of Users
# TYPE gitea_users gauge
gitea_users 1
# HELP gitea_watches Number of Watches
# TYPE gitea_watches gauge
gitea_watches 1
# HELP gitea_webhooks Number of Webhooks
# TYPE gitea_webhooks gauge
gitea_webhooks 0

What's missing in WIP:

  • Metrics are exposed on /metrics and are currently publicly visible. I would be great to generate a token on start and display for admins to grab from the admin web UI. Add a middleware to check the token and only then display the metrics via http. E.g. /metrics?token=abc123.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/go-gitea/gitea/pull/678 **Author:** [@metalmatze](https://github.com/metalmatze) **Created:** 1/15/2017 **Status:** ❌ Closed **Base:** `master` ← **Head:** `feature/metrics` --- ### 📝 Commits (3) - [`1a243ee`](https://github.com/go-gitea/gitea/commit/1a243eeda44b730b973d12206bd2f3227f6b66fa) Create prometheus statistic exporter with /metrics route - [`c089294`](https://github.com/go-gitea/gitea/commit/c0892948ed9812a9d50964e4e7c0a7693005fe99) Add all missing metrics to prometheus Collector - [`807d185`](https://github.com/go-gitea/gitea/commit/807d185f3a56b89e1bd1158b21c6a76a55935d5e) Vendor all prometheus dependencies ### 📊 Changes **74 files changed** (+14693 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `cmd/web.go` (+13 -1) ➕ `modules/metrics/statistic.go` (+294 -0) ➕ `vendor/github.com/beorn7/perks/LICENSE` (+20 -0) ➕ `vendor/github.com/beorn7/perks/quantile/exampledata.txt` (+2388 -0) ➕ `vendor/github.com/beorn7/perks/quantile/stream.go` (+292 -0) ➕ `vendor/github.com/matttproud/golang_protobuf_extensions/LICENSE` (+201 -0) ➕ `vendor/github.com/matttproud/golang_protobuf_extensions/NOTICE` (+1 -0) ➕ `vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/Makefile` (+7 -0) ➕ `vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go` (+75 -0) ➕ `vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go` (+16 -0) ➕ `vendor/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go` (+46 -0) ➕ `vendor/github.com/prometheus/client_golang/LICENSE` (+201 -0) ➕ `vendor/github.com/prometheus/client_golang/NOTICE` (+23 -0) ➕ `vendor/github.com/prometheus/client_golang/prometheus/README.md` (+1 -0) ➕ `vendor/github.com/prometheus/client_golang/prometheus/collector.go` (+75 -0) ➕ `vendor/github.com/prometheus/client_golang/prometheus/counter.go` (+164 -0) ➕ `vendor/github.com/prometheus/client_golang/prometheus/desc.go` (+200 -0) ➕ `vendor/github.com/prometheus/client_golang/prometheus/doc.go` (+181 -0) ➕ `vendor/github.com/prometheus/client_golang/prometheus/expvar_collector.go` (+119 -0) ➕ `vendor/github.com/prometheus/client_golang/prometheus/fnv.go` (+29 -0) _...and 54 more files_ </details> ### 📄 Description We already have metrics displayed on the admin dashboard. But I want to be able to create metrics from them. A lot more metrics can be added in the future. I think about things like: pushes & pulls or whatever comes to mind. [Prometheus](https://prometheus.io/) is the way to go with metrics in 2016 and of course in 2017. After being added to Kubernetes, Docker and now Gitlab. I want to have metrics in Gitea too. Metrics from the dashboard below are exposed like the following: ![screenshot from 2017-01-15 22-16-17](https://cloud.githubusercontent.com/assets/872251/21966246/436bb364-db70-11e6-8158-c069c6a8883b.png) ``` # HELP gitea_accesses Number of Accesses # TYPE gitea_accesses gauge gitea_accesses 0 # HELP gitea_actions Number of Actions # TYPE gitea_actions gauge gitea_actions 3 # HELP gitea_attachments Number of Attachments # TYPE gitea_attachments gauge gitea_attachments 0 # HELP gitea_comments Number of Comments # TYPE gitea_comments gauge gitea_comments 0 # HELP gitea_follows Number of Follows # TYPE gitea_follows gauge gitea_follows 0 # HELP gitea_hooktasks Number of HookTasks # TYPE gitea_hooktasks gauge gitea_hooktasks 0 # HELP gitea_issues Number of Issues # TYPE gitea_issues gauge gitea_issues 0 # HELP gitea_labels Number of Labels # TYPE gitea_labels gauge gitea_labels 0 # HELP gitea_loginsources Number of LoginSources # TYPE gitea_loginsources gauge gitea_loginsources 0 # HELP gitea_milestones Number of Milestones # TYPE gitea_milestones gauge gitea_milestones 0 # HELP gitea_mirrors Number of Mirrors # TYPE gitea_mirrors gauge gitea_mirrors 0 # HELP gitea_oauths Number of Oauths # TYPE gitea_oauths gauge gitea_oauths 0 # HELP gitea_organizations Number of Organizations # TYPE gitea_organizations gauge gitea_organizations 1 # HELP gitea_publickeys Number of PublicKeys # TYPE gitea_publickeys gauge gitea_publickeys 0 # HELP gitea_releases Number of Releases # TYPE gitea_releases gauge gitea_releases 0 # HELP gitea_repositories Number of Repositories # TYPE gitea_repositories gauge gitea_repositories 1 # HELP gitea_stars Number of Stars # TYPE gitea_stars gauge gitea_stars 0 # HELP gitea_teams Number of Teams # TYPE gitea_teams gauge gitea_teams 1 # HELP gitea_updatetasks Number of UpdateTasks # TYPE gitea_updatetasks gauge gitea_updatetasks 0 # HELP gitea_users Number of Users # TYPE gitea_users gauge gitea_users 1 # HELP gitea_watches Number of Watches # TYPE gitea_watches gauge gitea_watches 1 # HELP gitea_webhooks Number of Webhooks # TYPE gitea_webhooks gauge gitea_webhooks 0 ``` What's missing in WIP: * Metrics are exposed on `/metrics` and are currently publicly visible. I would be great to generate a token on start and display for admins to grab from the admin web UI. Add a middleware to check the token and only then display the metrics via http. E.g. `/metrics?token=abc123`. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-02 11:48:34 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#15524