Skip to content

Commit

Permalink
metrics: add bgp_routes_advertised metric
Browse files Browse the repository at this point in the history
  • Loading branch information
anitgandhi authored and fujita committed May 22, 2024
1 parent e2e1f76 commit 076e9fc
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions internal/pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ var (
"Number of routes accepted from peer",
rfLabels, nil,
)
bgpRoutesAdvertisedDesc = prometheus.NewDesc(
"bgp_routes_advertised",
"Number of routes advertised to peer",
rfLabels, nil,
)
)

func NewBgpCollector(server *server.BgpServer) prometheus.Collector {
Expand Down Expand Up @@ -82,10 +87,11 @@ func (c *bgpCollector) Describe(out chan<- *prometheus.Desc) {

out <- bgpRoutesReceivedDesc
out <- bgpRoutesAcceptedDesc
out <- bgpRoutesAdvertisedDesc
}

func (c *bgpCollector) Collect(out chan<- prometheus.Metric) {
req := &api.ListPeerRequest{EnableAdvertised: false}
req := &api.ListPeerRequest{EnableAdvertised: true}
err := c.server.ListPeer(context.Background(), req, func(p *api.Peer) {
peerState := p.GetState()
peerAddr := peerState.GetNeighborAddress()
Expand Down Expand Up @@ -128,21 +134,29 @@ func (c *bgpCollector) Collect(out chan<- prometheus.Metric) {
if !afiSafi.GetConfig().GetEnabled() {
continue
}
afiState := afiSafi.GetState()
family := bgp.AfiSafiToRouteFamily(
uint16(afiSafi.GetState().GetFamily().GetAfi()),
uint8(afiSafi.GetState().GetFamily().GetSafi()),
uint16(afiState.GetFamily().GetAfi()),
uint8(afiState.GetFamily().GetSafi()),
).String()
labelValues := []string{peerAddr, family}
out <- prometheus.MustNewConstMetric(
bgpRoutesReceivedDesc,
prometheus.GaugeValue,
float64(afiSafi.GetState().GetReceived()),
peerAddr, family,
float64(afiState.GetReceived()),
labelValues...,
)
out <- prometheus.MustNewConstMetric(
bgpRoutesAcceptedDesc,
prometheus.GaugeValue,
float64(afiSafi.GetState().GetAccepted()),
peerAddr, family,
float64(afiState.GetAccepted()),
labelValues...,
)
out <- prometheus.MustNewConstMetric(
bgpRoutesAdvertisedDesc,
prometheus.GaugeValue,
float64(afiState.GetAdvertised()),
labelValues...,
)
}
})
Expand Down

0 comments on commit 076e9fc

Please sign in to comment.