Skip to content

Commit af7f192

Browse files
authored
Merge pull request #1125 from alvaroaleman/moar-metrics
✨ Add metrics for total workers and active workers
2 parents d12bb87 + 5cefa42 commit af7f192

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pkg/internal/controller/controller.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func (c *Controller) Start(stop <-chan struct{}) error {
169169

170170
// Launch workers to process resources
171171
c.Log.Info("Starting workers", "worker count", c.MaxConcurrentReconciles)
172+
ctrlmetrics.WorkerCount.WithLabelValues(c.Name).Set(float64(c.MaxConcurrentReconciles))
172173
for i := 0; i < c.MaxConcurrentReconciles; i++ {
173174
// Process work items
174175
go wait.Until(c.worker, c.JitterPeriod, stop)
@@ -210,6 +211,9 @@ func (c *Controller) processNextWorkItem() bool {
210211
// period.
211212
defer c.Queue.Done(obj)
212213

214+
ctrlmetrics.ActiveWorkers.WithLabelValues(c.Name).Add(1)
215+
defer ctrlmetrics.ActiveWorkers.WithLabelValues(c.Name).Add(-1)
216+
213217
return c.reconcileHandler(obj)
214218
}
215219

pkg/internal/controller/metrics/metrics.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,29 @@ var (
4444
Name: "controller_runtime_reconcile_time_seconds",
4545
Help: "Length of time per reconciliation per controller",
4646
}, []string{"controller"})
47+
48+
// WorkerCount is a prometheus metric which holds the number of
49+
// concurrent reconciles per controller
50+
WorkerCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{
51+
Name: "controller_runtime_max_concurrent_reconciles",
52+
Help: "Maximum number of concurrent reconciles per controller",
53+
}, []string{"controller"})
54+
55+
// ActiveWorkers is a prometheus metric which holds the number
56+
// of active workers per controller
57+
ActiveWorkers = prometheus.NewGaugeVec(prometheus.GaugeOpts{
58+
Name: "controller_runtime_active_workers",
59+
Help: "Number of currently used workers per controller",
60+
}, []string{"controller"})
4761
)
4862

4963
func init() {
5064
metrics.Registry.MustRegister(
5165
ReconcileTotal,
5266
ReconcileErrors,
5367
ReconcileTime,
68+
WorkerCount,
69+
ActiveWorkers,
5470
// expose process metrics like CPU, Memory, file descriptor usage etc.
5571
prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}),
5672
// expose Go runtime metrics like GC stats, memory stats etc.

0 commit comments

Comments
 (0)