diff options
author | Romain <romdum@users.noreply.github.com> | 2021-10-05 20:39:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-05 20:39:37 +0200 |
commit | 987152ba408b03fe0b15dd9c72dfd1614b4159fd (patch) | |
tree | 02572cb5512f146797c3a3d715f0bee22eb138f7 /modules | |
parent | 760d61b411460db3f3c688c214a6199b5b18eb27 (diff) | |
download | gitea-987152ba408b03fe0b15dd9c72dfd1614b4159fd.tar.gz gitea-987152ba408b03fe0b15dd9c72dfd1614b4159fd.zip |
Add metrics to get issues by repository (#17225)
Diffstat (limited to 'modules')
-rwxr-xr-x | modules/metrics/collector.go | 69 | ||||
-rw-r--r-- | modules/setting/setting.go | 14 |
2 files changed, 50 insertions, 33 deletions
diff --git a/modules/metrics/collector.go b/modules/metrics/collector.go index dcc147631b..527202e0a6 100755 --- a/modules/metrics/collector.go +++ b/modules/metrics/collector.go @@ -15,33 +15,34 @@ const namespace = "gitea_" // Collector implements the prometheus.Collector interface and // exposes gitea metrics for prometheus type Collector struct { - Accesses *prometheus.Desc - Actions *prometheus.Desc - Attachments *prometheus.Desc - Comments *prometheus.Desc - Follows *prometheus.Desc - HookTasks *prometheus.Desc - Issues *prometheus.Desc - IssuesOpen *prometheus.Desc - IssuesClosed *prometheus.Desc - IssuesByLabel *prometheus.Desc - Labels *prometheus.Desc - LoginSources *prometheus.Desc - Milestones *prometheus.Desc - Mirrors *prometheus.Desc - Oauths *prometheus.Desc - Organizations *prometheus.Desc - Projects *prometheus.Desc - ProjectBoards *prometheus.Desc - PublicKeys *prometheus.Desc - Releases *prometheus.Desc - Repositories *prometheus.Desc - Stars *prometheus.Desc - Teams *prometheus.Desc - UpdateTasks *prometheus.Desc - Users *prometheus.Desc - Watches *prometheus.Desc - Webhooks *prometheus.Desc + Accesses *prometheus.Desc + Actions *prometheus.Desc + Attachments *prometheus.Desc + Comments *prometheus.Desc + Follows *prometheus.Desc + HookTasks *prometheus.Desc + Issues *prometheus.Desc + IssuesOpen *prometheus.Desc + IssuesClosed *prometheus.Desc + IssuesByLabel *prometheus.Desc + IssuesByRepository *prometheus.Desc + Labels *prometheus.Desc + LoginSources *prometheus.Desc + Milestones *prometheus.Desc + Mirrors *prometheus.Desc + Oauths *prometheus.Desc + Organizations *prometheus.Desc + Projects *prometheus.Desc + ProjectBoards *prometheus.Desc + PublicKeys *prometheus.Desc + Releases *prometheus.Desc + Repositories *prometheus.Desc + Stars *prometheus.Desc + Teams *prometheus.Desc + UpdateTasks *prometheus.Desc + Users *prometheus.Desc + Watches *prometheus.Desc + Webhooks *prometheus.Desc } // NewCollector returns a new Collector with all prometheus.Desc initialized @@ -88,6 +89,11 @@ func NewCollector() Collector { "Number of Issues", []string{"label"}, nil, ), + IssuesByRepository: prometheus.NewDesc( + namespace+"issues_by_repository", + "Number of Issues", + []string{"repository"}, nil, + ), IssuesOpen: prometheus.NewDesc( namespace+"issues_open", "Number of open Issues", @@ -196,6 +202,7 @@ func (c Collector) Describe(ch chan<- *prometheus.Desc) { ch <- c.HookTasks ch <- c.Issues ch <- c.IssuesByLabel + ch <- c.IssuesByRepository ch <- c.IssuesOpen ch <- c.IssuesClosed ch <- c.Labels @@ -264,6 +271,14 @@ func (c Collector) Collect(ch chan<- prometheus.Metric) { il.Label, ) } + for _, ir := range stats.Counter.IssueByRepository { + ch <- prometheus.MustNewConstMetric( + c.IssuesByRepository, + prometheus.GaugeValue, + float64(ir.Count), + ir.OwnerName+"/"+ir.Repository, + ) + } ch <- prometheus.MustNewConstMetric( c.IssuesClosed, prometheus.GaugeValue, diff --git a/modules/setting/setting.go b/modules/setting/setting.go index bdb3b1fd7b..88302be1d3 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -390,13 +390,15 @@ var ( // Metrics settings Metrics = struct { - Enabled bool - Token string - EnabledIssueByLabel bool + Enabled bool + Token string + EnabledIssueByLabel bool + EnabledIssueByRepository bool }{ - Enabled: false, - Token: "", - EnabledIssueByLabel: false, + Enabled: false, + Token: "", + EnabledIssueByLabel: false, + EnabledIssueByRepository: false, } // I18n settings |