1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

feat: add label 'state' to metric 'gitea_users' (#34326)

This PR adds the label _state_ to the metric _gitea_users_. With the
change, _gitea_users_ would be reported like this:

```
...
# HELP gitea_users Number of Users
# TYPE gitea_users gauge
gitea_users{state="active"} 20
gitea_users{state="inactive"} 10
...
```

The metrics above would be from a Gitea instance with 30 user accounts.
20 of the accounts are active and 10 of the accounts are not active.

Resolve #34325
This commit is contained in:
Tobias Balle-Petersen
2025-05-07 20:00:53 +02:00
committed by GitHub
parent dd886d729f
commit 020e774b91
3 changed files with 30 additions and 4 deletions

View File

@@ -184,7 +184,7 @@ func NewCollector() Collector {
Users: prometheus.NewDesc(
namespace+"users",
"Number of Users",
nil, nil,
[]string{"state"}, nil,
),
Watches: prometheus.NewDesc(
namespace+"watches",
@@ -373,7 +373,14 @@ func (c Collector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(
c.Users,
prometheus.GaugeValue,
float64(stats.Counter.User),
float64(stats.Counter.UsersActive),
"active", // state label
)
ch <- prometheus.MustNewConstMetric(
c.Users,
prometheus.GaugeValue,
float64(stats.Counter.UsersNotActive),
"inactive", // state label
)
ch <- prometheus.MustNewConstMetric(
c.Watches,