From 320ad2d6132240295e07bb704d0df338a4ad8825 Mon Sep 17 00:00:00 2001 From: sberk42 Date: Fri, 4 Dec 2020 16:49:36 +0100 Subject: [PATCH] moved fixedLabels to promDesc --- fritzbox_lua/lua_client.go | 13 ++++--------- main.go | 33 ++++++++++++++++----------------- metrics-lua.json | 24 +++++++++++++++--------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/fritzbox_lua/lua_client.go b/fritzbox_lua/lua_client.go index 0322a41..29c25ae 100644 --- a/fritzbox_lua/lua_client.go +++ b/fritzbox_lua/lua_client.go @@ -57,11 +57,10 @@ type LuaPage struct { // LuaMetricValueDefinition definition for a single metric type LuaMetricValueDefinition struct { - Path string - Key string - OkValue string - Labels []string - FixedLabels map[string]string + Path string + Key string + OkValue string + Labels []string } // LuaMetricValue single value retrieved from lua page @@ -110,10 +109,6 @@ func (lmvDef *LuaMetricValueDefinition) createValue(name string, value float64) Labels: make(map[string]string), } - for l := range lmvDef.FixedLabels { - lmv.Labels[l] = lmvDef.FixedLabels[l] - } - return lmv } diff --git a/main.go b/main.go index 6c71406..5a35784 100644 --- a/main.go +++ b/main.go @@ -71,9 +71,10 @@ var ( ) type JSON_PromDesc struct { - FqName string `json:"fqName"` - Help string `json:"help"` - VarLabels []string `json:"varLabels"` + FqName string `json:"fqName"` + Help string `json:"help"` + VarLabels []string `json:"varLabels"` + FixedLabels map[string]string `json:"fixedLabels"` } type ActionArg struct { @@ -110,14 +111,13 @@ type LuaLabelRename struct { type LuaMetric struct { // initialized loading JSON - Path string `json:"path"` - Params string `json:"params"` - ResultPath string `json:"resultPath"` - ResultKey string `json:"resultKey"` - OkValue string `json:"okValue"` - FixedLabels map[string]string `json:"fixedLabels"` - PromDesc JSON_PromDesc `json:"promDesc"` - PromType string `json:"promType"` + Path string `json:"path"` + Params string `json:"params"` + ResultPath string `json:"resultPath"` + ResultKey string `json:"resultKey"` + OkValue string `json:"okValue"` + PromDesc JSON_PromDesc `json:"promDesc"` + PromType string `json:"promType"` // initialized at startup Desc *prometheus.Desc @@ -643,7 +643,7 @@ func main() { labels[i] = strings.ToLower(l) } - lm.Desc = prometheus.NewDesc(pd.FqName, pd.Help, labels, nil) + lm.Desc = prometheus.NewDesc(pd.FqName, pd.Help, labels, pd.FixedLabels) lm.MetricType = getValueType(lm.PromType) lm.LuaPage = lua.LuaPage{ @@ -652,11 +652,10 @@ func main() { } lm.LuaMetricDef = lua.LuaMetricValueDefinition{ - Path: lm.ResultPath, - Key: lm.ResultKey, - OkValue: lm.OkValue, - Labels: pd.VarLabels, - FixedLabels: lm.FixedLabels, + Path: lm.ResultPath, + Key: lm.ResultKey, + OkValue: lm.OkValue, + Labels: pd.VarLabels, } } diff --git a/metrics-lua.json b/metrics-lua.json index 7b0045b..2166377 100644 --- a/metrics-lua.json +++ b/metrics-lua.json @@ -92,13 +92,15 @@ "params": "page=ecoStat", "resultPath": "data.ramusage.series.0", "resultKey": "-1", - "fixedLabels": { "ram_type" : "Fixed" }, "promDesc": { "fqName": "gateway_data_ecostat_ramusage", "help": "percentage of RAM utilization from data.lua?page=energy", "varLabels": [ - "gateway", "ram_type" - ] + "gateway" + ], + "fixedLabels": { + "ram_type" : "Fixed" + } }, "promType": "GaugeValue" }, @@ -107,13 +109,15 @@ "params": "page=ecoStat", "resultPath": "data.ramusage.series.1", "resultKey": "-1", - "fixedLabels": { "ram_type" : "Dynamic" }, "promDesc": { "fqName": "gateway_data_ecostat_ramusage", "help": "percentage of RAM utilization from data.lua?page=energy", "varLabels": [ - "gateway", "ram_type" - ] + "gateway" + ], + "fixedLabels": { + "ram_type" : "Dynamic" + } }, "promType": "GaugeValue" }, @@ -122,13 +126,15 @@ "params": "page=ecoStat", "resultPath": "data.ramusage.series.2", "resultKey": "-1", - "fixedLabels": { "ram_type" : "Free" }, "promDesc": { "fqName": "gateway_data_ecostat_ramusage", "help": "percentage of RAM utilization from data.lua?page=energy", "varLabels": [ - "gateway", "ram_type" - ] + "gateway" + ], + "fixedLabels": { + "ram_type" : "Free" + } }, "promType": "GaugeValue" },