From 71e4ec2273504689e75a8bf65021afb4db023997 Mon Sep 17 00:00:00 2001 From: WilliButz Date: Tue, 21 Aug 2018 02:04:29 +0200 Subject: [PATCH] jsonexporter/scraper: add bool support --- jsonexporter/scraper.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/jsonexporter/scraper.go b/jsonexporter/scraper.go index 89e2157..d112c0b 100644 --- a/jsonexporter/scraper.go +++ b/jsonexporter/scraper.go @@ -67,6 +67,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: @@ -76,6 +77,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:<%s>,value:<%s>", vs.valueJsonPath, result.Value)