From 30e64b5ac242132825e76e6ac2b53c46f4f09fb6 Mon Sep 17 00:00:00 2001 From: Tim Foerster Date: Mon, 25 Dec 2023 14:42:10 +0100 Subject: [PATCH] Adjust prometheus client lin --- lib/sma_exporter.rb | 58 ++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/sma_exporter.rb b/lib/sma_exporter.rb index c98019c..40da01a 100644 --- a/lib/sma_exporter.rb +++ b/lib/sma_exporter.rb @@ -25,31 +25,31 @@ def type :counter end - def set(labels, value) - @values[label_set_for(labels)] = value.to_f + def set(value, labels: {}) + @store.set(labels: label_set_for(labels), val: value.to_f) end end - DC_POW = PC::Gauge.new(:sma_dc_power_kw, "DC Power") - DC_U = PC::Gauge.new(:sma_dc_voltage, "DC Voltage") - DC_I = PC::Gauge.new(:sma_dc_current, "DC Current") + DC_POW = PC::Gauge.new(:sma_dc_power_kw, docstring: "DC Power") + DC_U = PC::Gauge.new(:sma_dc_voltage, docstring: "DC Voltage") + DC_I = PC::Gauge.new(:sma_dc_current, docstring: "DC Current") - AC_POW = PC::Gauge.new(:sma_ac_power_kw, "AC Power") - AC_U = PC::Gauge.new(:sma_ac_voltage, "AC Voltage") - AC_I = PC::Gauge.new(:sma_ac_current, "AC Current") + AC_POW = PC::Gauge.new(:sma_ac_power_kw, docstring: "AC Power") + AC_U = PC::Gauge.new(:sma_ac_voltage, docstring: "AC Voltage") + AC_I = PC::Gauge.new(:sma_ac_current, docstring: "AC Current") - YIELD_TODAY_TOTAL = CustomCounter.new(:sma_yield_today_total, "Yield today") - YIELD_TOTAL = CustomCounter.new(:sma_yield_total, "Yield overall") + YIELD_TODAY_TOTAL = CustomCounter.new(:sma_yield_today_total, docstring: "Yield today") + YIELD_TOTAL = CustomCounter.new(:sma_yield_total, docstring: "Yield overall") - OPERATING_HOURS = CustomCounter.new(:sma_operating_hours, "Power on hours") - FEED_IN_TIME = CustomCounter.new(:sma_feed_in_hours, "Feed-in time") + OPERATING_HOURS = CustomCounter.new(:sma_operating_hours, docstring: "Power on hours") + FEED_IN_TIME = CustomCounter.new(:sma_feed_in_hours, docstring: "Feed-in time") - DEV_TEMP = PC::Gauge.new(:sma_device_temperature, "SMA device temperature") - DEV_STATE = PC::Gauge.new(:sma_device_state, "SMA device state") - DEV_SN = PC::Gauge.new(:sma_device_sn, "SMA device serialnumber") + DEV_TEMP = PC::Gauge.new(:sma_device_temperature, docstring: "SMA device temperature") + DEV_STATE = PC::Gauge.new(:sma_device_state, docstring: "SMA device state") + DEV_SN = PC::Gauge.new(:sma_device_sn, docstring: "SMA device serialnumber") - GRID_STATE = PC::Gauge.new(:sma_grid_state, "SMA grid state") - GRID_FREQ = PC::Gauge.new(:sma_grid_freq, "SMA grid state") + GRID_STATE = PC::Gauge.new(:sma_grid_state, docstring: "SMA grid state") + GRID_FREQ = PC::Gauge.new(:sma_grid_freq, docstring: "SMA grid state") module_function @@ -79,33 +79,33 @@ def register! def set_device! x = data.device - DEV_TEMP.set({},x[:temp]) + DEV_TEMP.set(x[:temp]) end def set_grid! x = data.grid - GRID_FREQ.set({},x[:freq]) + GRID_FREQ.set(x[:freq]) end def set_dc! data.dc.each do |x| - DC_POW.set({phase: x[:id]}, x[:power]) - DC_U.set({phase: x[:id]}, x[:voltage]) - DC_I.set({phase: x[:id]}, x[:current]) + DC_POW.set(x[:power], labels: {phase: x[:id]}) + DC_U.set(x[:voltage], labels: {phase: x[:id]}) + DC_I.set(x[:current], labels: {phase: x[:id]}) end end def set_ac! data.ac.each do |x| - AC_POW.set({phase: x[:id]}, x[:power]) - AC_U.set({phase: x[:id]}, x[:voltage]) - AC_I.set({phase: x[:id]}, x[:current]) + AC_POW.set(x[:power], labels: {phase: x[:id]}) + AC_U.set(x[:voltage], labels: {phase: x[:id]}) + AC_I.set(x[:current], labels: {phase: x[:id]}) end end def set_yield! - YIELD_TODAY_TOTAL.set({}, data.yield[:today]) - YIELD_TOTAL.set({}, data.yield[:total]) + YIELD_TODAY_TOTAL.set(data.yield[:today]) + YIELD_TOTAL.set(data.yield[:total]) end def set_operating_hours! @@ -113,8 +113,8 @@ def set_operating_hours! # to read them return if data.operating_hours[:power].zero? - OPERATING_HOURS.set({}, data.operating_hours[:power]) - FEED_IN_TIME.set({}, data.operating_hours[:feed_in]) + OPERATING_HOURS.set(data.operating_hours[:power]) + FEED_IN_TIME.set(data.operating_hours[:feed_in]) end def flush!