@@ -65,22 +65,21 @@ func (mc JSONMetricCollector) Collect(ch chan<- prometheus.Metric) {
6565 floatValue ,
6666 extractLabels (mc .Logger , mc .Data , m .LabelsJSONPaths )... ,
6767 )
68+ } else {
69+ intValue , err := SanitizeHexIntValue (value )
70+ if err == nil {
71+ ch <- prometheus .MustNewConstMetric (
72+ m .Desc ,
73+ m .ValueType ,
74+ float64 (intValue ),
75+ extractLabels (mc .Logger , mc .Data , m .LabelsJSONPaths )... ,
76+ )
77+ } else {
78+ level .Error (mc .Logger ).Log ("msg" , "Failed to convert extracted value to float64" , "path" , m .KeyJSONPath , "value" , value , "err" , err , "metric" , m .Desc )
79+ continue
80+ }
6881 }
6982
70- intValue , err := SanitizeHexIntValue (value )
71- if err == nil {
72- ch <- prometheus .MustNewConstMetric (
73- m .Desc ,
74- prometheus .UntypedValue ,
75- float64 (intValue ),
76- extractLabels (mc .Logger , mc .Data , m .LabelsJSONPaths )... ,
77- )
78- }
79-
80-
81- level .Error (mc .Logger ).Log ("msg" , "Failed to convert extracted value to float64" , "path" , m .KeyJSONPath , "value" , value , "err" , err , "metric" , m .Desc )
82- continue
83-
8483 case config .ObjectScrape :
8584 values , err := extractValue (mc .Logger , mc .Data , m .KeyJSONPath , true )
8685 if err != nil {
@@ -102,7 +101,8 @@ func (mc JSONMetricCollector) Collect(ch chan<- prometheus.Metric) {
102101 continue
103102 }
104103
105- if floatValue , err := SanitizeValue (value ); err == nil {
104+ floatValue , err := SanitizeValue (value )
105+ if err == nil {
106106 metric := prometheus .MustNewConstMetric (
107107 m .Desc ,
108108 m .ValueType ,
@@ -111,8 +111,18 @@ func (mc JSONMetricCollector) Collect(ch chan<- prometheus.Metric) {
111111 )
112112 ch <- timestampMetric (mc .Logger , m , jdata , metric )
113113 } else {
114- level .Error (mc .Logger ).Log ("msg" , "Failed to convert extracted value to float64" , "path" , m .ValueJSONPath , "value" , value , "err" , err , "metric" , m .Desc )
115- continue
114+ intValue , err := SanitizeHexIntValue (value )
115+ if err == nil {
116+ ch <- prometheus .MustNewConstMetric (
117+ m .Desc ,
118+ m .ValueType ,
119+ float64 (intValue ),
120+ extractLabels (mc .Logger , mc .Data , m .LabelsJSONPaths )... ,
121+ )
122+ } else {
123+ level .Error (mc .Logger ).Log ("msg" , "Failed to convert extracted value to float64" , "path" , m .ValueJSONPath , "value" , value , "err" , err , "metric" , m .Desc )
124+ continue
125+ }
116126 }
117127 }
118128 } else {
0 commit comments