2022-12-14 22:37:37 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2022-10-27 10:38:52 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2022-11-10 19:28:48 +01:00
|
|
|
#include <ESPAsyncWebServer.h>
|
2022-12-14 22:13:03 +01:00
|
|
|
#include <Hoymiles.h>
|
2024-01-20 02:00:22 +01:00
|
|
|
#include <TaskSchedulerDeclarations.h>
|
2023-02-24 19:10:35 +01:00
|
|
|
#include <map>
|
2022-10-27 10:38:52 +02:00
|
|
|
|
|
|
|
|
class WebApiPrometheusClass {
|
|
|
|
|
public:
|
2024-01-20 02:00:22 +01:00
|
|
|
void init(AsyncWebServer& server, Scheduler& scheduler);
|
2022-10-27 10:38:52 +02:00
|
|
|
|
|
|
|
|
private:
|
2022-11-10 19:51:01 +01:00
|
|
|
void onPrometheusMetricsGet(AsyncWebServerRequest* request);
|
2022-10-27 10:38:52 +02:00
|
|
|
|
2023-12-12 00:21:14 +01:00
|
|
|
void addField(AsyncResponseStream* stream, const String& serial, const uint8_t idx, std::shared_ptr<InverterAbstract> inv, const ChannelType_t type, const ChannelNum_t channel, const FieldId_t fieldId, const char* metricName, const char* channelName = nullptr);
|
2022-10-27 10:38:52 +02:00
|
|
|
|
2023-12-12 00:21:14 +01:00
|
|
|
void addPanelInfo(AsyncResponseStream* stream, const String& serial, const uint8_t idx, std::shared_ptr<InverterAbstract> inv, const ChannelType_t type, const ChannelNum_t channel);
|
2023-03-08 09:11:25 +01:00
|
|
|
|
2023-08-22 13:00:52 +02:00
|
|
|
enum MetricType_t {
|
|
|
|
|
NONE = 0,
|
|
|
|
|
GAUGE,
|
|
|
|
|
COUNTER,
|
2023-02-24 19:10:35 +01:00
|
|
|
};
|
|
|
|
|
const char* _metricTypes[3] = { 0, "gauge", "counter" };
|
|
|
|
|
|
2023-08-22 13:00:52 +02:00
|
|
|
struct publish_type_t {
|
|
|
|
|
FieldId_t field;
|
|
|
|
|
MetricType_t type;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const publish_type_t _publishFields[14] = {
|
|
|
|
|
{ FLD_PAC, MetricType_t::GAUGE },
|
|
|
|
|
{ FLD_UAC, MetricType_t::GAUGE },
|
|
|
|
|
{ FLD_IAC, MetricType_t::GAUGE },
|
|
|
|
|
{ FLD_PDC, MetricType_t::GAUGE },
|
|
|
|
|
{ FLD_UDC, MetricType_t::GAUGE },
|
|
|
|
|
{ FLD_IDC, MetricType_t::GAUGE },
|
|
|
|
|
{ FLD_YD, MetricType_t::COUNTER },
|
|
|
|
|
{ FLD_YT, MetricType_t::COUNTER },
|
|
|
|
|
{ FLD_F, MetricType_t::GAUGE },
|
|
|
|
|
{ FLD_T, MetricType_t::GAUGE },
|
|
|
|
|
{ FLD_PF, MetricType_t::GAUGE },
|
|
|
|
|
{ FLD_Q, MetricType_t::GAUGE },
|
|
|
|
|
{ FLD_EFF, MetricType_t::GAUGE },
|
|
|
|
|
{ FLD_IRR, MetricType_t::GAUGE },
|
2023-02-24 19:10:35 +01:00
|
|
|
};
|
2024-01-20 02:00:22 +01:00
|
|
|
};
|