Skip to content

Commit 7616dd7

Browse files
committed
Separate open and closed issue in metrics
1 parent 067d82b commit 7616dd7

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

models/models.go

100644100755
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ type Statistic struct {
272272
Counter struct {
273273
User, Org, PublicKey,
274274
Repo, Watch, Star, Action, Access,
275-
Issue, Comment, Oauth, Follow,
275+
IssueClosed, IssueOpen, Comment, Oauth, Follow,
276276
Mirror, Release, LoginSource, Webhook,
277277
Milestone, Label, HookTask,
278278
Team, UpdateTask, Attachment int64
@@ -289,7 +289,8 @@ func GetStatistic() (stats Statistic) {
289289
stats.Counter.Star, _ = x.Count(new(Star))
290290
stats.Counter.Action, _ = x.Count(new(Action))
291291
stats.Counter.Access, _ = x.Count(new(Access))
292-
stats.Counter.Issue, _ = x.Count(new(Issue))
292+
stats.Counter.IssueClosed, _ = x.Where("is_closed=?", true).Count(new(Issue))
293+
stats.Counter.IssueOpen, _ = x.Where("is_closed=?", false).Count(new(Issue))
293294
stats.Counter.Comment, _ = x.Count(new(Comment))
294295
stats.Counter.Oauth = 0
295296
stats.Counter.Follow, _ = x.Count(new(Follow))

modules/metrics/collector.go

100644100755
Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ type Collector struct {
2121
Comments *prometheus.Desc
2222
Follows *prometheus.Desc
2323
HookTasks *prometheus.Desc
24-
Issues *prometheus.Desc
24+
IssuesOpen *prometheus.Desc
25+
IssuesClosed *prometheus.Desc
2526
Labels *prometheus.Desc
2627
LoginSources *prometheus.Desc
2728
Milestones *prometheus.Desc
@@ -72,9 +73,14 @@ func NewCollector() Collector {
7273
"Number of HookTasks",
7374
nil, nil,
7475
),
75-
Issues: prometheus.NewDesc(
76-
namespace+"issues",
77-
"Number of Issues",
76+
IssuesOpen: prometheus.NewDesc(
77+
namespace+"issues_open",
78+
"Number of open Issues",
79+
nil, nil,
80+
),
81+
IssuesClosed: prometheus.NewDesc(
82+
namespace+"issues_closed",
83+
"Number of closed Issues",
7884
nil, nil,
7985
),
8086
Labels: prometheus.NewDesc(
@@ -164,7 +170,8 @@ func (c Collector) Describe(ch chan<- *prometheus.Desc) {
164170
ch <- c.Comments
165171
ch <- c.Follows
166172
ch <- c.HookTasks
167-
ch <- c.Issues
173+
ch <- c.IssuesOpen
174+
ch <- c.IssuesClosed
168175
ch <- c.Labels
169176
ch <- c.LoginSources
170177
ch <- c.Milestones
@@ -217,9 +224,14 @@ func (c Collector) Collect(ch chan<- prometheus.Metric) {
217224
float64(stats.Counter.HookTask),
218225
)
219226
ch <- prometheus.MustNewConstMetric(
220-
c.Issues,
227+
c.IssuesClosed,
228+
prometheus.GaugeValue,
229+
float64(stats.Counter.IssueClosed),
230+
)
231+
ch <- prometheus.MustNewConstMetric(
232+
c.IssuesOpen,
221233
prometheus.GaugeValue,
222-
float64(stats.Counter.Issue),
234+
float64(stats.Counter.IssueOpen),
223235
)
224236
ch <- prometheus.MustNewConstMetric(
225237
c.Labels,

0 commit comments

Comments
 (0)