From eb9269527d39776939b76a65f83f5891de276414 Mon Sep 17 00:00:00 2001 From: Daniel Czerwonk Date: Mon, 21 May 2018 22:56:21 +0200 Subject: [PATCH] fixed bgp collector (#12) --- collector/bgp_collector.go | 14 +++++--------- collector/collector.go | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/collector/bgp_collector.go b/collector/bgp_collector.go index d27caa0..c9e7aec 100644 --- a/collector/bgp_collector.go +++ b/collector/bgp_collector.go @@ -67,15 +67,11 @@ func (c *bgpCollector) fetch(ctx *collectorContext) ([]*proto.Sentence, error) { } func (c *bgpCollector) collectForStat(re *proto.Sentence, ctx *collectorContext) { - var session, asn string - for _, p := range c.props { - if p == "name" { - session = re.Map[p] - } else if p == "remote-as" { - asn = re.Map[p] - } else { - c.collectMetricForProperty(p, session, asn, re, ctx) - } + asn := re.Map["remote-as"] + session := re.Map["name"] + + for _, p := range c.props[2:] { + c.collectMetricForProperty(p, session, asn, re, ctx) } } diff --git a/collector/collector.go b/collector/collector.go index aee6db5..30775a8 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -46,7 +46,7 @@ type collector struct { // WithBGP enables BGP routing metrics func WithBGP() Option { return func(c *collector) { - c.collectors = append(c.collectors, &bgpCollector{}) + c.collectors = append(c.collectors, newBGPCollector()) } }