mirror of
https://github.com/go-gitea/gitea.git
synced 2024-11-22 20:42:47 +08:00
Add projects and project boards in exposed metrics (#17202)
* Add projects and project boards in exposed metrics * Refactor db.GetEngine Co-authored-by: delvh <dev.lh@web.de>
This commit is contained in:
parent
5b2b2cf923
commit
c64e2a319f
|
@ -18,20 +18,22 @@ type Statistic struct {
|
||||||
Comment, Oauth, Follow,
|
Comment, Oauth, Follow,
|
||||||
Mirror, Release, LoginSource, Webhook,
|
Mirror, Release, LoginSource, Webhook,
|
||||||
Milestone, Label, HookTask,
|
Milestone, Label, HookTask,
|
||||||
Team, UpdateTask, Attachment int64
|
Team, UpdateTask, Project,
|
||||||
|
ProjectBoard, Attachment int64
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetStatistic returns the database statistics
|
// GetStatistic returns the database statistics
|
||||||
func GetStatistic() (stats Statistic) {
|
func GetStatistic() (stats Statistic) {
|
||||||
|
e := db.GetEngine(db.DefaultContext)
|
||||||
stats.Counter.User = CountUsers()
|
stats.Counter.User = CountUsers()
|
||||||
stats.Counter.Org = CountOrganizations()
|
stats.Counter.Org = CountOrganizations()
|
||||||
stats.Counter.PublicKey, _ = db.GetEngine(db.DefaultContext).Count(new(PublicKey))
|
stats.Counter.PublicKey, _ = e.Count(new(PublicKey))
|
||||||
stats.Counter.Repo = CountRepositories(true)
|
stats.Counter.Repo = CountRepositories(true)
|
||||||
stats.Counter.Watch, _ = db.GetEngine(db.DefaultContext).Count(new(Watch))
|
stats.Counter.Watch, _ = e.Count(new(Watch))
|
||||||
stats.Counter.Star, _ = db.GetEngine(db.DefaultContext).Count(new(Star))
|
stats.Counter.Star, _ = e.Count(new(Star))
|
||||||
stats.Counter.Action, _ = db.GetEngine(db.DefaultContext).Count(new(Action))
|
stats.Counter.Action, _ = e.Count(new(Action))
|
||||||
stats.Counter.Access, _ = db.GetEngine(db.DefaultContext).Count(new(Access))
|
stats.Counter.Access, _ = e.Count(new(Access))
|
||||||
|
|
||||||
type IssueCount struct {
|
type IssueCount struct {
|
||||||
Count int64
|
Count int64
|
||||||
|
@ -39,7 +41,7 @@ func GetStatistic() (stats Statistic) {
|
||||||
}
|
}
|
||||||
issueCounts := []IssueCount{}
|
issueCounts := []IssueCount{}
|
||||||
|
|
||||||
_ = db.GetEngine(db.DefaultContext).Select("COUNT(*) AS count, is_closed").Table("issue").GroupBy("is_closed").Find(&issueCounts)
|
_ = e.Select("COUNT(*) AS count, is_closed").Table("issue").GroupBy("is_closed").Find(&issueCounts)
|
||||||
for _, c := range issueCounts {
|
for _, c := range issueCounts {
|
||||||
if c.IsClosed {
|
if c.IsClosed {
|
||||||
stats.Counter.IssueClosed = c.Count
|
stats.Counter.IssueClosed = c.Count
|
||||||
|
@ -50,17 +52,19 @@ func GetStatistic() (stats Statistic) {
|
||||||
|
|
||||||
stats.Counter.Issue = stats.Counter.IssueClosed + stats.Counter.IssueOpen
|
stats.Counter.Issue = stats.Counter.IssueClosed + stats.Counter.IssueOpen
|
||||||
|
|
||||||
stats.Counter.Comment, _ = db.GetEngine(db.DefaultContext).Count(new(Comment))
|
stats.Counter.Comment, _ = e.Count(new(Comment))
|
||||||
stats.Counter.Oauth = 0
|
stats.Counter.Oauth = 0
|
||||||
stats.Counter.Follow, _ = db.GetEngine(db.DefaultContext).Count(new(Follow))
|
stats.Counter.Follow, _ = e.Count(new(Follow))
|
||||||
stats.Counter.Mirror, _ = db.GetEngine(db.DefaultContext).Count(new(Mirror))
|
stats.Counter.Mirror, _ = e.Count(new(Mirror))
|
||||||
stats.Counter.Release, _ = db.GetEngine(db.DefaultContext).Count(new(Release))
|
stats.Counter.Release, _ = e.Count(new(Release))
|
||||||
stats.Counter.LoginSource = login.CountSources()
|
stats.Counter.LoginSource = login.CountSources()
|
||||||
stats.Counter.Webhook, _ = db.GetEngine(db.DefaultContext).Count(new(Webhook))
|
stats.Counter.Webhook, _ = e.Count(new(Webhook))
|
||||||
stats.Counter.Milestone, _ = db.GetEngine(db.DefaultContext).Count(new(Milestone))
|
stats.Counter.Milestone, _ = e.Count(new(Milestone))
|
||||||
stats.Counter.Label, _ = db.GetEngine(db.DefaultContext).Count(new(Label))
|
stats.Counter.Label, _ = e.Count(new(Label))
|
||||||
stats.Counter.HookTask, _ = db.GetEngine(db.DefaultContext).Count(new(HookTask))
|
stats.Counter.HookTask, _ = e.Count(new(HookTask))
|
||||||
stats.Counter.Team, _ = db.GetEngine(db.DefaultContext).Count(new(Team))
|
stats.Counter.Team, _ = e.Count(new(Team))
|
||||||
stats.Counter.Attachment, _ = db.GetEngine(db.DefaultContext).Count(new(Attachment))
|
stats.Counter.Attachment, _ = e.Count(new(Attachment))
|
||||||
|
stats.Counter.Project, _ = e.Count(new(Project))
|
||||||
|
stats.Counter.ProjectBoard, _ = e.Count(new(ProjectBoard))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ type Collector struct {
|
||||||
Mirrors *prometheus.Desc
|
Mirrors *prometheus.Desc
|
||||||
Oauths *prometheus.Desc
|
Oauths *prometheus.Desc
|
||||||
Organizations *prometheus.Desc
|
Organizations *prometheus.Desc
|
||||||
|
Projects *prometheus.Desc
|
||||||
|
ProjectBoards *prometheus.Desc
|
||||||
PublicKeys *prometheus.Desc
|
PublicKeys *prometheus.Desc
|
||||||
Releases *prometheus.Desc
|
Releases *prometheus.Desc
|
||||||
Repositories *prometheus.Desc
|
Repositories *prometheus.Desc
|
||||||
|
@ -119,6 +121,16 @@ func NewCollector() Collector {
|
||||||
"Number of Organizations",
|
"Number of Organizations",
|
||||||
nil, nil,
|
nil, nil,
|
||||||
),
|
),
|
||||||
|
Projects: prometheus.NewDesc(
|
||||||
|
namespace+"projects",
|
||||||
|
"Number of projects",
|
||||||
|
nil, nil,
|
||||||
|
),
|
||||||
|
ProjectBoards: prometheus.NewDesc(
|
||||||
|
namespace+"projects_boards",
|
||||||
|
"Number of project boards",
|
||||||
|
nil, nil,
|
||||||
|
),
|
||||||
PublicKeys: prometheus.NewDesc(
|
PublicKeys: prometheus.NewDesc(
|
||||||
namespace+"publickeys",
|
namespace+"publickeys",
|
||||||
"Number of PublicKeys",
|
"Number of PublicKeys",
|
||||||
|
@ -185,6 +197,8 @@ func (c Collector) Describe(ch chan<- *prometheus.Desc) {
|
||||||
ch <- c.Mirrors
|
ch <- c.Mirrors
|
||||||
ch <- c.Oauths
|
ch <- c.Oauths
|
||||||
ch <- c.Organizations
|
ch <- c.Organizations
|
||||||
|
ch <- c.Projects
|
||||||
|
ch <- c.ProjectBoards
|
||||||
ch <- c.PublicKeys
|
ch <- c.PublicKeys
|
||||||
ch <- c.Releases
|
ch <- c.Releases
|
||||||
ch <- c.Repositories
|
ch <- c.Repositories
|
||||||
|
@ -275,6 +289,16 @@ func (c Collector) Collect(ch chan<- prometheus.Metric) {
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
float64(stats.Counter.Org),
|
float64(stats.Counter.Org),
|
||||||
)
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.Projects,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
float64(stats.Counter.Project),
|
||||||
|
)
|
||||||
|
ch <- prometheus.MustNewConstMetric(
|
||||||
|
c.ProjectBoards,
|
||||||
|
prometheus.GaugeValue,
|
||||||
|
float64(stats.Counter.ProjectBoard),
|
||||||
|
)
|
||||||
ch <- prometheus.MustNewConstMetric(
|
ch <- prometheus.MustNewConstMetric(
|
||||||
c.PublicKeys,
|
c.PublicKeys,
|
||||||
prometheus.GaugeValue,
|
prometheus.GaugeValue,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user