Skip to content

Commit

Permalink
Adjust prometheus client lin
Browse files Browse the repository at this point in the history
  • Loading branch information
tonobo committed Dec 25, 2023
1 parent 51dce96 commit 30e64b5
Showing 1 changed file with 29 additions and 29 deletions.
58 changes: 29 additions & 29 deletions lib/sma_exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -79,42 +79,42 @@ 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!
# sbfspot is sometimes missing the operating time, only update if possible
# 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!
Expand Down

0 comments on commit 30e64b5

Please sign in to comment.