mirror of
https://github.com/lumapu/ahoy.git
synced 2025-07-27 13:17:11 +02:00
added further inverter and alarm info to prometheus endpoint
This commit is contained in:
parent
edefcf1c83
commit
e7fff27a4a
2 changed files with 74 additions and 27 deletions
|
@ -5,22 +5,23 @@ Prometheus metrics provided at `/metrics`.
|
||||||
|
|
||||||
## Labels
|
## Labels
|
||||||
| Label name | Description |
|
| Label name | Description |
|
||||||
|:-----------|:--------------------------------------|
|
|:-------------|:--------------------------------------|
|
||||||
| version | current installed version of AhoyDTU |
|
| version | current installed version of AhoyDTU |
|
||||||
| image | currently not used |
|
| image | currently not used |
|
||||||
| devicename | Device name from setup |
|
| devicename | Device name from setup |
|
||||||
| name | Inverter name from setup |
|
| name | Inverter name from setup |
|
||||||
| serial | Serial number of inverter |
|
| serial | Serial number of inverter |
|
||||||
| enabled | Communication enable for inverter |
|
|
||||||
| inverter | Inverter name from setup |
|
| inverter | Inverter name from setup |
|
||||||
| channel | Channel name from setup |
|
| channel | Channel name from setup |
|
||||||
|
|
||||||
|
|
||||||
## Exported Metrics
|
## Exported Metrics
|
||||||
| Metric name | Type | Description | Labels |
|
| Metric name | Type | Description | Labels |
|
||||||
|----------------------------------------|---------|--------------------------------------------------------|--------------|
|
|----------------------------------------|---------|--------------------------------------------------------|--------------|
|
||||||
| `ahoy_solar_info` | Gauge | Information about the AhoyDTU device | version, image, devicename |
|
| `ahoy_solar_info` | Gauge | Information about the AhoyDTU device | version, image, devicename |
|
||||||
| `ahoy_solar_inverter_info` | Gauge | Information about the configured inverter(s) | name, serial, enabled |
|
| `ahoy_solar_inverter_info` | Gauge | Information about the configured inverter(s) | name, serial |
|
||||||
|
| `ahoy_solar_inverter_enabled` | Gauge | Is the inverter enabled? | inverter |
|
||||||
|
| `ahoy_solar_inverter_is_available` | Gauge | is the inverter available? | inverter |
|
||||||
|
| `ahoy_solar_inverter_is_producing` | Gauge | Is the inverter producing? | inverter |
|
||||||
| `ahoy_solar_U_AC_volt` | Gauge | AC voltage of inverter [V] | inverter |
|
| `ahoy_solar_U_AC_volt` | Gauge | AC voltage of inverter [V] | inverter |
|
||||||
| `ahoy_solar_I_AC_ampere` | Gauge | AC current of inverter [A] | inverter |
|
| `ahoy_solar_I_AC_ampere` | Gauge | AC current of inverter [A] | inverter |
|
||||||
| `ahoy_solar_P_AC_watt` | Gauge | AC power of inverter [W] | inverter |
|
| `ahoy_solar_P_AC_watt` | Gauge | AC power of inverter [W] | inverter |
|
||||||
|
@ -28,7 +29,8 @@ Prometheus metrics provided at `/metrics`.
|
||||||
| `ahoy_solar_F_AC_hertz` | Gauge | AC frequency [Hz] | inverter |
|
| `ahoy_solar_F_AC_hertz` | Gauge | AC frequency [Hz] | inverter |
|
||||||
| `ahoy_solar_PF_AC` | Gauge | AC Power factor | inverter |
|
| `ahoy_solar_PF_AC` | Gauge | AC Power factor | inverter |
|
||||||
| `ahoy_solar_Temp_celsius` | Gauge | Temperature of inverter | inverter |
|
| `ahoy_solar_Temp_celsius` | Gauge | Temperature of inverter | inverter |
|
||||||
| `ahoy_solar_ALARM_MES_ID` | Gauge | Last alarm message id of inverter | inverter |
|
| `ahoy_solar_ALARM_MES_ID` | Gauge | Alarm message index of inverter | inverter |
|
||||||
|
| `ahoy_solar_LastAlarmCode` | Gauge | Last alarm code from inverter | inverter |
|
||||||
| `ahoy_solar_YieldDay_wattHours` | Counter | Energy converted to AC per day [Wh] | inverter |
|
| `ahoy_solar_YieldDay_wattHours` | Counter | Energy converted to AC per day [Wh] | inverter |
|
||||||
| `ahoy_solar_YieldTotal_kilowattHours` | Counter | Energy converted to AC since reset [kWh] | inverter |
|
| `ahoy_solar_YieldTotal_kilowattHours` | Counter | Energy converted to AC since reset [kWh] | inverter |
|
||||||
| `ahoy_solar_P_DC_watt` | Gauge | DC power of inverter [W] | inverter |
|
| `ahoy_solar_P_DC_watt` | Gauge | DC power of inverter [W] | inverter |
|
||||||
|
|
|
@ -735,7 +735,7 @@ class Web {
|
||||||
|
|
||||||
#ifdef ENABLE_PROMETHEUS_EP
|
#ifdef ENABLE_PROMETHEUS_EP
|
||||||
enum {
|
enum {
|
||||||
metricsStateStart, metricsStateInverter, metricStateChannel,metricsStateEnd
|
metricsStateStart, metricsStateInverter, metricStateRealtimeData,metricsStateAlarmData,metricsStateEnd
|
||||||
} metricsStep;
|
} metricsStep;
|
||||||
int metricsInverterId,metricsChannelId;
|
int metricsInverterId,metricsChannelId;
|
||||||
|
|
||||||
|
@ -749,15 +749,22 @@ class Web {
|
||||||
Inverter<> *iv;
|
Inverter<> *iv;
|
||||||
record_t<> *rec;
|
record_t<> *rec;
|
||||||
statistics_t *stat;
|
statistics_t *stat;
|
||||||
|
String promUnit, promType;
|
||||||
String metrics;
|
String metrics;
|
||||||
char type[60], topic[100], val[25];
|
char type[60], topic[100], val[25];
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
int alarmChannelId;
|
||||||
|
|
||||||
switch (metricsStep) {
|
switch (metricsStep) {
|
||||||
case metricsStateStart: // System Info & NRF Statistics : fit to one packet
|
case metricsStateStart: // System Info & NRF Statistics : fit to one packet
|
||||||
snprintf(topic,sizeof(topic),"# TYPE ahoy_solar_info gauge\nahoy_solar_info{version=\"%s\",image=\"\",devicename=\"%s\"} 1\n",
|
snprintf(type,sizeof(type),"# TYPE ahoy_solar_info gauge\n");
|
||||||
|
snprintf(topic,sizeof(topic),"ahoy_solar_info{version=\"%s\",image=\"\",devicename=\"%s\"} 1\n",
|
||||||
mApp->getVersion(), mConfig->sys.deviceName);
|
mApp->getVersion(), mConfig->sys.deviceName);
|
||||||
metrics = topic;
|
metrics = String(type) + String(topic);
|
||||||
|
|
||||||
|
snprintf(topic,sizeof(topic),"# TYPE ahoy_solar_freeheap gauge\nahoy_solar_freeheap{devicename=\"%s\"} %u\n",mConfig->sys.deviceName,ESP.getFreeHeap());
|
||||||
|
metrics += String(topic);
|
||||||
|
|
||||||
// NRF Statistics
|
// NRF Statistics
|
||||||
stat = mApp->getStatistics();
|
stat = mApp->getStatistics();
|
||||||
metrics += radioStatistic(F("rx_success"), stat->rxSuccess);
|
metrics += radioStatistic(F("rx_success"), stat->rxSuccess);
|
||||||
|
@ -776,24 +783,40 @@ class Web {
|
||||||
if (metricsInverterId < mSys->getNumInverters()) {
|
if (metricsInverterId < mSys->getNumInverters()) {
|
||||||
iv = mSys->getInverterByPos(metricsInverterId);
|
iv = mSys->getInverterByPos(metricsInverterId);
|
||||||
if(NULL != iv) {
|
if(NULL != iv) {
|
||||||
// Inverter info
|
// Inverter info : fit to one packet
|
||||||
len = snprintf((char *)buffer, maxLen, "ahoy_solar_inverter_info{name=\"%s\",serial=\"%12llx\",enabled=\"%d\"} 1\n",
|
snprintf(type,sizeof(type),"# TYPE ahoy_solar_inverter_info gauge\n");
|
||||||
iv->config->name, iv->config->serial.u64,iv->config->enabled);
|
snprintf(topic,sizeof(topic),"ahoy_solar_inverter_info{name=\"%s\",serial=\"%12llx\"} 1\n",
|
||||||
// Start Channel loop for this inverter
|
iv->config->name, iv->config->serial.u64);
|
||||||
|
metrics = String(type) + String(topic);
|
||||||
|
|
||||||
|
snprintf(type,sizeof(type),"# TYPE ahoy_solar_inverter_is_enabled gauge\n");
|
||||||
|
snprintf(topic,sizeof(topic),"ahoy_solar_inverter_is_enabled {inverter=\"%s\"} %d\n",iv->config->name,iv->config->enabled);
|
||||||
|
metrics += String(type) + String(topic);
|
||||||
|
|
||||||
|
snprintf(type,sizeof(type),"# TYPE ahoy_solar_inverter_is_available gauge\n");
|
||||||
|
snprintf(topic,sizeof(topic),"ahoy_solar_inverter_is_available {inverter=\"%s\"} %d\n",iv->config->name,iv->isAvailable(mApp->getTimestamp()));
|
||||||
|
metrics += String(type) + String(topic);
|
||||||
|
|
||||||
|
snprintf(type,sizeof(type),"# TYPE ahoy_solar_inverter_is_producing gauge\n");
|
||||||
|
snprintf(topic,sizeof(topic),"ahoy_solar_inverter_is_producing {inverter=\"%s\"} %d\n",iv->config->name,iv->isProducing(mApp->getTimestamp()));
|
||||||
|
metrics += String(type) + String(topic);
|
||||||
|
|
||||||
|
len = snprintf((char *)buffer,maxLen,"%s",metrics.c_str());
|
||||||
|
|
||||||
|
// Start Realtime Data Channel loop for this inverter
|
||||||
metricsChannelId = 0;
|
metricsChannelId = 0;
|
||||||
metricsStep = metricStateChannel;
|
metricsStep = metricStateRealtimeData;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
metricsStep = metricsStateEnd;
|
metricsStep = metricsStateEnd;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case metricStateChannel: // Channel loop
|
case metricStateRealtimeData: // Realtime Data Channel loop
|
||||||
iv = mSys->getInverterByPos(metricsInverterId);
|
iv = mSys->getInverterByPos(metricsInverterId);
|
||||||
rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
rec = iv->getRecordStruct(RealTimeRunData_Debug);
|
||||||
if (metricsChannelId < rec->length) {
|
if (metricsChannelId < rec->length) {
|
||||||
uint8_t channel = rec->assign[metricsChannelId].ch;
|
uint8_t channel = rec->assign[metricsChannelId].ch;
|
||||||
String promUnit, promType;
|
|
||||||
std::tie(promUnit, promType) = convertToPromUnits(iv->getUnit(metricsChannelId, rec));
|
std::tie(promUnit, promType) = convertToPromUnits(iv->getUnit(metricsChannelId, rec));
|
||||||
snprintf(type, sizeof(type), "# TYPE ahoy_solar_%s%s %s", iv->getFieldName(metricsChannelId, rec), promUnit.c_str(), promType.c_str());
|
snprintf(type, sizeof(type), "# TYPE ahoy_solar_%s%s %s", iv->getFieldName(metricsChannelId, rec), promUnit.c_str(), promType.c_str());
|
||||||
if (0 == channel) {
|
if (0 == channel) {
|
||||||
|
@ -808,10 +831,32 @@ class Web {
|
||||||
} else {
|
} else {
|
||||||
len = snprintf((char*)buffer,maxLen,"#\n"); // At least one char to send otherwise the transmission ends.
|
len = snprintf((char*)buffer,maxLen,"#\n"); // At least one char to send otherwise the transmission ends.
|
||||||
|
|
||||||
// All channels processed --> try next inverter
|
// All realtime data channels processed --> try alarm data
|
||||||
|
metricsStep = metricsStateAlarmData;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case metricsStateAlarmData: // Alarm Info loop
|
||||||
|
iv = mSys->getInverterByPos(metricsInverterId);
|
||||||
|
rec = iv->getRecordStruct(AlarmData);
|
||||||
|
// simple hack : there is only one channel with alarm data
|
||||||
|
// TODO: find the right one channel with the alarm id
|
||||||
|
alarmChannelId = 0;
|
||||||
|
// printf("AlarmData Length %d\n",rec->length);
|
||||||
|
if (alarmChannelId < rec->length)
|
||||||
|
{
|
||||||
|
//uint8_t channel = rec->assign[alarmChannelId].ch;
|
||||||
|
std::tie(promUnit, promType) = convertToPromUnits(iv->getUnit(alarmChannelId, rec));
|
||||||
|
snprintf(type, sizeof(type), "# TYPE ahoy_solar_%s%s %s", iv->getFieldName(alarmChannelId, rec), promUnit.c_str(), promType.c_str());
|
||||||
|
snprintf(topic, sizeof(topic), "ahoy_solar_%s%s{inverter=\"%s\"}", iv->getFieldName(alarmChannelId, rec), promUnit.c_str(), iv->config->name);
|
||||||
|
snprintf(val, sizeof(val), "%.3f", iv->getValue(alarmChannelId, rec));
|
||||||
|
len = snprintf((char*)buffer,maxLen,"%s\n%s %s\n",type,topic,val);
|
||||||
|
} else {
|
||||||
|
len = snprintf((char*)buffer,maxLen,"#\n"); // At least one char to send otherwise the transmission ends.
|
||||||
|
}
|
||||||
|
// alarm channel processed --> try next inverter
|
||||||
metricsInverterId++;
|
metricsInverterId++;
|
||||||
metricsStep = metricsStateInverter;
|
metricsStep = metricsStateInverter;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case metricsStateEnd:
|
case metricsStateEnd:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue