diff --git a/cmd/stayrtr/stayrtr.go b/cmd/stayrtr/stayrtr.go index cbcbc5a..4de91d2 100644 --- a/cmd/stayrtr/stayrtr.go +++ b/cmd/stayrtr/stayrtr.go @@ -134,14 +134,21 @@ var ( Name: "rtr_clients", Help: "Number of clients connected.", }, - []string{"bind"}, + []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) } @@ -693,11 +701,13 @@ 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() + ClientsFlaps.WithLabelValues(c.GetLocalAddress().String(), c.GetRemoteAddress().String()).Add(1) } func (m *metricsEvent) ClientDisconnected(c *rtr.Client) { - ClientsMetric.WithLabelValues(c.GetLocalAddress().String()).Dec() + 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) {