From 03efbbfafe3a2902d23e6c2c3ac64d0c4209a967 Mon Sep 17 00:00:00 2001 From: Jan Grewe Date: Tue, 22 Sep 2020 11:56:28 +0200 Subject: [PATCH] Non-working fix for newer varnishstat JSON with metrics in the "counters" object ``` { "version": 1, "timestamp": "2020-09-22T11:55:40", "counters": { "MGT.uptime": { "description": "Management process uptime", "flag": "c", "format": "d", "value": 4725 }, ... ``` --- varnish.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/varnish.go b/varnish.go index 4e1d058..e400467 100644 --- a/varnish.go +++ b/varnish.go @@ -67,8 +67,15 @@ func ScrapeVarnishFrom(buf []byte, ch chan<- prometheus.Metric) ([]byte, error) return buf, err } - for vName, raw := range metricsJSON { - if vName == "timestamp" { + countersJSON := make(map[string]interface{}) + if metricsJSON["version"] == 1 { + countersJSON = metricsJSON["counters"] + } else { + countersJSON = metricsJSON + } + + for vName, raw := range countersJSON { + if vName == "version" || vName == "timestamp" { continue } if dt := reflect.TypeOf(raw); dt.Kind() != reflect.Map {