Skip to content

Commit 943d2a4

Browse files
committed
Add support for hex values
1 parent 661af08 commit 943d2a4

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

exporter/collector.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"bytes"
1818
"encoding/json"
1919
"time"
20+
"math/big"
21+
"strings"
2022

2123
"github.com/go-kit/log"
2224
"github.com/go-kit/log/level"
@@ -91,6 +93,11 @@ func (mc JSONMetricCollector) Collect(ch chan<- prometheus.Metric) {
9193
continue
9294
}
9395

96+
// When value starts by '0x', convert hex to decimal
97+
if strings.HasPrefix(value, "0x") {
98+
value = formatHex(value)
99+
}
100+
94101
if floatValue, err := SanitizeValue(value); err == nil {
95102
metric := prometheus.MustNewConstMetric(
96103
m.Desc,
@@ -178,3 +185,11 @@ func timestampMetric(logger log.Logger, m JSONMetric, data []byte, pm prometheus
178185
timestamp := time.UnixMilli(epochTime)
179186
return prometheus.NewMetricWithTimestamp(timestamp, pm)
180187
}
188+
189+
func formatHex(s string) string {
190+
st := strings.Replace(s, "0x", "", -1)
191+
i := new(big.Int)
192+
i.SetString(st, 16)
193+
str := i.String()
194+
return str
195+
}

0 commit comments

Comments
 (0)