userver
C++ Async Framework
Loading...
Searching...
No Matches
sensor.hpp
Go to the documentation of this file.
1
#
pragma
once
2
3
/// @file userver/congestion_control/sensor.hpp
4
/// @brief Congestion control sensor interfaces
5
6
#
include
<
chrono
>
7
#
include
<
cstdint
>
8
#
include
<
string
>
9
#
include
<
unordered_map
>
10
11
USERVER_NAMESPACE_BEGIN
12
13
namespace
congestion_control
{
14
15
/// Abstract sensor that fetches counters. These counters will be used
16
/// to forecast saturation levels and limit current load.
17
class
Sensor
{
18
public
:
19
struct
Data
{
20
std::uint64_t current_load{0};
21
std::uint64_t overload_events_count{0};
22
std::uint64_t no_overload_events_count{0};
23
std::chrono::steady_clock::time_point tp;
24
25
double
GetLoadPercent()
const
;
26
};
27
28
virtual
~Sensor() =
default
;
29
30
/// @brief Fetch current counters
31
/// @note Can be called both from coroutine and non-coroutine context
32
virtual
Data
FetchCurrent
() = 0;
33
};
34
35
namespace
v2 {
36
37
class
Sensor
{
38
public
:
39
struct
SingleObjectData
{
40
static
constexpr
auto
kCommonObjectName =
"common"
;
41
42
std::size_t total{0};
43
std::size_t timeouts{0};
44
std::size_t timings_sum_ms{0};
45
46
double
GetRate()
const
{
return
static_cast
<
double
>(timeouts) / (total ? total : 1); }
47
std::string ToLogString()
const
;
48
};
49
50
struct
Data
{
51
std::unordered_map<std::string,
SingleObjectData
> objects;
52
std::size_t current_load{0};
53
};
54
55
virtual
~Sensor() =
default
;
56
57
virtual
Data
GetCurrent() = 0;
58
};
59
60
}
// namespace v2
61
62
}
// namespace congestion_control
63
64
USERVER_NAMESPACE_END
userver
congestion_control
sensor.hpp
Generated on Thu May 21 2026 16:16:03 for userver by
Doxygen
1.13.2