Skip to content

Commit 0f7d5be

Browse files
aeriffnshttpd
authored andcommitted
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=
1 parent 25911b4 commit 0f7d5be

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

collector/interface_collector.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,18 @@ func (c *interfaceCollector) collectForStat(re *proto.Sentence, ctx *collectorCo
7373

7474
func (c *interfaceCollector) collectMetricForProperty(property, iface, comment string, re *proto.Sentence, ctx *collectorContext) {
7575
desc := c.descriptions[property]
76-
v, err := strconv.ParseFloat(re.Map[property], 64)
77-
if err != nil {
78-
log.WithFields(log.Fields{
79-
"device": ctx.device.Name,
80-
"interface": iface,
81-
"property": property,
82-
"value": re.Map[property],
83-
"error": err,
84-
}).Error("error parsing interface metric value")
85-
return
76+
if value := re.Map[property]; value != "" {
77+
v, err := strconv.ParseFloat(value, 64)
78+
if err != nil {
79+
log.WithFields(log.Fields{
80+
"device": ctx.device.Name,
81+
"interface": iface,
82+
"property": property,
83+
"value": value,
84+
"error": err,
85+
}).Error("error parsing interface metric value")
86+
return
87+
}
88+
ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, v, ctx.device.Name, ctx.device.Address, iface, comment)
8689
}
87-
88-
ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.CounterValue, v, ctx.device.Name, ctx.device.Address, iface, comment)
8990
}

0 commit comments

Comments
 (0)