From 237da11722c3f7414112eeb5375b5bbbdfdc8c76 Mon Sep 17 00:00:00 2001 From: netixx Date: Mon, 11 Mar 2024 16:28:54 +0100 Subject: [PATCH 1/2] Enable remote_ip dimension in rtr_clients This makes the rtr_clients track the number of connections per remote IP, enabling us to see if a client flaps, and what client it is. --- cmd/stayrtr/stayrtr.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/stayrtr/stayrtr.go b/cmd/stayrtr/stayrtr.go index cbcbc5a..4554964 100644 --- a/cmd/stayrtr/stayrtr.go +++ b/cmd/stayrtr/stayrtr.go @@ -134,7 +134,7 @@ var ( Name: "rtr_clients", Help: "Number of clients connected.", }, - []string{"bind"}, + []string{"bind", "remote_ip"}, ) PDUsRecv = prometheus.NewCounterVec( prometheus.CounterOpts{ @@ -693,11 +693,11 @@ type metricsEvent struct { } func (m *metricsEvent) ClientConnected(c *rtr.Client) { - ClientsMetric.WithLabelValues(c.GetLocalAddress().String()).Inc() + ClientsMetric.WithLabelValues(c.GetLocalAddress().String(), c.GetRemoteAddress().String()).Inc() } func (m *metricsEvent) ClientDisconnected(c *rtr.Client) { - ClientsMetric.WithLabelValues(c.GetLocalAddress().String()).Dec() + ClientsMetric.WithLabelValues(c.GetLocalAddress().String(), c.GetRemoteAddress().String()).Dec() } func (m *metricsEvent) HandlePDU(c *rtr.Client, pdu rtr.PDU) { From 5bd78492f93fc58b32c12556db2c35dcbf1da09b Mon Sep 17 00:00:00 2001 From: netixx Date: Tue, 12 Mar 2024 12:31:24 +0100 Subject: [PATCH 2/2] Add flaps metrics and remote_ip in PDUs counter --- cmd/stayrtr/stayrtr.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd/stayrtr/stayrtr.go b/cmd/stayrtr/stayrtr.go index 4554964..4de91d2 100644 --- a/cmd/stayrtr/stayrtr.go +++ b/cmd/stayrtr/stayrtr.go @@ -136,12 +136,19 @@ var ( }, []string{"bind", "remote_ip"}, ) + ClientsFlaps = prometheus.NewCounterVec( + prometheus.CounterOpts{ + Name: "rtr_client_flaps", + Help: "Total count of connect/disconnect events per local and remote IP.", + }, + []string{"bind", "remote_ip"}, + ) PDUsRecv = prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "rtr_pdus", Help: "PDU received.", }, - []string{"type"}, + []string{"type", "remote_ip"}, ) CurrentSerial = prometheus.NewGauge( prometheus.GaugeOpts{ @@ -164,6 +171,7 @@ func initMetrics() { prometheus.MustRegister(LastRefresh) prometheus.MustRegister(RefreshStatusCode) prometheus.MustRegister(ClientsMetric) + prometheus.MustRegister(ClientsFlaps) prometheus.MustRegister(PDUsRecv) prometheus.MustRegister(CurrentSerial) } @@ -694,10 +702,12 @@ type metricsEvent struct { func (m *metricsEvent) ClientConnected(c *rtr.Client) { ClientsMetric.WithLabelValues(c.GetLocalAddress().String(), c.GetRemoteAddress().String()).Inc() + ClientsFlaps.WithLabelValues(c.GetLocalAddress().String(), c.GetRemoteAddress().String()).Add(1) } func (m *metricsEvent) ClientDisconnected(c *rtr.Client) { ClientsMetric.WithLabelValues(c.GetLocalAddress().String(), c.GetRemoteAddress().String()).Dec() + ClientsFlaps.WithLabelValues(c.GetLocalAddress().String(), c.GetRemoteAddress().String()).Add(1) } func (m *metricsEvent) HandlePDU(c *rtr.Client, pdu rtr.PDU) { @@ -707,7 +717,9 @@ func (m *metricsEvent) HandlePDU(c *rtr.Client, pdu rtr.PDU) { rtr.TypeToString( pdu.GetType()), " ", - "_", -1))).Inc() + "_", -1)), + c.GetRemoteAddress().String(), + ).Inc() } func (m *metricsEvent) UpdateMetrics(numIPv4 int, numIPv6 int, numIPv4filtered int, numIPv6filtered int, changed time.Time, refreshed time.Time, file string, brkCount int, aspaCount int) {