From e7275201cc66754cb23f7a4ad01bcc61a1a8bdc4 Mon Sep 17 00:00:00 2001 From: DJ Gill Date: Thu, 8 Feb 2024 11:16:27 -0500 Subject: [PATCH] Add Prometheus Metrics to Loadbalancers (#48) * nearly there, pushing for questions Signed-off-by: Dejon Gill dgill@equinix.com Signed-off-by: Dejon Gill * add prom metrics to server package Signed-off-by: Dejon Gill * Separate requested/released IP gauges Signed-off-by: Dejon Gill * Remove unused type PromGauge Signed-off-by: Dejon Gill --------- Signed-off-by: Dejon Gill dgill@equinix.com Signed-off-by: Dejon Gill --- internal/server/changes.go | 4 ++++ internal/server/prom.go | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 internal/server/prom.go diff --git a/internal/server/changes.go b/internal/server/changes.go index 97a94da..5e67ca0 100644 --- a/internal/server/changes.go +++ b/internal/server/changes.go @@ -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 @@ -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 diff --git a/internal/server/prom.go b/internal/server/prom.go new file mode 100644 index 0000000..e6c1f5b --- /dev/null +++ b/internal/server/prom.go @@ -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", + }, + ) +)