LCOV - code coverage report
Current view: top level - zephyr/net/prometheus - counter.h Hit Total Coverage
Test: new.info Lines: 6 6 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_COUNTER_H_
       8             : #define ZEPHYR_INCLUDE_PROMETHEUS_COUNTER_H_
       9             : 
      10             : /**
      11             :  * @file
      12             :  *
      13             :  * @brief Prometheus counter APIs.
      14             :  *
      15             :  * @addtogroup prometheus
      16             :  * @{
      17             :  */
      18             : 
      19             : #include <stdint.h>
      20             : 
      21             : #include <zephyr/sys/iterable_sections.h>
      22             : #include <zephyr/net/prometheus/metric.h>
      23             : 
      24             : /**
      25             :  * @brief Type used to represent a Prometheus counter metric.
      26             :  *
      27             :  * * References
      28             :  * * See https://prometheus.io/docs/concepts/metric_types/#counter
      29             :  */
      30           1 : struct prometheus_counter {
      31             :         /** Base of the Prometheus counter metric */
      32           1 :         struct prometheus_metric *base;
      33             :         /** Value of the Prometheus counter metric */
      34           1 :         uint64_t value;
      35             : };
      36             : 
      37             : /**
      38             :  * @brief Prometheus Counter definition.
      39             :  *
      40             :  * This macro defines a Counter metric.
      41             :  *
      42             :  * @param _name The channel's name.
      43             :  * @param _detail The metric base.
      44             :  *
      45             :  * Example usage:
      46             :  * @code{.c}
      47             :  *
      48             :  * struct prometheus_metric http_request_counter = {
      49             :  *      .type = PROMETHEUS_COUNTER,
      50             :  *      .name = "http_request_counter",
      51             :  *      .description = "HTTP request counter",
      52             :  *      .num_labels = 1,
      53             :  *      .labels = {
      54             :  *              { .key = "http_request", .value = "request_count",}
      55             :  *      },
      56             :  *};
      57             :  *
      58             :  * PROMETHEUS_COUNTER_DEFINE(test_counter, &test_counter_metric);
      59             :  * @endcode
      60             :  */
      61           1 : #define PROMETHEUS_COUNTER_DEFINE(_name, _detail)                                                  \
      62             :         static STRUCT_SECTION_ITERABLE(prometheus_counter, _name) = {.base = (void *)(_detail),    \
      63             :                                                                      .value = 0}
      64             : 
      65             : /**
      66             :  * @brief Increment the value of a Prometheus counter metric
      67             :  * Increments the value of the specified counter metric by one.
      68             :  * @param counter Pointer to the counter metric to increment.
      69             :  * @return 0 on success, negative errno on error.
      70             :  */
      71           1 : int prometheus_counter_inc(struct prometheus_counter *counter);
      72             : 
      73             : /**
      74             :  * @}
      75             :  */
      76             : 
      77             : #endif /* ZEPHYR_INCLUDE_PROMETHEUS_COUNTER_H_ */

Generated by: LCOV version 1.14