Do not send prometheus metric if channel is disabled in configuration

This commit is contained in:
Frank 2023-04-07 09:15:55 +02:00
parent 7857424fe7
commit 0334898e3d
2 changed files with 13 additions and 8 deletions

View file

@ -12,7 +12,7 @@ Prometheus metrics provided at `/metrics`.
| name | Inverter name from setup |
| serial | Serial number of inverter |
| inverter | Inverter name from setup |
| channel | Channel name from setup |
| channel | Channel (Module) name from setup. Label only available if max power level of module is set to non-zero. Be sure to have a cannel name set in configuration. |
## Exported Metrics
| Metric name | Type | Description | Labels |

View file

@ -719,6 +719,8 @@ class Web {
rec = iv->getRecordStruct(RealTimeRunData_Debug);
if (metricsChannelId < rec->length) {
uint8_t channel = rec->assign[metricsChannelId].ch;
// Skip entry if maxPwr is 0 and it's not the inverter channel (channel 0)
if (0 == channel || 0 != iv->config->chMaxPwr[channel-1]) {
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());
if (0 == channel) {
@ -728,6 +730,9 @@ class Web {
}
snprintf(val, sizeof(val), "%.3f", iv->getValue(metricsChannelId, 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.
}
metricsChannelId++;
} else {