LCOV - code coverage report
Current view: top level - zephyr/net/prometheus - gauge.h Hit Total Coverage
Test: new.info Lines: 6 6 100.0 %
Date: 2024-10-22 03:18:24

          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_GAUGE_H_
       8             : #define ZEPHYR_INCLUDE_PROMETHEUS_GAUGE_H_
       9             : 
      10             : /**
      11             :  * @file
      12             :  *
      13             :  * @brief Prometheus gauge APIs.
      14             :  *
      15             :  * @addtogroup prometheus
      16             :  * @{
      17             :  */
      18             : 
      19             : #include <zephyr/sys/iterable_sections.h>
      20             : #include <zephyr/net/prometheus/metric.h>
      21             : 
      22             : /**
      23             :  * @brief Type used to represent a Prometheus gauge metric.
      24             :  *
      25             :  * * References
      26             :  * * See https://prometheus.io/docs/concepts/metric_types/#gauge
      27             :  */
      28           1 : struct prometheus_gauge {
      29             :         /** Base of the Prometheus gauge metric */
      30           1 :         struct prometheus_metric *base;
      31             :         /** Value of the Prometheus gauge metric */
      32           1 :         double value;
      33             : };
      34             : 
      35             : /**
      36             :  * @brief Prometheus Gauge definition.
      37             :  *
      38             :  * This macro defines a Gauge metric.
      39             :  *
      40             :  * @param _name The channel's name.
      41             :  * @param _detail The metric base.
      42             :  *
      43             :  * Example usage:
      44             :  * @code{.c}
      45             :  *
      46             :  * struct prometheus_metric http_request_gauge = {
      47             :  *      .type = PROMETHEUS_GAUGE,
      48             :  *      .name = "http_request_gauge",
      49             :  *      .description = "HTTP request gauge",
      50             :  *      .num_labels = 1,
      51             :  *      .labels = {
      52             :  *              { .key = "http_request", .value = "request_count",}
      53             :  *      },
      54             :  * };
      55             :  *
      56             :  * PROMETHEUS_GAUGE_DEFINE(test_gauge, &test_gauge_metric);
      57             :  *
      58             :  * @endcode
      59             :  */
      60           1 : #define PROMETHEUS_GAUGE_DEFINE(_name, _detail)                                                    \
      61             :         static STRUCT_SECTION_ITERABLE(prometheus_gauge, _name) = {.base = (void *)(_detail),      \
      62             :                                                                    .value = 0}
      63             : 
      64             : /**
      65             :  * @brief Set the value of a Prometheus gauge metric
      66             :  *
      67             :  * Sets the value of the specified gauge metric to the given value.
      68             :  *
      69             :  * @param gauge Pointer to the gauge metric to set.
      70             :  * @param value Value to set the gauge metric to.
      71             :  *
      72             :  * @return 0 on success, -EINVAL if the value is negative.
      73             :  */
      74           1 : int prometheus_gauge_set(struct prometheus_gauge *gauge, double value);
      75             : 
      76             : /**
      77             :  * @}
      78             :  */
      79             : 
      80             : #endif /* ZEPHYR_INCLUDE_PROMETHEUS_GAUGE_H_ */

Generated by: LCOV version 1.14