From 9eff5f228b03837c21564b9567a32ab5e427c971 Mon Sep 17 00:00:00 2001 From: Markus Dobel Date: Wed, 8 Mar 2023 09:11:25 +0100 Subject: [PATCH] feat: export panel settings (name, max power, offset) as prometheus metrics --- include/WebApi_prometheus.h | 2 ++ src/WebApi_prometheus.cpp | 49 ++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/include/WebApi_prometheus.h b/include/WebApi_prometheus.h index 5eb894ee..f2b5b66a 100644 --- a/include/WebApi_prometheus.h +++ b/include/WebApi_prometheus.h @@ -15,6 +15,8 @@ private: void addField(AsyncResponseStream* stream, String& serial, uint8_t idx, std::shared_ptr inv, ChannelType_t type, ChannelNum_t channel, FieldId_t fieldId, const char* channelName = NULL); + void addPanelInfo(AsyncResponseStream* stream, String& serial, uint8_t idx, std::shared_ptr inv, ChannelType_t type, ChannelNum_t channel); + AsyncWebServer* _server; enum { diff --git a/src/WebApi_prometheus.cpp b/src/WebApi_prometheus.cpp index 8b59f9b7..f037c237 100644 --- a/src/WebApi_prometheus.cpp +++ b/src/WebApi_prometheus.cpp @@ -69,6 +69,7 @@ void WebApiPrometheusClass::onPrometheusMetricsGet(AsyncWebServerRequest* reques if (inv->Statistics()->getLastUpdate() > 0) { for (auto& t : inv->Statistics()->getChannelTypes()) { for (auto& c : inv->Statistics()->getChannelsByType(t)) { + addPanelInfo(stream, serial, i, inv, t, c); addField(stream, serial, i, inv, t, c, FLD_PAC); addField(stream, serial, i, inv, t, c, FLD_UAC); addField(stream, serial, i, inv, t, c, FLD_IAC); @@ -118,4 +119,50 @@ void WebApiPrometheusClass::addField(AsyncResponseStream* stream, String& serial channel, inv->Statistics()->getChannelFieldValue(type, channel, fieldId)); } -} \ No newline at end of file +} + +void WebApiPrometheusClass::addPanelInfo(AsyncResponseStream* stream, String& serial, uint8_t idx, std::shared_ptr inv, ChannelType_t type, ChannelNum_t channel) +{ + if (type != TYPE_DC) { + return; + } + + const CONFIG_T& config = Configuration.get(); + + const bool printHelp = (idx == 0 && channel == 0); + if (printHelp) { + stream->print(F("# HELP opendtu_PanelInfo panel information\n")); + stream->print(F("# TYPE opendtu_PanelInfo gauge\n")); + } + stream->printf("opendtu_PanelInfo{serial=\"%s\",unit=\"%d\",name=\"%s\",channel=\"%d\",panelname=\"%s\"} 1\n", + serial.c_str(), + idx, + inv->name(), + channel, + config.Inverter[idx].channel[channel].Name + ); + + if (printHelp) { + stream->print(F("# HELP opendtu_MaxPower panel maximum output power\n")); + stream->print(F("# TYPE opendtu_MaxPower gauge\n")); + } + stream->printf("opendtu_MaxPower{serial=\"%s\",unit=\"%d\",name=\"%s\",channel=\"%d\"} %d\n", + serial.c_str(), + idx, + inv->name(), + channel, + config.Inverter[idx].channel[channel].MaxChannelPower + ); + + if (printHelp) { + stream->print(F("# HELP opendtu_YieldTotalOffset panel yield offset (for used inverters)\n")); + stream->print(F("# TYPE opendtu_YieldTotalOffset gauge\n")); + } + stream->printf("opendtu_YieldTotalOffset{serial=\"%s\",unit=\"%d\",name=\"%s\",channel=\"%d\"} %f\n", + serial.c_str(), + idx, + inv->name(), + channel, + config.Inverter[idx].channel[channel].YieldTotalOffset + ); +}