Skip to content

Commit

Permalink
prometheus: active worker gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
croissanne committed Apr 19, 2024
1 parent 1b4935c commit 68bc8e0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions internal/prometheus/worker_metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package prometheus

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

var (
ActiveWorkers = promauto.NewGaugeVec(prometheus.GaugeOpts{
Name: "active_workers",
Namespace: Namespace,
Subsystem: WorkerSubsystem,
Help: "Active workers",
}, []string{"worker", "tenant", "arch"})
)

func AddActiveWorker(worker, tenant, arch string) {
ActiveWorkers.WithLabelValues(worker, tenant, arch).Inc()
}

func RemoveActiveWorker(worker, tenant, arch string) {
ActiveWorkers.WithLabelValues(worker, tenant, arch).Dec()
}
3 changes: 3 additions & 0 deletions internal/worker/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ func (s *Server) WatchWorkers() {
err = s.jobs.DeleteWorker(w.ID)
if err != nil {
logrus.Warningf("Unable to remove worker: %v", err)
continue
}
prometheus.RemoveActiveWorker(w.ID.String(), w.Channel, w.Arch)
}
}
}
Expand Down Expand Up @@ -828,6 +830,7 @@ func (s *Server) RegisterWorker(c, a string) (uuid.UUID, error) {
if err != nil {
return uuid.Nil, err
}
prometheus.AddActiveWorker(workerID.String(), c, a)
logrus.Infof("Worker (%v) registered", a)
return workerID, nil
}
Expand Down

0 comments on commit 68bc8e0

Please sign in to comment.