(out chan<- prometheus.Metric)
| 301 | } |
| 302 | |
| 303 | func (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 | } |
no test coverage detected