diff --git a/exporter/collector.go b/exporter/collector.go index 4effc10f..b9a5ab10 100644 --- a/exporter/collector.go +++ b/exporter/collector.go @@ -17,6 +17,8 @@ import ( "bytes" "encoding/json" "time" + "math/big" + "strings" "github.com/go-kit/log" "github.com/go-kit/log/level" @@ -91,6 +93,11 @@ func (mc JSONMetricCollector) Collect(ch chan<- prometheus.Metric) { continue } + // When value starts by '0x', convert hex to decimal + if strings.HasPrefix(value, "0x") { + value = formatHex(value) + } + if floatValue, err := SanitizeValue(value); err == nil { metric := prometheus.MustNewConstMetric( m.Desc, @@ -178,3 +185,11 @@ func timestampMetric(logger log.Logger, m JSONMetric, data []byte, pm prometheus timestamp := time.UnixMilli(epochTime) return prometheus.NewMetricWithTimestamp(timestamp, pm) } + +func formatHex(s string) string { + st := strings.Replace(s, "0x", "", -1) + i := new(big.Int) + i.SetString(st, 16) + str := i.String() + return str +}