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

Implementation of the metrics. More...

#include "metrics.h"
#include "esp_log.h"
#include "event_bus.h"
#include "slab_pool.h"
Include dependency graph for metrics.c:

Macros

#define AS_STRING(id, str)   str,
 

Functions

static void metrics_increment_stat_helper (metrics_stat_t stat)
 Increment a metric counter.
 
static void on_error_callback (const event_bus_t *event_ptr, void *ctx)
 Callback on error.
 
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.
 

Variables

static const char * TAG = "METRICS"
 
static uint32_t system_metrics [METRICS_STAT_MAX] = {0}
 

Detailed Description

Implementation of the metrics.

  • Uses 'system event bus' module to receive stats events
  • Can return a coy of stats structure or print them through ESP logging facilities

Macro Definition Documentation

◆ AS_STRING

#define AS_STRING (   id,
  str 
)    str,

Extract stat name from table

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_increment_stat_helper()

static void metrics_increment_stat_helper ( metrics_stat_t  stat)
static

Increment a metric counter.

Parameters
statStat to increment
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:

◆ on_error_callback()

static void on_error_callback ( const event_bus_t event_ptr,
void *  ctx 
)
static

Callback on error.

Increment received event corresponding stat

Parameters
event_ptrPointer to event
ctxPointer to event context
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ system_metrics

uint32_t system_metrics[METRICS_STAT_MAX] = {0}
static

Metrics counters structure

◆ TAG

const char* TAG = "METRICS"
static

Metrics TAG name