Skip to content
Snippets Groups Projects
Commit 3e153bae authored by Oliver Herms's avatar Oliver Herms
Browse files

Add BMP session status metric

parent 340700fb
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@ const (
)
var (
bmpSessionEstablishedDesc *prometheus.Desc
routeMonitoringMessagesDesc *prometheus.Desc
statisticsReportMessages *prometheus.Desc
peerDownNotificationMessages *prometheus.Desc
......@@ -28,6 +29,7 @@ var (
func init() {
labels := []string{"router"}
bmpSessionEstablishedDesc = prometheus.NewDesc(prefix+"session_established", "Indicates if a BMP session is established", labels, nil)
routeMonitoringMessagesDesc = prometheus.NewDesc(prefix+"route_monitoring_messages", "Returns number of received route monitoring messages", labels, nil)
statisticsReportMessages = prometheus.NewDesc(prefix+"statistics_report_messages", "Returns number of received statistics report messages", labels, nil)
peerDownNotificationMessages = prometheus.NewDesc(prefix+"peer_down_messages", "Returns number of received peer down notification messages", labels, nil)
......@@ -49,6 +51,7 @@ type bmpCollector struct {
// Describe conforms to the prometheus collector interface
func (c *bmpCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- bmpSessionEstablishedDesc
ch <- routeMonitoringMessagesDesc
ch <- statisticsReportMessages
ch <- peerDownNotificationMessages
......@@ -77,6 +80,12 @@ func (c *bmpCollector) Collect(ch chan<- prometheus.Metric) {
func (c *bmpCollector) collectForRouter(ch chan<- prometheus.Metric, rtr *metrics.BMPRouterMetrics) {
l := []string{rtr.Name}
established := 0
if rtr.Established {
established = 1
}
ch <- prometheus.MustNewConstMetric(bmpSessionEstablishedDesc, prometheus.GaugeValue, float64(established), l...)
ch <- prometheus.MustNewConstMetric(routeMonitoringMessagesDesc, prometheus.CounterValue, float64(rtr.RouteMonitoringMessages), l...)
ch <- prometheus.MustNewConstMetric(statisticsReportMessages, prometheus.CounterValue, float64(rtr.StatisticsReportMessages), l...)
ch <- prometheus.MustNewConstMetric(peerDownNotificationMessages, prometheus.CounterValue, float64(rtr.PeerDownNotificationMessages), l...)
......
......@@ -14,6 +14,9 @@ type BMPRouterMetrics struct {
// Name of the monitored routers
Name string
// Status of TCP session
Established bool
// Count of received RouteMonitoringMessages
RouteMonitoringMessages uint64
......
......@@ -30,8 +30,11 @@ func (b *bmpMetricsService) routerMetrics() []*metrics.BMPRouterMetrics {
}
func (b *bmpMetricsService) metricsForRouter(rtr *Router) *metrics.BMPRouterMetrics {
established := atomic.LoadUint32(&rtr.established)
rm := &metrics.BMPRouterMetrics{
Name: rtr.name,
Established: established == 1,
RouteMonitoringMessages: atomic.LoadUint64(&rtr.counters.routeMonitoringMessages),
StatisticsReportMessages: atomic.LoadUint64(&rtr.counters.statisticsReportMessages),
PeerDownNotificationMessages: atomic.LoadUint64(&rtr.counters.peerDownNotificationMessages),
......
......@@ -20,12 +20,14 @@ import (
"github.com/bio-routing/tflow2/convert"
)
// Router represents a BMP enabled route in BMP context
type Router struct {
name string
nameMu sync.RWMutex
address net.IP
port uint16
con net.Conn
established uint32
reconnectTimeMin int
reconnectTimeMax int
reconnectTime int
......@@ -79,14 +81,17 @@ func newRouter(addr net.IP, port uint16) *Router {
}
}
// GetVRF get's a VRF
func (r *Router) GetVRF(rd uint64) *vrf.VRF {
return r.vrfRegistry.GetVRFByRD(rd)
}
// GetVRFs gets all VRFs
func (r *Router) GetVRFs() []*vrf.VRF {
return r.vrfRegistry.List()
}
// Name gets a routers name
func (r *Router) Name() string {
r.nameMu.RLock()
defer r.nameMu.RUnlock()
......
......@@ -5,6 +5,7 @@ import (
"io"
"net"
"sync"
"sync/atomic"
"time"
"github.com/bio-routing/bio-rd/protocols/bgp/metrics"
......@@ -68,10 +69,12 @@ func (b *BMPServer) AddRouter(addr net.IP, port uint16) {
continue
}
atomic.StoreUint32(&r.established, 1)
r.reconnectTime = r.reconnectTimeMin
r.reconnectTimer = time.NewTimer(time.Second * time.Duration(r.reconnectTime))
log.Infof("Connected to %s", r.address.String())
r.serve(c)
atomic.StoreUint32(&r.established, 0)
}
}(r)
}
......@@ -126,6 +129,7 @@ func recvBMPMsg(c net.Conn) (msg []byte, err error) {
return buffer[0:toRead], nil
}
// GetRouters gets all routers
func (b *BMPServer) GetRouters() []*Router {
b.routersMu.RLock()
defer b.routersMu.RUnlock()
......@@ -138,6 +142,7 @@ func (b *BMPServer) GetRouters() []*Router {
return r
}
// GetRouter gets a router
func (b *BMPServer) GetRouter(name string) *Router {
b.routersMu.RLock()
defer b.routersMu.RUnlock()
......@@ -153,6 +158,7 @@ func (b *BMPServer) GetRouter(name string) *Router {
return nil
}
// Metrics gets BMP server metrics
func (b *BMPServer) Metrics() (*metrics.BMPMetrics, error) {
if b.metrics == nil {
return nil, fmt.Errorf("Server not started yet")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment