userver: userver/utils/statistics/rate.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 bool operator==(Rate rhs) const noexcept { return value == rhs.value; }
28
29 bool operator!=(Rate rhs) const noexcept { return !(*this == rhs); }
30
31 bool operator<(Rate rhs) const noexcept { return value < rhs.value; }
32
33 bool operator>(Rate rhs) const noexcept { return rhs < *this; }
34
35 bool operator<=(Rate rhs) const noexcept { return !(rhs < *this); }
36
37 bool operator>=(Rate rhs) const noexcept { return !(*this < rhs); }
38
39 bool operator==(std::uint64_t rhs) const noexcept { return value == 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
52inline Rate operator+(Rate first, Rate second) noexcept {
53 return Rate{first.value + second.value};
54}
55
56} // namespace utils::statistics
57
58USERVER_NAMESPACE_END