Files
smart-oil-heating-control-s…/main/metrics.h
2026-01-10 13:32:49 +01:00

62 lines
1.6 KiB
C

/**
* @file metrics.h
* @brief Prometheus metrics HTTP endpoint.
*
* This module provides a HTTP server on port 9100 that exposes
* system metrics in Prometheus format at /metrics endpoint.
*/
#pragma once
#include "esp_err.h"
#include "esp_http_server.h"
#include <stdint.h>
/** @brief Maximum size of HTTP response buffer. */
#define HTML_RESPONSE_SIZE 4096U
/** @brief Maximum length of metric name. */
#define METRIC_NAME_MAX_SIZE 64U
/** @brief Maximum number of metrics. */
#define METRIC_MAX_COUNT 38U
/**
* @brief Metric value type enumeration.
*/
typedef enum _MetricValueType
{
FLOAT, /**< Floating point value. */
INTEGER_U8, /**< 8-bit unsigned integer. */
INTEGER_64, /**< 64-bit signed integer. */
} eMetricValueType;
/**
* @brief Metric data structure.
*/
typedef struct _metric
{
char caMetricName[METRIC_NAME_MAX_SIZE]; /**< Metric name. */
eMetricValueType type; /**< Value type. */
float fMetricValue; /**< Float value (if type is FLOAT). */
uint8_t u8MetricValue; /**< U8 value (if type is INTEGER_U8). */
int64_t i64MetricValue; /**< I64 value (if type is INTEGER_64). */
} sMetric;
/**
* @brief Initialize the metrics module.
*
* Starts the HTTP server and creates the metrics collection task.
*
* @return ESP_OK on success, ESP_FAIL on error.
*/
esp_err_t initMetrics(void);
/**
* @brief Update the metrics buffer.
* @param paMetrics Array of metrics to publish.
* @param u16Size Number of metrics in array.
*/
void vSetMetrics(sMetric *paMetrics, uint16_t u16Size);