mirror of
https://github.com/nshttpd/mikrotik-exporter.git
synced 2025-01-02 17:48:04 +01:00
Handle empty properties when collecting interface metrics (#20)
Instead of logging an error, check if a property is empty before attempting to call strconv.ParseFloat on it. ERRO[0005] error parsing interface metric value device=gw error="strconv.ParseFloat: parsing \"\": invalid syntax" interface=ether2 property=tx-drop value=
This commit is contained in:
parent
25911b4e60
commit
0f7d5bea2c
@ -73,17 +73,18 @@ func (c *interfaceCollector) collectForStat(re *proto.Sentence, ctx *collectorCo
|
||||
|
||||
func (c *interfaceCollector) collectMetricForProperty(property, iface, comment string, re *proto.Sentence, ctx *collectorContext) {
|
||||
desc := c.descriptions[property]
|
||||
v, err := strconv.ParseFloat(re.Map[property], 64)
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"device": ctx.device.Name,
|
||||
"interface": iface,
|
||||
"property": property,
|
||||
"value": re.Map[property],
|
||||
"error": err,
|
||||
}).Error("error parsing interface metric value")
|
||||
return
|
||||
if value := re.Map[property]; value != "" {
|
||||
v, err := strconv.ParseFloat(value, 64)
|
||||
if err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"device": ctx.device.Name,
|
||||
"interface": iface,
|
||||
"property": property,
|
||||
"value": value,
|
||||
"error": err,
|
||||
}).Error("error parsing interface metric value")
|
||||
return
|
||||
}
|
||||
ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, v, ctx.device.Name, ctx.device.Address, iface, comment)
|
||||
}
|
||||
|
||||
ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, v, ctx.device.Name, ctx.device.Address, iface, comment)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user