Merge pull request #17 from WilliButz/add-bool-support

jsonexporter/scraper: add bool support
This commit is contained in:
Ben Kochie 2020-04-17 09:16:49 +02:00 committed by GitHub
commit c483776514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -80,6 +80,7 @@ func (vs *ValueScraper) Scrape(data []byte, reg *harness.MetricRegistry) error {
isFirst = false
var value float64
var boolValue bool
var err error
switch result.Type {
case jsonpath.JsonNumber:
@ -89,6 +90,12 @@ func (vs *ValueScraper) Scrape(data []byte, reg *harness.MetricRegistry) error {
value, err = vs.parseValue(result.Value[1 : len(result.Value)-1])
case jsonpath.JsonNull:
value = math.NaN()
case jsonpath.JsonBool:
if boolValue, err = strconv.ParseBool(string(result.Value)); boolValue {
value = 1
} else {
value = 0
}
default:
log.Warnf("skipping not numerical result;path:<%v>,value:<%s>",
vs.valueJsonPath, result.Value)