mirror of
https://github.com/nshttpd/mikrotik-exporter.git
synced 2025-02-21 01:11:21 +01:00
Health Collector fix
This commit is contained in:
parent
dc93f93f62
commit
c18ba74b8c
@ -1,12 +1,10 @@
|
|||||||
package collector
|
package collector
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"gopkg.in/routeros.v2/proto"
|
"gopkg.in/routeros.v2/proto"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type healthCollector struct {
|
type healthCollector struct {
|
||||||
@ -51,7 +49,7 @@ func (c *healthCollector) collect(ctx *collectorContext) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *healthCollector) fetch(ctx *collectorContext) ([]*proto.Sentence, error) {
|
func (c *healthCollector) fetch(ctx *collectorContext) ([]*proto.Sentence, error) {
|
||||||
reply, err := ctx.client.Run("/system/health/print", "=.proplist="+strings.Join(c.props, ","))
|
reply, err := ctx.client.Run("/system/health/print")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"device": ctx.device.Name,
|
"device": ctx.device.Name,
|
||||||
@ -64,30 +62,24 @@ func (c *healthCollector) fetch(ctx *collectorContext) ([]*proto.Sentence, error
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *healthCollector) collectForStat(re *proto.Sentence, ctx *collectorContext) {
|
func (c *healthCollector) collectForStat(re *proto.Sentence, ctx *collectorContext) {
|
||||||
for _, p := range c.props[:3] {
|
|
||||||
c.collectMetricForProperty(p, re, ctx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *healthCollector) collectMetricForProperty(property string, re *proto.Sentence, ctx *collectorContext) {
|
|
||||||
var v float64
|
var v float64
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if re.Map[property] == "" {
|
if re.Map["value"] == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
v, err = strconv.ParseFloat(re.Map[property], 64)
|
v, err = strconv.ParseFloat(re.Map["value"], 64)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(log.Fields{
|
log.WithFields(log.Fields{
|
||||||
"device": ctx.device.Name,
|
"device": ctx.device.Name,
|
||||||
"property": property,
|
"property": re.Map["name"],
|
||||||
"value": re.Map[property],
|
"value": re.Map["value"],
|
||||||
"error": err,
|
"error": err,
|
||||||
}).Error("error parsing system health metric value")
|
}).Error("error parsing system health metric value")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
desc := c.descriptions[property]
|
desc := c.descriptions[re.Map["name"]]
|
||||||
ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, v, ctx.device.Name, ctx.device.Address)
|
ctx.ch <- prometheus.MustNewConstMetric(desc, prometheus.GaugeValue, v, ctx.device.Name, ctx.device.Address)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user