;ENABLED = false
;; If you want to add authorization, specify a token here
;TOKEN =
+;; Enable issue by label metrics; default is false
+;ENABLED_ISSUE_BY_LABEL = false
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
## Metrics (`metrics`)
- `ENABLED`: **false**: Enables /metrics endpoint for prometheus.
+- `ENABLED_ISSUE_BY_LABEL`: **false**: Enable issue by label metrics
- `TOKEN`: **\<empty\>**: You need to specify the token, if you want to include in the authorization the metrics . The same token need to be used in prometheus parameters `bearer_token` or `bearer_token_file`.
## API (`api`)
import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/login"
+ "code.gitea.io/gitea/modules/setting"
)
// Statistic contains the database statistics
Milestone, Label, HookTask,
Team, UpdateTask, Project,
ProjectBoard, Attachment int64
+ IssueByLabel []IssueByLabelCount
}
}
+// IssueByLabelCount contains the number of issue group by label
+type IssueByLabelCount struct {
+ Count int64
+ Label string
+}
+
// GetStatistic returns the database statistics
func GetStatistic() (stats Statistic) {
e := db.GetEngine(db.DefaultContext)
Count int64
IsClosed bool
}
+
+ if setting.Metrics.EnabledIssueByLabel {
+ stats.Counter.IssueByLabel = []IssueByLabelCount{}
+
+ _ = e.Select("COUNT(*) AS count, l.name AS label").
+ Join("LEFT", "label l", "l.id=il.label_id").
+ Table("issue_label il").
+ GroupBy("l.name").
+ Find(&stats.Counter.IssueByLabel)
+ }
+
issueCounts := []IssueCount{}
_ = e.Select("COUNT(*) AS count, is_closed").Table("issue").GroupBy("is_closed").Find(&issueCounts)
Issues *prometheus.Desc
IssuesOpen *prometheus.Desc
IssuesClosed *prometheus.Desc
+ IssuesByLabel *prometheus.Desc
Labels *prometheus.Desc
LoginSources *prometheus.Desc
Milestones *prometheus.Desc
// NewCollector returns a new Collector with all prometheus.Desc initialized
func NewCollector() Collector {
+
return Collector{
Accesses: prometheus.NewDesc(
namespace+"accesses",
"Number of Issues",
nil, nil,
),
+ IssuesByLabel: prometheus.NewDesc(
+ namespace+"issues_by_label",
+ "Number of Issues",
+ []string{"label"}, nil,
+ ),
IssuesOpen: prometheus.NewDesc(
namespace+"issues_open",
"Number of open Issues",
nil, nil,
),
}
-
}
// Describe returns all possible prometheus.Desc
ch <- c.Follows
ch <- c.HookTasks
ch <- c.Issues
+ ch <- c.IssuesByLabel
ch <- c.IssuesOpen
ch <- c.IssuesClosed
ch <- c.Labels
prometheus.GaugeValue,
float64(stats.Counter.Issue),
)
+ for _, il := range stats.Counter.IssueByLabel {
+ ch <- prometheus.MustNewConstMetric(
+ c.IssuesByLabel,
+ prometheus.GaugeValue,
+ float64(il.Count),
+ il.Label,
+ )
+ }
ch <- prometheus.MustNewConstMetric(
c.IssuesClosed,
prometheus.GaugeValue,
// Metrics settings
Metrics = struct {
- Enabled bool
- Token string
+ Enabled bool
+ Token string
+ EnabledIssueByLabel bool
}{
- Enabled: false,
- Token: "",
+ Enabled: false,
+ Token: "",
+ EnabledIssueByLabel: false,
}
// I18n settings