ESPHome  2022.6.2
prometheus_handler.h
Go to the documentation of this file.
1 #pragma once
2 
3 #ifdef USE_ARDUINO
4 
8 
9 namespace esphome {
10 namespace prometheus {
11 
12 class PrometheusHandler : public AsyncWebHandler, public Component {
13  public:
15 
21  void set_include_internal(bool include_internal) { include_internal_ = include_internal; }
22 
23  bool canHandle(AsyncWebServerRequest *request) override {
24  if (request->method() == HTTP_GET) {
25  if (request->url() == "/metrics")
26  return true;
27  }
28 
29  return false;
30  }
31 
32  void handleRequest(AsyncWebServerRequest *req) override;
33 
34  void setup() override {
35  this->base_->init();
36  this->base_->add_handler(this);
37  }
38  float get_setup_priority() const override {
39  // After WiFi
40  return setup_priority::WIFI - 1.0f;
41  }
42 
43  protected:
44 #ifdef USE_SENSOR
45  void sensor_type_(AsyncResponseStream *stream);
48  void sensor_row_(AsyncResponseStream *stream, sensor::Sensor *obj);
49 #endif
50 
51 #ifdef USE_BINARY_SENSOR
52  void binary_sensor_type_(AsyncResponseStream *stream);
55  void binary_sensor_row_(AsyncResponseStream *stream, binary_sensor::BinarySensor *obj);
56 #endif
57 
58 #ifdef USE_FAN
59  void fan_type_(AsyncResponseStream *stream);
62  void fan_row_(AsyncResponseStream *stream, fan::Fan *obj);
63 #endif
64 
65 #ifdef USE_LIGHT
66  void light_type_(AsyncResponseStream *stream);
69  void light_row_(AsyncResponseStream *stream, light::LightState *obj);
70 #endif
71 
72 #ifdef USE_COVER
73  void cover_type_(AsyncResponseStream *stream);
76  void cover_row_(AsyncResponseStream *stream, cover::Cover *obj);
77 #endif
78 
79 #ifdef USE_SWITCH
80  void switch_type_(AsyncResponseStream *stream);
83  void switch_row_(AsyncResponseStream *stream, switch_::Switch *obj);
84 #endif
85 
86 #ifdef USE_LOCK
87  void lock_type_(AsyncResponseStream *stream);
90  void lock_row_(AsyncResponseStream *stream, lock::Lock *obj);
91 #endif
92 
94  bool include_internal_{false};
95 };
96 
97 } // namespace prometheus
98 } // namespace esphome
99 
100 #endif // USE_ARDUINO
Base class for all switches.
Definition: switch.h:33
void handleRequest(AsyncWebServerRequest *req) override
This class represents the communication layer between the front-end MQTT layer and the hardware outpu...
Definition: light_state.h:32
void switch_row_(AsyncResponseStream *stream, switch_::Switch *obj)
Return the switch Values state as prometheus data point.
Base class for all cover devices.
Definition: cover.h:111
void switch_type_(AsyncResponseStream *stream)
Return the type for prometheus.
bool canHandle(AsyncWebServerRequest *request) override
void add_handler(AsyncWebHandler *handler)
void light_row_(AsyncResponseStream *stream, light::LightState *obj)
Return the Light Values state as prometheus data point.
void binary_sensor_type_(AsyncResponseStream *stream)
Return the type for prometheus.
void sensor_row_(AsyncResponseStream *stream, sensor::Sensor *obj)
Return the sensor state as prometheus data point.
void set_include_internal(bool include_internal)
Determine whether internal components should be exported as metrics.
void light_type_(AsyncResponseStream *stream)
Return the type for prometheus.
web_server_base::WebServerBase * base_
void binary_sensor_row_(AsyncResponseStream *stream, binary_sensor::BinarySensor *obj)
Return the sensor state as prometheus data point.
PrometheusHandler(web_server_base::WebServerBase *base)
void lock_row_(AsyncResponseStream *stream, lock::Lock *obj)
Return the lock Values state as prometheus data point.
void lock_type_(AsyncResponseStream *stream)
Return the type for prometheus.
void fan_type_(AsyncResponseStream *stream)
Return the type for prometheus.
void sensor_type_(AsyncResponseStream *stream)
Return the type for prometheus.
void cover_type_(AsyncResponseStream *stream)
Return the type for prometheus.
Definition: a4988.cpp:4
Base class for all binary_sensor-type classes.
Definition: binary_sensor.h:26
Base-class for all sensors.
Definition: sensor.h:47
void cover_row_(AsyncResponseStream *stream, cover::Cover *obj)
Return the switch Values state as prometheus data point.
Base class for all locks.
Definition: lock.h:103
void fan_row_(AsyncResponseStream *stream, fan::Fan *obj)
Return the sensor state as prometheus data point.