Skip to content

Commit 30290e1

Browse files
committed
backward compatibility
1 parent c18ba74 commit 30290e1

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

collector/health_collector.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ func (c *healthCollector) collect(ctx *collectorContext) error {
4242
}
4343

4444
for _, re := range stats {
45-
c.collectForStat(re, ctx)
45+
if metric, ok := re.Map["name"]; ok {
46+
c.collectMetricForProperty(metric, re, ctx)
47+
} else {
48+
c.collectForStat(re, ctx)
49+
}
4650
}
4751

4852
return nil
@@ -62,24 +66,36 @@ func (c *healthCollector) fetch(ctx *collectorContext) ([]*proto.Sentence, error
6266
}
6367

6468
func (c *healthCollector) collectForStat(re *proto.Sentence, ctx *collectorContext) {
69+
for _, p := range c.props[:3] {
70+
c.collectMetricForProperty(p, re, ctx)
71+
}
72+
}
73+
74+
func (c *healthCollector) collectMetricForProperty(property string, re *proto.Sentence, ctx *collectorContext) {
6575
var v float64
6676
var err error
6777

68-
if re.Map["value"] == "" {
69-
return
78+
name := property
79+
value := re.Map[property]
80+
81+
if value == "" {
82+
var ok bool
83+
if value, ok = re.Map["value"]; !ok {
84+
return
85+
}
7086
}
71-
v, err = strconv.ParseFloat(re.Map["value"], 64)
87+
v, err = strconv.ParseFloat(value, 64)
7288

7389
if err != nil {
7490
log.WithFields(log.Fields{
7591
"device": ctx.device.Name,
76-
"property": re.Map["name"],
77-
"value": re.Map["value"],
92+
"property": name,
93+
"value": value,
7894
"error": err,
7995
}).Error("error parsing system health metric value")
8096
return
8197
}
8298

83-
desc := c.descriptions[re.Map["name"]]
99+
desc := c.descriptions[name]
84100
ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, v, ctx.device.Name, ctx.device.Address)
85101
}

0 commit comments

Comments
 (0)