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 {
@@ -44,14 +42,18 @@ func (c *healthCollector) collect(ctx *collectorContext) error {
44
42
}
45
43
46
44
for _ , re := range stats {
47
- 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
+ }
48
50
}
49
51
50
52
return nil
51
53
}
52
54
53
55
func (c * healthCollector ) fetch (ctx * collectorContext ) ([]* proto.Sentence , error ) {
54
- reply , err := ctx .client .Run ("/system/health/print" , "=.proplist=" + strings . Join ( c . props , "," ) )
56
+ reply , err := ctx .client .Run ("/system/health/print" )
55
57
if err != nil {
56
58
log .WithFields (log.Fields {
57
59
"device" : ctx .device .Name ,
@@ -73,21 +75,27 @@ func (c *healthCollector) collectMetricForProperty(property string, re *proto.Se
73
75
var v float64
74
76
var err error
75
77
76
- if re .Map [property ] == "" {
77
- 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
+ }
78
86
}
79
- v , err = strconv .ParseFloat (re . Map [ property ] , 64 )
87
+ v , err = strconv .ParseFloat (value , 64 )
80
88
81
89
if err != nil {
82
90
log .WithFields (log.Fields {
83
91
"device" : ctx .device .Name ,
84
- "property" : property ,
85
- "value" : re . Map [ property ] ,
92
+ "property" : name ,
93
+ "value" : value ,
86
94
"error" : err ,
87
95
}).Error ("error parsing system health metric value" )
88
96
return
89
97
}
90
98
91
- desc := c .descriptions [property ]
99
+ desc := c .descriptions [name ]
92
100
ctx .ch <- prometheus .MustNewConstMetric (desc , prometheus .GaugeValue , v , ctx .device .Name , ctx .device .Address )
93
101
}
0 commit comments