Browse Source

moved fixedLabels to promDesc

pull/4/head
sberk42 4 years ago
parent
commit
320ad2d613
  1. 13
      fritzbox_lua/lua_client.go
  2. 33
      main.go
  3. 24
      metrics-lua.json

13
fritzbox_lua/lua_client.go

@ -57,11 +57,10 @@ type LuaPage struct {
// LuaMetricValueDefinition definition for a single metric // LuaMetricValueDefinition definition for a single metric
type LuaMetricValueDefinition struct { type LuaMetricValueDefinition struct {
Path string Path string
Key string Key string
OkValue string OkValue string
Labels []string Labels []string
FixedLabels map[string]string
} }
// LuaMetricValue single value retrieved from lua page // LuaMetricValue single value retrieved from lua page
@ -110,10 +109,6 @@ func (lmvDef *LuaMetricValueDefinition) createValue(name string, value float64)
Labels: make(map[string]string), Labels: make(map[string]string),
} }
for l := range lmvDef.FixedLabels {
lmv.Labels[l] = lmvDef.FixedLabels[l]
}
return lmv return lmv
} }

33
main.go

@ -71,9 +71,10 @@ var (
) )
type JSON_PromDesc struct { type JSON_PromDesc struct {
FqName string `json:"fqName"` FqName string `json:"fqName"`
Help string `json:"help"` Help string `json:"help"`
VarLabels []string `json:"varLabels"` VarLabels []string `json:"varLabels"`
FixedLabels map[string]string `json:"fixedLabels"`
} }
type ActionArg struct { type ActionArg struct {
@ -110,14 +111,13 @@ type LuaLabelRename struct {
type LuaMetric struct { type LuaMetric struct {
// initialized loading JSON // initialized loading JSON
Path string `json:"path"` Path string `json:"path"`
Params string `json:"params"` Params string `json:"params"`
ResultPath string `json:"resultPath"` ResultPath string `json:"resultPath"`
ResultKey string `json:"resultKey"` ResultKey string `json:"resultKey"`
OkValue string `json:"okValue"` OkValue string `json:"okValue"`
FixedLabels map[string]string `json:"fixedLabels"` PromDesc JSON_PromDesc `json:"promDesc"`
PromDesc JSON_PromDesc `json:"promDesc"` PromType string `json:"promType"`
PromType string `json:"promType"`
// initialized at startup // initialized at startup
Desc *prometheus.Desc Desc *prometheus.Desc
@ -643,7 +643,7 @@ func main() {
labels[i] = strings.ToLower(l) 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.MetricType = getValueType(lm.PromType)
lm.LuaPage = lua.LuaPage{ lm.LuaPage = lua.LuaPage{
@ -652,11 +652,10 @@ func main() {
} }
lm.LuaMetricDef = lua.LuaMetricValueDefinition{ lm.LuaMetricDef = lua.LuaMetricValueDefinition{
Path: lm.ResultPath, Path: lm.ResultPath,
Key: lm.ResultKey, Key: lm.ResultKey,
OkValue: lm.OkValue, OkValue: lm.OkValue,
Labels: pd.VarLabels, Labels: pd.VarLabels,
FixedLabels: lm.FixedLabels,
} }
} }

24
metrics-lua.json

@ -92,13 +92,15 @@
"params": "page=ecoStat", "params": "page=ecoStat",
"resultPath": "data.ramusage.series.0", "resultPath": "data.ramusage.series.0",
"resultKey": "-1", "resultKey": "-1",
"fixedLabels": { "ram_type" : "Fixed" },
"promDesc": { "promDesc": {
"fqName": "gateway_data_ecostat_ramusage", "fqName": "gateway_data_ecostat_ramusage",
"help": "percentage of RAM utilization from data.lua?page=energy", "help": "percentage of RAM utilization from data.lua?page=energy",
"varLabels": [ "varLabels": [
"gateway", "ram_type" "gateway"
] ],
"fixedLabels": {
"ram_type" : "Fixed"
}
}, },
"promType": "GaugeValue" "promType": "GaugeValue"
}, },
@ -107,13 +109,15 @@
"params": "page=ecoStat", "params": "page=ecoStat",
"resultPath": "data.ramusage.series.1", "resultPath": "data.ramusage.series.1",
"resultKey": "-1", "resultKey": "-1",
"fixedLabels": { "ram_type" : "Dynamic" },
"promDesc": { "promDesc": {
"fqName": "gateway_data_ecostat_ramusage", "fqName": "gateway_data_ecostat_ramusage",
"help": "percentage of RAM utilization from data.lua?page=energy", "help": "percentage of RAM utilization from data.lua?page=energy",
"varLabels": [ "varLabels": [
"gateway", "ram_type" "gateway"
] ],
"fixedLabels": {
"ram_type" : "Dynamic"
}
}, },
"promType": "GaugeValue" "promType": "GaugeValue"
}, },
@ -122,13 +126,15 @@
"params": "page=ecoStat", "params": "page=ecoStat",
"resultPath": "data.ramusage.series.2", "resultPath": "data.ramusage.series.2",
"resultKey": "-1", "resultKey": "-1",
"fixedLabels": { "ram_type" : "Free" },
"promDesc": { "promDesc": {
"fqName": "gateway_data_ecostat_ramusage", "fqName": "gateway_data_ecostat_ramusage",
"help": "percentage of RAM utilization from data.lua?page=energy", "help": "percentage of RAM utilization from data.lua?page=energy",
"varLabels": [ "varLabels": [
"gateway", "ram_type" "gateway"
] ],
"fixedLabels": {
"ram_type" : "Free"
}
}, },
"promType": "GaugeValue" "promType": "GaugeValue"
}, },

Loading…
Cancel
Save