espressif / esp-insights

ESP Insights: A remote diagnostics/observability framework for connected devices
Apache License 2.0
101 stars 27 forks source link

Custom metrics demo #29

Closed ftc300 closed 1 year ago

ftc300 commented 1 year ago

I would like to inquire about monitoring the Bluetooth connection status and how to create a custom Metric for this purpose. Could you please provide me with a demo or example on how to achieve this?

vikramdattu commented 1 year ago

@ftc300 I hope you figured this out. We will add an example that will showcase a use case with the usage of custom metrics real soon.

dolphin22 commented 1 year ago

@vikramdattu please kindly spend time showing us how to add custom metrics and variables as well. Thank you in advanced!

vikramdattu commented 1 year ago

Hi @dolphin22 adding a custom metric/veriable has two parts:

  1. Register a metrics/veriable // one time at the start after initialising insights
  2. Send the data // this can be multiple times as per requirement
#include <esp_diagnostics_metric.h>`
#define TAG "heap"
#define KEY "free"
#define LABEL "amount of free heap"
#define PATH "Heap.Free"

Register a metric: esp_diag_metrics_register(TAG, KEY, LABEL, PATH ESP_DIAG_DATA_TYPE_UINT); // API ref

Send the data: (this can be done multiple times)

uint32_t free_heap = <code to get free heap>
esp_diag_metrics_add_uint(KEY,  free heap); 

API ref

I have shown the example to add metrics, you can extend this similarly for variables. Hope this helps!

dolphin22 commented 1 year ago

Hi @dolphin22 adding a custom metric/veriable has two parts:

  1. Register a metrics/veriable // one time at the start after initialising insights
  2. Send the data // this can be multiple times as per requirement
#include <esp_diagnostics_metric.h>`
#define TAG "heap"
#define KEY "free"
#define LABEL "amount of free heap"
#define PATH "Heap.Free"

Register a metric: esp_diag_metrics_register(TAG, KEY, LABEL, PATH ESP_DIAG_DATA_TYPE_UINT); // API ref

Send the data: (this can be done multiple times)

uint32_t free_heap = <code to get free heap>
esp_diag_metrics_add_uint(KEY,  free heap); 

API ref

I have shown the example to add metrics, you can extend this similarly for variables. Hope this helps!

It works, thanks!