Modbus Vault v1.0
Loading...
Searching...
No Matches
metrics.h File Reference

System-wide metrics/telemetry module. More...

#include "esp_err.h"
#include "stdint.h"
Include dependency graph for metrics.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define METRICS_TABLE(ENTRY)
 Metrics table.
 
#define AS_ENUM(id, str)   id,
 

Enumerations

enum  metrics_stat_t {
  METRICS_STAT_RS485_DRIVER_OVERFLOW_ERRORS , METRICS_STAT_RS485_DRIVER_PARITY_ERRORS , METRICS_STAT_MODBUS_CRC_ERRORS , METRICS_STAT_MODBUS_OVERFLOW_ERRORS ,
  METRICS_STAT_MODBUS_NO_MEM_ERRORS , METRICS_STAT_TELEMETRY_PUBLISH_ERRORS , METRICS_STAT_LOGGER_WRITE_ERRORS , METRICS_STAT_MAX
}
 Metrics stats Enums. More...
 

Functions

esp_err_t metrics_init (void)
 Initialize metrics.
 
esp_err_t metrics_get_snapshot (uint32_t *buf_ptr, size_t buf_length, uint16_t *copied_length)
 Get a snapshot of current system metrics.
 
void metrics_log_all (void)
 Logs metrics stats through ESP logging facilities.
 
void metrics_reset_all (void)
 Resets metrics counters to zero.
 
const char * metrics_stat_to_string (metrics_stat_t stat)
 Gets metric state name.
 

Detailed Description

System-wide metrics/telemetry module.

Author
Abanoub Salah
  • Provides lightweight counters for tracking system behavior
  • Thread-safe and designed for multi-tasking environments

Macro Definition Documentation

◆ AS_ENUM

#define AS_ENUM (   id,
  str 
)    id,

Extract stat ID from table

◆ METRICS_TABLE

#define METRICS_TABLE (   ENTRY)
Value:
ENTRY (METRICS_STAT_RS485_DRIVER_OVERFLOW_ERRORS, "RS485_DRIVER_OVERFLOW_ERRORS") \
ENTRY (METRICS_STAT_RS485_DRIVER_PARITY_ERRORS, "RS485_DRIVER_PARITY_ERRORS") \
ENTRY (METRICS_STAT_MODBUS_CRC_ERRORS, "MODBUS_CRC_ERRORS") \
ENTRY (METRICS_STAT_MODBUS_OVERFLOW_ERRORS, "MODBUS_OVERFLOW_ERRORS") \
ENTRY (METRICS_STAT_MODBUS_NO_MEM_ERRORS, "MODBUS_NO_MEM_ERRORS") \
ENTRY (METRICS_STAT_TELEMETRY_PUBLISH_ERRORS, "TELEMETRY_PUBLISH_ERRORS") \
ENTRY (METRICS_STAT_LOGGER_WRITE_ERRORS, "LOGGER_WRITE_ERRORS")

Metrics table.

Note
  • Entry format as follows
    • ENTRY (stat_enum, stat_name)
  • Where
    • stat_enum: Enum used within code
    • stat_name: Displayed name of the stat

Enumeration Type Documentation

◆ metrics_stat_t

Metrics stats Enums.

Note
To add a stat simply add an entry to METRICS_TABLE above and start using it within your code

Function Documentation

◆ metrics_get_snapshot()

esp_err_t metrics_get_snapshot ( uint32_t *  buf_ptr,
size_t  buf_length,
uint16_t *  copied_length 
)

Get a snapshot of current system metrics.

Get a snapshot of current system metrics by copying stats to user provided buffer it's length has to be equal to metric stat maximum length and same counters used type (e.g. uint32_t)

Parameters
buf_ptrPointer to a buffer
buf_lengthLength of the buffer
copied_lengthPointer to assign copied length by function
Returns
esp_err_t Get snapshot result
Return values
ESP_OKMetrics copy success
ESP_ERR_INVALID_ARGProvided invalid argument(s)
Note
Stats can be accessed using their enums as indexes to access them in copied buffer
Here is the caller graph for this function:

◆ metrics_init()

esp_err_t metrics_init ( void  )

Initialize metrics.

Initialize metrics counters to zero and subscribe to event bus to collect different system stats

Returns
esp_err_t Initialize result
Return values
ESP_OKInitialize success
ESP_ERR_NO_MEMSubscription fails
Here is the call graph for this function:
Here is the caller graph for this function:

◆ metrics_stat_to_string()

const char * metrics_stat_to_string ( metrics_stat_t  stat)

Gets metric state name.

Parameters
statMetric stat
Returns
char* string name of the specified stat

Stat names list

Here is the caller graph for this function: