Skip to content

Commit 25eee16

Browse files
committed
add cron inflight metric
1 parent 96246b9 commit 25eee16

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

services/cron/tasks.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@ import (
1919
"code.gitea.io/gitea/modules/process"
2020
"code.gitea.io/gitea/modules/setting"
2121
"code.gitea.io/gitea/modules/translation"
22+
"github.com/prometheus/client_golang/prometheus"
23+
"github.com/prometheus/client_golang/prometheus/promauto"
2224
)
2325

2426
var (
27+
cronInflight = promauto.NewGauge(prometheus.GaugeOpts{
28+
Namespace: "gitea",
29+
Subsystem: "cron",
30+
Name: "active_tasks",
31+
Help: "Number of running cron tasks",
32+
})
2533
lock = sync.Mutex{}
2634
started = false
2735
tasks = []*Task{}
@@ -86,6 +94,8 @@ func (t *Task) RunWithUser(doer *user_model.User, config Config) {
8694
taskStatusTable.Stop(t.Name)
8795
}()
8896
graceful.GetManager().RunWithShutdownContext(func(baseCtx context.Context) {
97+
cronInflight.Inc()
98+
defer cronInflight.Dec()
8999
defer func() {
90100
if err := recover(); err != nil {
91101
// Recover a panic within the execution of the task.

0 commit comments

Comments
 (0)