Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/include/prometheus/counter.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class PROMETHEUS_CPP_CORE_EXPORT Counter: public MetricBase {
/// \brief Create a counter that starts at 0.
Counter(const bool alert_if_no_family = true);

/// \brief Resets the counter.
void Reset();

/// \brief Increment the counter by a given amount.
///
/// The counter will not change if the given amount is negative.
Expand Down
3 changes: 3 additions & 0 deletions core/include/prometheus/gauge.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class PROMETHEUS_CPP_CORE_EXPORT Gauge: public MetricBase {
/// \brief Create a gauge that starts at the given amount.
Gauge(const double value = 0, const bool alert_if_no_family = true);

/// \brief Reset the gauge.
void Reset(const double value = 0);

/// \brief Increment the gauge by the given amount.
void Increment(const double value = 1);

Expand Down
3 changes: 3 additions & 0 deletions core/include/prometheus/histogram.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class PROMETHEUS_CPP_CORE_EXPORT Histogram: public MetricBase {
/// The bucket boundaries cannot be changed once the histogram is created.
Histogram(const BucketBoundaries& buckets, const bool alert_if_no_family = true);

/// \brief Reset the histogram.
void Reset();

/// \brief Observe the given amount.
///
/// The given amount selects the 'observed' bucket. The observed bucket is
Expand Down
2 changes: 1 addition & 1 deletion core/include/prometheus/metric_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace prometheus {
class PROMETHEUS_CPP_CORE_EXPORT MetricBase {
public:
MetricBase(const bool alert_if_no_family = true);

/// \brief Prints a message to stderr if the metric doesn't have a family
bool HasFamily();

Expand Down
5 changes: 5 additions & 0 deletions core/src/counter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ namespace prometheus {

Counter::Counter(const bool alert_if_no_family) : MetricBase(alert_if_no_family) {};

void Counter::Reset() {
value_ = 0;
last_update_ = std::time(nullptr);
AlertIfNoFamily();
}

void Counter::Increment(const double value) {
if (value < 0.0) return;
Expand Down
6 changes: 6 additions & 0 deletions core/src/gauge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ namespace prometheus {

Gauge::Gauge(const double value, const bool alert_if_no_family) : MetricBase(alert_if_no_family), value_(value) {}

void Gauge::Reset(const double value) {
value_ = value;
last_update_ = std::time(nullptr);
AlertIfNoFamily();
}

void Gauge::Increment(const double value) {
if (value < 0.0) return;
value_ = value_ + value;
Expand Down
9 changes: 9 additions & 0 deletions core/src/histogram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ Histogram::Histogram(const BucketBoundaries& buckets, const bool alert_if_no_fam
std::end(bucket_boundaries_)));
}

void Histogram::Reset() {
for (unsigned int bucket_index = 0; bucket_index < bucket_counts_.size(); ++bucket_index) {
bucket_counts_[bucket_index] = 0;
}
sum_ = 0;
last_update_ = std::time(nullptr);
AlertIfNoFamily();
}

void Histogram::Observe(const double value) {
// TODO: determine bucket list size at which binary search would be faster
const auto bucket_index = static_cast<std::size_t>(std::distance(
Expand Down