@@ -16,7 +16,7 @@ package collector
16
16
17
17
import (
18
18
"encoding/json"
19
- "errors "
19
+ "fmt "
20
20
"io/ioutil"
21
21
"net/http"
22
22
"regexp"
@@ -95,15 +95,15 @@ func (collector *GenericCollector) Collect() (time.Time, []v2.Metric, error) {
95
95
96
96
matchString := regex .FindStringSubmatch (string (pageContent ))
97
97
if matchString != nil {
98
- if strings . Contains ( matchString [ 1 ], "." ) {
98
+ if metricConfig . Units == "float" {
99
99
regVal , err := strconv .ParseFloat (strings .TrimSpace (matchString [1 ]), 64 )
100
100
if err != nil {
101
101
errorSlice = append (errorSlice , err )
102
102
}
103
103
metrics [ind ].FloatPoints = []v2.FloatPoint {
104
104
{Value : regVal , Timestamp : currentTime },
105
105
}
106
- } else {
106
+ } else if metricConfig . Units == "integer" || metricConfig . Units == "int" {
107
107
regVal , err := strconv .ParseInt (strings .TrimSpace (matchString [1 ]), 10 , 64 )
108
108
if err != nil {
109
109
errorSlice = append (errorSlice , err )
@@ -112,9 +112,11 @@ func (collector *GenericCollector) Collect() (time.Time, []v2.Metric, error) {
112
112
{Value : regVal , Timestamp : currentTime },
113
113
}
114
114
115
+ } else {
116
+ errorSlice = append (errorSlice , fmt .Errorf ("Unexpected value of 'units' for metric '%v' in config " , metricConfig .Name ))
115
117
}
116
118
} else {
117
- errorSlice = append (errorSlice , errors . New ("No match found for metric regexp: " + metricConfig .Regex ))
119
+ errorSlice = append (errorSlice , fmt . Errorf ("No match found for regexp: %v for metric '%v' in config" , metricConfig .Regex , metricConfig . Name ))
118
120
}
119
121
120
122
metrics [ind ].Name = metricConfig .Name
0 commit comments