feat: export panel settings (name, max power, offset) as prometheus metrics
This commit is contained in:
parent
b42fff8d5f
commit
9eff5f228b
@ -15,6 +15,8 @@ private:
|
||||
|
||||
void addField(AsyncResponseStream* stream, String& serial, uint8_t idx, std::shared_ptr<InverterAbstract> 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<InverterAbstract> inv, ChannelType_t type, ChannelNum_t channel);
|
||||
|
||||
AsyncWebServer* _server;
|
||||
|
||||
enum {
|
||||
|
||||
@ -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);
|
||||
@ -119,3 +120,49 @@ void WebApiPrometheusClass::addField(AsyncResponseStream* stream, String& serial
|
||||
inv->Statistics()->getChannelFieldValue(type, channel, fieldId));
|
||||
}
|
||||
}
|
||||
|
||||
void WebApiPrometheusClass::addPanelInfo(AsyncResponseStream* stream, String& serial, uint8_t idx, std::shared_ptr<InverterAbstract> 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
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user