Skip to content

Commit

Permalink
Merge pull request #1125 from alvaroaleman/moar-metrics
Browse files Browse the repository at this point in the history
✨ Add metrics for total workers and active workers
  • Loading branch information
k8s-ci-robot committed Aug 18, 2020
2 parents d12bb87 + 5cefa42 commit af7f192
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ func (c *Controller) Start(stop <-chan struct{}) error {

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

ctrlmetrics.ActiveWorkers.WithLabelValues(c.Name).Add(1)
defer ctrlmetrics.ActiveWorkers.WithLabelValues(c.Name).Add(-1)

return c.reconcileHandler(obj)
}

Expand Down
16 changes: 16 additions & 0 deletions pkg/internal/controller/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,29 @@ var (
Name: "controller_runtime_reconcile_time_seconds",
Help: "Length of time per reconciliation per controller",
}, []string{"controller"})

// WorkerCount is a prometheus metric which holds the number of
// concurrent reconciles per controller
WorkerCount = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "controller_runtime_max_concurrent_reconciles",
Help: "Maximum number of concurrent reconciles per controller",
}, []string{"controller"})

// ActiveWorkers is a prometheus metric which holds the number
// of active workers per controller
ActiveWorkers = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "controller_runtime_active_workers",
Help: "Number of currently used workers per controller",
}, []string{"controller"})
)

func init() {
metrics.Registry.MustRegister(
ReconcileTotal,
ReconcileErrors,
ReconcileTime,
WorkerCount,
ActiveWorkers,
// expose process metrics like CPU, Memory, file descriptor usage etc.
prometheus.NewProcessCollector(prometheus.ProcessCollectorOpts{}),
// expose Go runtime metrics like GC stats, memory stats etc.
Expand Down

0 comments on commit af7f192

Please sign in to comment.