2020-06-10 03:00:12 +02:00
|
|
|
#pragma once
|
|
|
|
|
2021-09-20 11:47:51 +02:00
|
|
|
#ifdef USE_ARDUINO
|
|
|
|
|
2020-06-10 03:00:12 +02:00
|
|
|
#include "esphome/components/web_server_base/web_server_base.h"
|
2020-07-27 12:07:05 +02:00
|
|
|
#include "esphome/core/controller.h"
|
|
|
|
#include "esphome/core/component.h"
|
2020-06-10 03:00:12 +02:00
|
|
|
|
|
|
|
namespace esphome {
|
2020-07-27 12:07:05 +02:00
|
|
|
namespace prometheus {
|
2020-06-10 03:00:12 +02:00
|
|
|
|
2020-07-27 12:07:05 +02:00
|
|
|
class PrometheusHandler : public AsyncWebHandler, public Component {
|
2020-06-10 03:00:12 +02:00
|
|
|
public:
|
2020-07-27 12:07:05 +02:00
|
|
|
PrometheusHandler(web_server_base::WebServerBase *base) : base_(base) {}
|
|
|
|
|
|
|
|
bool canHandle(AsyncWebServerRequest *request) override {
|
|
|
|
if (request->method() == HTTP_GET) {
|
|
|
|
if (request->url() == "/metrics")
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void handleRequest(AsyncWebServerRequest *req) override;
|
|
|
|
|
|
|
|
void setup() override {
|
|
|
|
this->base_->init();
|
|
|
|
this->base_->add_handler(this);
|
|
|
|
}
|
2020-07-28 12:01:38 +02:00
|
|
|
float get_setup_priority() const override {
|
|
|
|
// After WiFi
|
|
|
|
return setup_priority::WIFI - 1.0f;
|
|
|
|
}
|
2020-06-10 03:00:12 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
#ifdef USE_SENSOR
|
|
|
|
/// Return the type for prometheus
|
|
|
|
void sensor_type_(AsyncResponseStream *stream);
|
|
|
|
/// Return the sensor state as prometheus data point
|
|
|
|
void sensor_row_(AsyncResponseStream *stream, sensor::Sensor *obj);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_BINARY_SENSOR
|
|
|
|
/// Return the type for prometheus
|
|
|
|
void binary_sensor_type_(AsyncResponseStream *stream);
|
|
|
|
/// Return the sensor state as prometheus data point
|
|
|
|
void binary_sensor_row_(AsyncResponseStream *stream, binary_sensor::BinarySensor *obj);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_FAN
|
|
|
|
/// Return the type for prometheus
|
|
|
|
void fan_type_(AsyncResponseStream *stream);
|
|
|
|
/// Return the sensor state as prometheus data point
|
2022-01-23 10:21:54 +01:00
|
|
|
void fan_row_(AsyncResponseStream *stream, fan::Fan *obj);
|
2020-06-10 03:00:12 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_LIGHT
|
|
|
|
/// Return the type for prometheus
|
|
|
|
void light_type_(AsyncResponseStream *stream);
|
|
|
|
/// Return the Light Values state as prometheus data point
|
|
|
|
void light_row_(AsyncResponseStream *stream, light::LightState *obj);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_COVER
|
|
|
|
/// Return the type for prometheus
|
|
|
|
void cover_type_(AsyncResponseStream *stream);
|
|
|
|
/// Return the switch Values state as prometheus data point
|
|
|
|
void cover_row_(AsyncResponseStream *stream, cover::Cover *obj);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_SWITCH
|
|
|
|
/// Return the type for prometheus
|
|
|
|
void switch_type_(AsyncResponseStream *stream);
|
|
|
|
/// Return the switch Values state as prometheus data point
|
|
|
|
void switch_row_(AsyncResponseStream *stream, switch_::Switch *obj);
|
|
|
|
#endif
|
2020-07-27 12:07:05 +02:00
|
|
|
|
2022-02-03 19:24:31 +01:00
|
|
|
#ifdef USE_LOCK
|
|
|
|
/// Return the type for prometheus
|
|
|
|
void lock_type_(AsyncResponseStream *stream);
|
|
|
|
/// Return the lock Values state as prometheus data point
|
|
|
|
void lock_row_(AsyncResponseStream *stream, lock::Lock *obj);
|
|
|
|
#endif
|
|
|
|
|
2020-07-27 12:07:05 +02:00
|
|
|
web_server_base::WebServerBase *base_;
|
2020-06-10 03:00:12 +02:00
|
|
|
};
|
|
|
|
|
2020-07-27 12:07:05 +02:00
|
|
|
} // namespace prometheus
|
2020-06-10 03:00:12 +02:00
|
|
|
} // namespace esphome
|
2021-09-20 11:47:51 +02:00
|
|
|
|
|
|
|
#endif // USE_ARDUINO
|