Skip to content

Commit

Permalink
Add Prometheus Metrics to Loadbalancers (#48)
Browse files Browse the repository at this point in the history
* nearly there, pushing for questions

Signed-off-by: Dejon Gill [email protected]
Signed-off-by: Dejon Gill <[email protected]>

* add prom metrics to server package

Signed-off-by: Dejon Gill <[email protected]>

* Separate requested/released IP gauges

Signed-off-by: Dejon Gill <[email protected]>

* Remove unused type PromGauge

Signed-off-by: Dejon Gill <[email protected]>

---------

Signed-off-by: Dejon Gill [email protected]
Signed-off-by: Dejon Gill <[email protected]>
  • Loading branch information
itsmed authored Feb 8, 2024
1 parent c767bb5 commit e727520
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/server/changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func (s *Server) processLoadBalancerChangeCreate(ctx context.Context, lb *loadba
AdditionalSubjectIDs: []gidx.PrefixedID{gidx.PrefixedID(lb.LbData.Location.ID)},
}

numberIPsRequestedGauge.Inc()

if _, err := s.EventsConnection.PublishEvent(ctx, "load-balancer", msg); err != nil {
s.Logger.Debugw("failed to publish event", "error", err, "ip", ip, "loadbalancer", lb.LoadBalancerID, "block", s.IPBlock)
return err
Expand Down Expand Up @@ -55,6 +57,8 @@ func (s *Server) processLoadBalancerChangeDelete(ctx context.Context, lb *loadba
AdditionalSubjectIDs: []gidx.PrefixedID{gidx.PrefixedID(lb.LbData.Location.ID)},
}

numberIPsReleasedGauge.Inc()

if _, err := s.EventsConnection.PublishEvent(ctx, "load-balancer", msg); err != nil {
s.Logger.Debugw("failed to publish event", "error", err, "loadbalancer", lb.LoadBalancerID, "block", s.IPBlock)
return err
Expand Down
25 changes: 25 additions & 0 deletions internal/server/prom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package server

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

const subsystem = "loadbalancer_provider_haproxy"

var (
numberIPsRequestedGauge = promauto.NewGauge(
prometheus.GaugeOpts{
Subsystem: subsystem,
Name: "ips_requested_count",
Help: "The total number of IPs requested",
},
)
numberIPsReleasedGauge = promauto.NewGauge(
prometheus.GaugeOpts{
Subsystem: subsystem,
Name: "ips_released_count",
Help: "The total number of IPs released",
},
)
)

0 comments on commit e727520

Please sign in to comment.