From 72367da04f46073cc13699de010340941ad36892 Mon Sep 17 00:00:00 2001 From: sberk42 Date: Sun, 5 Jul 2020 10:55:02 +0200 Subject: [PATCH] made action reuse work without ordered metrics --- main.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 49b7bb0..a0ba1fa 100644 --- a/main.go +++ b/main.go @@ -123,12 +123,12 @@ func (fc *FritzboxCollector) Collect(ch chan<- prometheus.Metric) { } var err error - var last_service string - var last_method string - var last_result upnp.Result + var result_map = make(map[string]upnp.Result) for _, m := range metrics { - if m.Service != last_service || m.Action != last_method { + m_key := m.Service+"|"+m.Action + last_result := result_map[m_key]; + if last_result == nil { service, ok := root.Services[m.Service] if !ok { // TODO @@ -149,6 +149,8 @@ func (fc *FritzboxCollector) Collect(ch chan<- prometheus.Metric) { collect_errors.Inc() continue } + + result_map[m_key]=last_result } val, ok := last_result[m.Result]