LCOV - code coverage report
Current view: top level - zephyr/net/prometheus - collector.h Hit Total Coverage
Test: new.info Lines: 8 8 100.0 %
Date: 2024-10-22 00:13:38

          Line data    Source code
       1           1 : /*
       2             :  * Copyright (c) 2024 Mustafa Abdullah Kus, Sparse Technology
       3             :  *
       4             :  * SPDX-License-Identifier: Apache-2.0
       5             :  */
       6             : 
       7             : #ifndef ZEPHYR_INCLUDE_PROMETHEUS_COLLECTOR_H_
       8             : #define ZEPHYR_INCLUDE_PROMETHEUS_COLLECTOR_H_
       9             : 
      10             : /**
      11             :  * @file
      12             :  *
      13             :  * @brief Prometheus collector APIs.
      14             :  *
      15             :  * @defgroup prometheus Prometheus API
      16             :  * @since 4.0
      17             :  * @version 0.1.0
      18             :  * @ingroup networking
      19             :  * @{
      20             :  */
      21             : 
      22             : #include <zephyr/sys/iterable_sections.h>
      23             : #include <zephyr/net/prometheus/metric.h>
      24             : 
      25             : #include <stddef.h>
      26             : 
      27             : /**
      28             :  * @brief Prometheus collector definition
      29             :  *
      30             :  * This structure defines a Prometheus collector.
      31             :  */
      32           1 : struct prometheus_collector {
      33             :         /** Name of the collector */
      34           1 :         const char *name;
      35             :         /** Array of metrics associated with the collector */
      36           1 :         struct prometheus_metric *metric[CONFIG_PROMETHEUS_MAX_METRICS];
      37             :         /** Number of metrics associated with the collector */
      38           1 :         size_t size;
      39             : };
      40             : 
      41             : /**
      42             :  * @brief Prometheus Collector definition.
      43             :  *
      44             :  * This macro defines a Collector.
      45             :  *
      46             :  * @param _name The collector's name.
      47             :  */
      48           1 : #define PROMETHEUS_COLLECTOR_DEFINE(_name)                                                         \
      49             :         static STRUCT_SECTION_ITERABLE(prometheus_collector, _name) = {                            \
      50             :                 .name = STRINGIFY(_name), .size = 0, .metric = {0}}
      51             : 
      52             : /**
      53             :  * @brief Register a metric with a Prometheus collector
      54             :  *
      55             :  * Registers the specified metric with the given collector.
      56             :  *
      57             :  * @param collector Pointer to the collector to register the metric with.
      58             :  * @param metric Pointer to the metric to register.
      59             :  *
      60             :  * @return 0 if successful, otherwise a negative error code.
      61             :  * @retval -EINVAL Invalid arguments.
      62             :  * @retval -ENOMEM Not enough memory to register the metric.
      63             :  */
      64           1 : int prometheus_collector_register_metric(struct prometheus_collector *collector,
      65             :                                          struct prometheus_metric *metric);
      66             : 
      67             : /**
      68             :  * @brief Get a metric from a Prometheus collector
      69             :  *
      70             :  * Retrieves the metric with the specified name from the given collector.
      71             :  *
      72             :  * @param collector Pointer to the collector to retrieve the metric from.
      73             :  * @param name Name of the metric to retrieve.
      74             :  * @return Pointer to the retrieved metric, or NULL if not found.
      75             :  */
      76           1 : const void *prometheus_collector_get_metric(const struct prometheus_collector *collector,
      77             :                                             const char *name);
      78             : 
      79             : /**
      80             :  * @}
      81             :  */
      82             : 
      83             : #endif /* ZEPHYR_INCLUDE_PROMETHEUS_COLLECTOR_H_ */

Generated by: LCOV version 1.14