Milestone, Label, HookTask,
Team, UpdateTask, Project,
ProjectBoard, Attachment int64
- IssueByLabel []IssueByLabelCount
+ IssueByLabel []IssueByLabelCount
+ IssueByRepository []IssueByRepositoryCount
}
}
Label string
}
+// IssueByRepositoryCount contains the number of issue group by repository
+type IssueByRepositoryCount struct {
+ Count int64
+ OwnerName string
+ Repository string
+}
+
// GetStatistic returns the database statistics
func GetStatistic() (stats Statistic) {
e := db.GetEngine(db.DefaultContext)
Find(&stats.Counter.IssueByLabel)
}
+ if setting.Metrics.EnabledIssueByRepository {
+ stats.Counter.IssueByRepository = []IssueByRepositoryCount{}
+
+ _ = e.Select("COUNT(*) AS count, r.owner_name, r.name AS repository").
+ Join("LEFT", "repository r", "r.id=i.repo_id").
+ Table("issue i").
+ GroupBy("r.owner_name, r.name").
+ Find(&stats.Counter.IssueByRepository)
+ }
+
issueCounts := []IssueCount{}
_ = e.Select("COUNT(*) AS count, is_closed").Table("issue").GroupBy("is_closed").Find(&issueCounts)
// 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
"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",
ch <- c.HookTasks
ch <- c.Issues
ch <- c.IssuesByLabel
+ ch <- c.IssuesByRepository
ch <- c.IssuesOpen
ch <- c.IssuesClosed
ch <- c.Labels
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,