Add Webserver Prometheus support for sensor, binary sensor, fan, light, cover and switch (#1032)

This commit is contained in:
Marvin Gaube
2020-06-10 03:00:12 +02:00
committed by GitHub
parent cd7af19e7c
commit f63fd9696f
8 changed files with 431 additions and 1 deletions
@@ -0,0 +1,61 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/core/controller.h"
#include "esphome/components/web_server_base/web_server_base.h"
namespace esphome {
namespace web_server {
class WebServerPrometheus {
public:
WebServerPrometheus(){};
/// Handle an prometheus metrics request under '/metrics'.
void handle_request(AsyncWebServerRequest *request);
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
void fan_row_(AsyncResponseStream *stream, fan::FanState *obj);
#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
};
} // namespace web_server
} // namespace esphome