MCPcopy
hub / github.com/osrg/gobgp / Collect

Method Collect

pkg/metrics/metrics.go:303–424  ·  view source on GitHub ↗
(out chan<- prometheus.Metric)

Source from the content-addressed store, hash-verified

301}
302
303func (c *bgpCollector) Collect(out chan<- prometheus.Metric) {
304 bgpServer, err := c.server.GetBgp(context.Background(), &api.GetBgpRequest{})
305 if err != nil {
306 out <- prometheus.NewInvalidMetric(prometheus.NewDesc("error", "error during metric collection", nil, nil), err)
307 return
308 }
309
310 req := &api.ListPeerRequest{EnableAdvertised: true}
311 err = c.server.ListPeer(context.Background(), req, func(p *api.Peer) {
312 peerState := p.GetState()
313 peerAddr := peerState.GetNeighborAddress()
314 peerTimers := p.GetTimers()
315 msg := peerState.GetMessages()
316
317 send := func(desc *prometheus.Desc, cnt uint64) {
318 out <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, float64(cnt), peerAddr)
319 }
320
321 // Statistics about BGP announcements we've received from our peers
322 send(bgpReceivedUpdateTotalDesc, msg.Received.Update)
323 send(bgpReceivedNotificationTotalDesc, msg.Received.Notification)
324 send(bgpReceivedOpenTotalDesc, msg.Received.Open)
325 send(bgpReceivedRefreshTotalDesc, msg.Received.Refresh)
326 send(bgpReceivedKeepaliveTotalDesc, msg.Received.Keepalive)
327 send(bgpReceivedWithdrawUpdateTotalDesc, msg.Received.WithdrawUpdate)
328 send(bgpReceivedWithdrawPrefixTotalDesc, msg.Received.WithdrawPrefix)
329 send(bgpReceivedDiscardedTotalDesc, msg.Received.Discarded)
330 send(bgpReceivedMessageTotalDesc, msg.Received.Total)
331
332 // Statistics about BGP announcements we've sent to our peers
333 send(bgpSentUpdateTotalDesc, msg.Sent.Update)
334 send(bgpSentNotificationTotalDesc, msg.Sent.Notification)
335 send(bgpSentOpenTotalDesc, msg.Sent.Open)
336 send(bgpSentRefreshTotalDesc, msg.Sent.Refresh)
337 send(bgpSentKeepaliveTotalDesc, msg.Sent.Keepalive)
338 send(bgpSentWithdrawUpdateTotalDesc, msg.Sent.WithdrawUpdate)
339 send(bgpSentWithdrawPrefixTotalDesc, msg.Sent.WithdrawPrefix)
340 send(bgpSentDiscardedTotalDesc, msg.Sent.Discarded)
341 send(bgpSentMessageTotalDesc, msg.Sent.Total)
342
343 // The outbound queue message size
344 send(bgpPeerOutQueueDesc, uint64(peerState.GetOutQ()))
345 // The number of neighbor flops
346 send(bgpPeerFlopsDesc, uint64(peerState.GetFlops()))
347 // Uptime in seconds of the session
348 send(bgpPeerUptimeDesc, uint64(peerTimers.GetState().GetUptime().GetSeconds()))
349 // Whether BGP community is being sent
350 send(bgpPeerSendCommunityFlagDesc, uint64(peerState.GetSendCommunity()))
351 // Whether BGP Private AS is being removed (1) or not (0)
352 send(bgpPeerRemovePrivateAsFlagDesc, uint64(peerState.GetRemovePrivate()))
353 // Peer Type (0) for internal, (1) for external
354 send(bgpPeerTypeDesc, uint64(peerState.GetType()))
355
356 // Whether authentication password is being set (1) or not (0)
357 passwordSetFlag := 0
358 if peerState.GetAuthPassword() != "" {
359 passwordSetFlag = 1
360 }

Callers 1

CollectMethod · 0.45

Calls 15

NewFamilyFunction · 0.92
GetMessagesMethod · 0.80
GetOutQMethod · 0.80
GetFlopsMethod · 0.80
GetAdminStateMethod · 0.80
GetAfiMethod · 0.80
GetSafiMethod · 0.80
GetAcceptedMethod · 0.80
GetBgpMethod · 0.65
ListPeerMethod · 0.65
GetTypeMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected