mirror of
https://github.com/nshttpd/mikrotik-exporter.git
synced 2025-01-04 18:07:50 +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) {
|
func (c *interfaceCollector) collectMetricForProperty(property, iface, comment string, re *proto.Sentence, ctx *collectorContext) {
|
||||||
desc := c.descriptions[property]
|
desc := c.descriptions[property]
|
||||||
v, err := strconv.ParseFloat(re.Map[property], 64)
|
if value := re.Map[property]; value != "" {
|
||||||
if err != nil {
|
v, err := strconv.ParseFloat(value, 64)
|
||||||
log.WithFields(log.Fields{
|
if err != nil {
|
||||||
"device": ctx.device.Name,
|
log.WithFields(log.Fields{
|
||||||
"interface": iface,
|
"device": ctx.device.Name,
|
||||||
"property": property,
|
"interface": iface,
|
||||||
"value": re.Map[property],
|
"property": property,
|
||||||
"error": err,
|
"value": value,
|
||||||
}).Error("error parsing interface metric value")
|
"error": err,
|
||||||
return
|
}).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