Skip to content

Commit c18ba74

Browse files
committed
Health Collector fix
1 parent dc93f93 commit c18ba74

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

collector/health_collector.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package collector
22

33
import (
4-
"strconv"
5-
"strings"
6-
74
"github.com/prometheus/client_golang/prometheus"
85
log "github.com/sirupsen/logrus"
96
"gopkg.in/routeros.v2/proto"
7+
"strconv"
108
)
119

1210
type healthCollector struct {
@@ -51,7 +49,7 @@ func (c *healthCollector) collect(ctx *collectorContext) error {
5149
}
5250

5351
func (c *healthCollector) fetch(ctx *collectorContext) ([]*proto.Sentence, error) {
54-
reply, err := ctx.client.Run("/system/health/print", "=.proplist="+strings.Join(c.props, ","))
52+
reply, err := ctx.client.Run("/system/health/print")
5553
if err != nil {
5654
log.WithFields(log.Fields{
5755
"device": ctx.device.Name,
@@ -64,30 +62,24 @@ func (c *healthCollector) fetch(ctx *collectorContext) ([]*proto.Sentence, error
6462
}
6563

6664
func (c *healthCollector) collectForStat(re *proto.Sentence, ctx *collectorContext) {
67-
for _, p := range c.props[:3] {
68-
c.collectMetricForProperty(p, re, ctx)
69-
}
70-
}
71-
72-
func (c *healthCollector) collectMetricForProperty(property string, re *proto.Sentence, ctx *collectorContext) {
7365
var v float64
7466
var err error
7567

76-
if re.Map[property] == "" {
68+
if re.Map["value"] == "" {
7769
return
7870
}
79-
v, err = strconv.ParseFloat(re.Map[property], 64)
71+
v, err = strconv.ParseFloat(re.Map["value"], 64)
8072

8173
if err != nil {
8274
log.WithFields(log.Fields{
8375
"device": ctx.device.Name,
84-
"property": property,
85-
"value": re.Map[property],
76+
"property": re.Map["name"],
77+
"value": re.Map["value"],
8678
"error": err,
8779
}).Error("error parsing system health metric value")
8880
return
8981
}
9082

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

0 commit comments

Comments
 (0)