Prometheus API: Set correct metrics type
This commit is contained in:
parent
d5af4c8032
commit
c67b3e3cbd
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <Hoymiles.h>
|
#include <Hoymiles.h>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
class WebApiPrometheusClass {
|
class WebApiPrometheusClass {
|
||||||
public:
|
public:
|
||||||
@ -15,4 +16,28 @@ 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 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);
|
||||||
|
|
||||||
AsyncWebServer* _server;
|
AsyncWebServer* _server;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
METRIC_TYPE_NONE = 0,
|
||||||
|
METRIC_TYPE_GAUGE,
|
||||||
|
METRIC_TYPE_COUNTER,
|
||||||
|
};
|
||||||
|
const char* _metricTypes[3] = { 0, "gauge", "counter" };
|
||||||
|
|
||||||
|
std::map<FieldId_t, uint8_t> _fieldMetricAssignment {
|
||||||
|
{ FLD_UDC, METRIC_TYPE_GAUGE },
|
||||||
|
{ FLD_IDC, METRIC_TYPE_GAUGE },
|
||||||
|
{ FLD_PDC, METRIC_TYPE_GAUGE },
|
||||||
|
{ FLD_YD, METRIC_TYPE_COUNTER },
|
||||||
|
{ FLD_YT, METRIC_TYPE_COUNTER },
|
||||||
|
{ FLD_UAC, METRIC_TYPE_GAUGE },
|
||||||
|
{ FLD_IAC, METRIC_TYPE_GAUGE },
|
||||||
|
{ FLD_PAC, METRIC_TYPE_GAUGE },
|
||||||
|
{ FLD_F, METRIC_TYPE_GAUGE },
|
||||||
|
{ FLD_T, METRIC_TYPE_GAUGE },
|
||||||
|
{ FLD_PF, METRIC_TYPE_GAUGE },
|
||||||
|
{ FLD_EFF, METRIC_TYPE_GAUGE },
|
||||||
|
{ FLD_IRR, METRIC_TYPE_GAUGE },
|
||||||
|
{ FLD_PRA, METRIC_TYPE_GAUGE }
|
||||||
|
};
|
||||||
};
|
};
|
||||||
@ -105,7 +105,7 @@ void WebApiPrometheusClass::addField(AsyncResponseStream* stream, String& serial
|
|||||||
const char* chanName = (channelName == NULL) ? inv->Statistics()->getChannelFieldName(type, channel, fieldId) : channelName;
|
const char* chanName = (channelName == NULL) ? inv->Statistics()->getChannelFieldName(type, channel, fieldId) : channelName;
|
||||||
if (idx == 0 && type == TYPE_AC && channel == 0) {
|
if (idx == 0 && type == TYPE_AC && channel == 0) {
|
||||||
stream->printf("# HELP opendtu_%s in %s\n", chanName, inv->Statistics()->getChannelFieldUnit(type, channel, fieldId));
|
stream->printf("# HELP opendtu_%s in %s\n", chanName, inv->Statistics()->getChannelFieldUnit(type, channel, fieldId));
|
||||||
stream->printf("# TYPE opendtu_%s gauge\n", chanName);
|
stream->printf("# TYPE opendtu_%s %s\n", chanName, _metricTypes[_fieldMetricAssignment[fieldId]]);
|
||||||
}
|
}
|
||||||
stream->printf("opendtu_%s{serial=\"%s\",unit=\"%d\",name=\"%s\",type=\"%s\",channel=\"%d\"} %f\n",
|
stream->printf("opendtu_%s{serial=\"%s\",unit=\"%d\",name=\"%s\",type=\"%s\",channel=\"%d\"} %f\n",
|
||||||
chanName,
|
chanName,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user