8000 feat(api): metrics jobs, refresh each 9s (#3265) · ovh/cds@0e1b2ce · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 0e1b2ce

Browse files
yesnaultbnjjj
authored andcommitted
feat(api): metrics jobs, refresh each 9s (#3265)
Signed-off-by: Yvonnick Esnault <yvonnick.esnault@corp.ovh.com>
1 parent 34373ee commit 0e1b2ce

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

engine/api/metrics/metrics.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func Initialize(c context.Context, DBFunc func() *gorp.DbMap, instance string) {
3030
nbWorkflowRuns := prometheus.NewCounter(prometheus.CounterOpts{Name: "nb_workflow_runs", Help: "metrics nb_workflow_runs", ConstLabels: labels})
3131
nbWorkflowNodeRuns := prometheus.NewCounter(prometheus.CounterOpts{Name: "nb_workflow_node_runs", Help: "metrics nb_workflow_node_runs", ConstLabels: labels})
3232
nbMaxWorkersBuilding := prometheus.NewCounter(prometheus.CounterOpts{Name: "nb_max_workers_building", Help: "metrics nb_max_workers_building", ConstLabels: labels})
33+
nbJobs := prometheus.NewCounter(prometheus.CounterOpts{Name: "nb_jobs", Help: "nb_jobs", ConstLabels: labels})
3334
queue := prometheus.NewGaugeVec(prometheus.GaugeOpts{Name: "queue", Help: "metrics queue", ConstLabels: prometheus.Labels{"instance": instance}}, []string{"status", "range"})
3435

3536
registry.MustRegister(nbUsers)
@@ -43,9 +44,10 @@ func Initialize(c context.Context, DBFunc func() *gorp.DbMap, instance string) {
4344
registry.MustRegister(nbWorkflowRuns)
4445
registry.MustRegister(nbWorkflowNodeRuns)
4546
registry.MustRegister(nbMaxWorkersBuilding)
47+
registry.MustRegister(nbJobs)
4648
registry.MustRegister(queue)
4749

48-
tick := time.NewTicker(30 * time.Second).C
50+
tick := time.NewTicker(9 * time.Second).C
4951

5052
go func(c context.Context, DBFunc func() *gorp.DbMap) {
5153
for {
@@ -67,6 +69,7 @@ func Initialize(c context.Context, DBFunc func() *gorp.DbMap, instance string) {
6769
count(DBFunc(), nbWorkflowRuns, "SELECT MAX(id) FROM workflow_run")
6870
count(DBFunc(), nbWorkflowNodeRuns, "SELECT MAX(id) FROM workflow_node_run")
6971
count(DBFunc(), nbMaxWorkersBuilding, "SELECT COUNT(1) FROM worker where status = 'Building'")
72+
count(DBFunc(), nbJobs, "SELECT MAX(id) FROM workflow_node_run_job_info")
7073

7174
now := time.Now()
7275
now10s := now.Add(-10 * time.Second)
@@ -81,13 +84,13 @@ func Initialize(c context.Context, DBFunc func() *gorp.DbMap, instance string) {
8184
queryOld := "select COUNT(1) from workflow_node_run_job where queued < $1 and status = 'Waiting'"
8285

8386
countGauge(DBFunc(), *queue, "building", "all", queryBuilding)
84-
countGauge(DBFunc(), *queue, "waiting", "less_10s", query, now10s, now)
85-
countGauge(DBFunc(), *queue, "waiting", "more_10s_less_30s", query, now30s, now10s)
86-
countGauge(DBFunc(), *queue, "waiting", "more_30s_less_1min", query, now1min, now30s)
87-
countGauge(DBFunc(), *queue, "waiting", "more_1min_less_2min", query, now2min, now1min)
88-
countGauge(DBFunc(), *queue, "waiting", "more_2min_less_5min", query, now5min, now2min)
89-
countGauge(DBFunc(), *queue, "waiting", "more_5min_less_10min", query, now10min, now5min)
90-
countGauge(DBFunc(), *queue, "waiting", "more_10min", queryOld, now10min)
87+
countGauge(DBFunc(), *queue, "waiting", "10_less_10s", query, now10s, now)
88+
countGauge(DBFunc(), *queue, "waiting", "20_more_10s_less_30s", query, now30s, now10s)
89+
countGauge(DBFunc(), *queue, "waiting", "30_more_30s_less_1min", query, now1min, now30s)
90+
countGauge(DBFunc(), *queue, "waiting", "40_more_1min_less_2min", query, now2min, now1min)
91+
countGauge(DBFunc(), *queue, "waiting", "50_more_2min_less_5min", query, now5min, now2min)
92+
countGauge(DBFunc(), *queue, "waiting", "60_more_5min_less_10min", query, now10min, now5min)
93+
countGauge(DBFunc(), *queue, "waiting", "70_more_10min", queryOld, now10min)
9194
}
9295
}
9396
}(c, DBFunc)

0 commit comments

Comments
 (0)
0