error handling and cleanup
This commit is contained in:
@ -1,26 +1,61 @@
|
||||
/**
|
||||
* @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_http_server.h>
|
||||
#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,
|
||||
INTEGER_U8,
|
||||
INTEGER_64,
|
||||
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];
|
||||
eMetricValueType type;
|
||||
float fMetricValue;
|
||||
uint8_t u8MetricValue;
|
||||
int64_t i64MetricValue;
|
||||
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;
|
||||
|
||||
void initMetrics(void);
|
||||
void vSetMetrics(sMetric *paMetrics, uint16_t u16Size);
|
||||
/**
|
||||
* @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);
|
||||
|
||||
Reference in New Issue
Block a user