From 638f52a8da3336106e39a4e9f821c16c08e312ee Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Sat, 13 Jan 2024 11:33:58 +0100 Subject: [PATCH] Feature: Add current limit to prometheus output Fixes #1617 --- src/WebApi_prometheus.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/WebApi_prometheus.cpp b/src/WebApi_prometheus.cpp index 3596376ea..2cbc6f5d1 100644 --- a/src/WebApi_prometheus.cpp +++ b/src/WebApi_prometheus.cpp @@ -81,6 +81,22 @@ void WebApiPrometheusClass::onPrometheusMetricsGet(AsyncWebServerRequest* reques stream->printf("opendtu_last_update{serial=\"%s\",unit=\"%d\",name=\"%s\"} %d\n", serial.c_str(), i, name, inv->Statistics()->getLastUpdate() / 1000); + if (i == 0) { + stream->print("# HELP opendtu_inverter_limit_relative current relative limit of the inverter\n"); + stream->print("# TYPE opendtu_inverter_limit_relative gauge\n"); + } + stream->printf("opendtu_inverter_limit_relative{serial=\"%s\",unit=\"%d\",name=\"%s\"} %f\n", + serial.c_str(), i, name, inv->SystemConfigPara()->getLimitPercent() / 100.0); + + if (inv->DevInfo()->getMaxPower() > 0) { + if (i == 0) { + stream->print("# HELP opendtu_inverter_limit_absolute current relative limit of the inverter\n"); + stream->print("# TYPE opendtu_inverter_limit_absolute gauge\n"); + } + stream->printf("opendtu_inverter_limit_absolute{serial=\"%s\",unit=\"%d\",name=\"%s\"} %f\n", + serial.c_str(), i, name, inv->SystemConfigPara()->getLimitPercent() * inv->DevInfo()->getMaxPower() / 100.0); + } + // Loop all channels if Statistics have been updated at least once since DTU boot if (inv->Statistics()->getLastUpdate() > 0) { for (auto& t : inv->Statistics()->getChannelTypes()) {