net: prometheus: counter: Add function to add a value
Add function to increase the counter value with arbitrary value. Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
parent
057ba5cf45
commit
d94bcd2566
2 changed files with 17 additions and 6 deletions
|
@ -62,13 +62,26 @@ struct prometheus_counter {
|
|||
static STRUCT_SECTION_ITERABLE(prometheus_counter, _name) = {.base = (void *)(_detail), \
|
||||
.value = 0}
|
||||
|
||||
/**
|
||||
* @brief Increment the value of a Prometheus counter metric
|
||||
* Increments the value of the specified counter metric by arbitrary amount.
|
||||
* @param counter Pointer to the counter metric to increment.
|
||||
* @param value Amount to increment the counter by.
|
||||
* @return 0 on success, negative errno on error.
|
||||
*/
|
||||
int prometheus_counter_add(struct prometheus_counter *counter, uint64_t value);
|
||||
|
||||
/**
|
||||
* @brief Increment the value of a Prometheus counter metric
|
||||
* Increments the value of the specified counter metric by one.
|
||||
* @param counter Pointer to the counter metric to increment.
|
||||
* @return 0 on success, negative errno on error.
|
||||
*/
|
||||
int prometheus_counter_inc(struct prometheus_counter *counter);
|
||||
static inline int prometheus_counter_inc(struct prometheus_counter *counter)
|
||||
{
|
||||
return prometheus_counter_add(counter, 1ULL);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
|
|
@ -14,15 +14,13 @@
|
|||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_REGISTER(pm_counter, CONFIG_PROMETHEUS_LOG_LEVEL);
|
||||
|
||||
int prometheus_counter_inc(struct prometheus_counter *counter)
|
||||
int prometheus_counter_add(struct prometheus_counter *counter, uint64_t value)
|
||||
{
|
||||
if (!counter) {
|
||||
if (counter == NULL) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (counter) {
|
||||
counter->value++;
|
||||
}
|
||||
counter->value += value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue