Fix routes collector to be compatible with latest RouterOS release (#66)

* Fix routes collector to be compatible with latest RouterOS release

Tested on RouterOS 6.46.1

* remove ipv6 pool collector
This commit is contained in:
Daniel Hodges
2020-02-03 21:33:02 -05:00
committed by GitHub
parent 5cea9840a7
commit c00607abe0
3 changed files with 16 additions and 30 deletions

View File

@@ -30,17 +30,7 @@ func (c *poolCollector) describe(ch chan<- *prometheus.Desc) {
} }
func (c *poolCollector) collect(ctx *collectorContext) error { func (c *poolCollector) collect(ctx *collectorContext) error {
err := c.collectForIPVersion("4", "ip", ctx) return c.collectForIPVersion("4", "ip", ctx)
if err != nil {
return err
}
err = c.collectForIPVersion("6", "ipv6", ctx)
if err != nil {
return err
}
return nil
} }
func (c *poolCollector) collectForIPVersion(ipVersion, topic string, ctx *collectorContext) error { func (c *poolCollector) collectForIPVersion(ipVersion, topic string, ctx *collectorContext) error {

View File

@@ -119,20 +119,20 @@ func parseUptime(uptime string) (float64, error) {
// should get one and only one match back on the regex // should get one and only one match back on the regex
if len(reMatch) != 1 { if len(reMatch) != 1 {
return 0, fmt.Errorf("invalid uptime value sent to regex") return 0, fmt.Errorf("invalid uptime value sent to regex")
} else { }
for i, match := range reMatch[0] {
if match != "" && i != 0 { for i, match := range reMatch[0] {
v, err := strconv.Atoi(match) if match != "" && i != 0 {
if err != nil { v, err := strconv.Atoi(match)
log.WithFields(log.Fields{ if err != nil {
"uptime": uptime, log.WithFields(log.Fields{
"value": match, "uptime": uptime,
"error": err, "value": match,
}).Error("error parsing uptime field value") "error": err,
return float64(0), err }).Error("error parsing uptime field value")
} return float64(0), err
u += time.Duration(v) * uptimeParts[i-1]
} }
u += time.Duration(v) * uptimeParts[i-1]
} }
} }
return u.Seconds(), nil return u.Seconds(), nil

View File

@@ -40,12 +40,7 @@ func (c *routesCollector) collect(ctx *collectorContext) error {
return err return err
} }
err = c.colllectForIPVersion("6", "ipv6", ctx) return c.colllectForIPVersion("6", "ip", ctx)
if err != nil {
return err
}
return nil
} }
func (c *routesCollector) colllectForIPVersion(ipVersion, topic string, ctx *collectorContext) error { func (c *routesCollector) colllectForIPVersion(ipVersion, topic string, ctx *collectorContext) error {
@@ -70,6 +65,7 @@ func (c *routesCollector) colllectCount(ipVersion, topic string, ctx *collectorC
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"ip_version": ipVersion, "ip_version": ipVersion,
"device": ctx.device.Name, "device": ctx.device.Name,
"topic": topic,
"error": err, "error": err,
}).Error("error fetching routes metrics") }).Error("error fetching routes metrics")
return err return err