1
1
package collector
2
2
3
3
import (
4
- "strconv"
5
- "strings"
6
-
7
4
"github.com/prometheus/client_golang/prometheus"
8
5
log "github.com/sirupsen/logrus"
9
6
"gopkg.in/routeros.v2/proto"
7
+ "strconv"
10
8
)
11
9
12
10
type healthCollector struct {
@@ -51,7 +49,7 @@ func (c *healthCollector) collect(ctx *collectorContext) error {
51
49
}
52
50
53
51
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" )
55
53
if err != nil {
56
54
log .WithFields (log.Fields {
57
55
"device" : ctx .device .Name ,
@@ -64,30 +62,24 @@ func (c *healthCollector) fetch(ctx *collectorContext) ([]*proto.Sentence, error
64
62
}
65
63
66
64
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 ) {
73
65
var v float64
74
66
var err error
75
67
76
- if re .Map [property ] == "" {
68
+ if re .Map ["value" ] == "" {
77
69
return
78
70
}
79
- v , err = strconv .ParseFloat (re .Map [property ], 64 )
71
+ v , err = strconv .ParseFloat (re .Map ["value" ], 64 )
80
72
81
73
if err != nil {
82
74
log .WithFields (log.Fields {
83
75
"device" : ctx .device .Name ,
84
- "property" : property ,
85
- "value" : re .Map [property ],
76
+ "property" : re . Map [ "name" ] ,
77
+ "value" : re .Map ["value" ],
86
78
"error" : err ,
87
79
}).Error ("error parsing system health metric value" )
88
80
return
89
81
}
90
82
91
- desc := c .descriptions [property ]
83
+ desc := c .descriptions [re . Map [ "name" ] ]
92
84
ctx .ch <- prometheus .MustNewConstMetric (desc , prometheus .GaugeValue , v , ctx .device .Name , ctx .device .Address )
93
85
}
0 commit comments