userver: userver/utils/statistics/rate.hpp Source File
Loading...
Searching...
No Matches
rate.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/utils/statistics/rate.hpp
4/// @brief @copybrief utils::statistics::Rate
5
6#include <cstdint>
7
8USERVER_NAMESPACE_BEGIN
9
10namespace utils::statistics {
11
12/// `Rate` metrics (or "counter" metrics) are metrics that only monotonically
13/// increase or are reset to zero on restart. Some monitoring systems give them
14/// special treatment with regard to maintaining proper non-negative derivative.
15struct Rate {
16 using ValueType = std::uint64_t;
17
18 ValueType value{0};
19
20 inline Rate& operator+=(Rate other) noexcept {
21 value += other.value;
22 return *this;
23 }
24
25 explicit operator bool() const noexcept { return value != 0; }
26
27 Rate operator-(Rate rhs) const noexcept { return {value - rhs.value}; }
28
29 bool operator==(Rate rhs) const noexcept { return value == rhs.value; }
30
31 bool operator!=(Rate rhs) const noexcept { return !(*this == rhs); }
32
33 bool operator<(Rate rhs) const noexcept { return value < rhs.value; }
34
35 bool operator>(Rate rhs) const noexcept { return rhs < *this; }
36
37 bool operator<=(Rate rhs) const noexcept { return !(rhs < *this); }
38
39 bool operator>=(Rate rhs) const noexcept { return !(*this < rhs); }
40
41 bool operator==(std::uint64_t rhs) const noexcept { return value == rhs; }
42
43 bool operator!=(std::uint64_t rhs) const noexcept { return value != rhs; }
44
45 bool operator<(std::uint64_t rhs) const noexcept { return value < rhs; }
46
47 bool operator>(std::uint64_t rhs) const noexcept { return value > rhs; }
48
49 bool operator<=(std::uint64_t rhs) const noexcept { return value <= rhs; }
50
51 bool operator>=(std::uint64_t rhs) const noexcept { return value >= rhs; }
52};
53
54inline Rate operator+(Rate first, Rate second) noexcept { return Rate{first.value + second.value}; }
55
56} // namespace utils::statistics
57
58USERVER_NAMESPACE_END