userver: userver/server/congestion_control/sensor.hpp Source File
Loading...
Searching...
No Matches
sensor.hpp
1#pragma once
2
3#include <cstdint>
4
5#include <userver/congestion_control/sensor.hpp>
6#include <userver/engine/task/task_processor_fwd.hpp>
7#include <userver/rcu/rcu.hpp>
8#include <userver/utils/statistics/recentperiod.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace server::congestion_control {
13
14class RequestsSource {
15 public:
16 virtual ~RequestsSource() = default;
17
18 virtual std::uint64_t GetTotalRequests() const = 0;
19};
20
21class Sensor final : public USERVER_NAMESPACE::congestion_control::Sensor {
22 public:
23 explicit Sensor(engine::TaskProcessor& tp);
24
25 Data FetchCurrent() override;
26
27 void RegisterRequestsSource(RequestsSource& source);
28
29 private:
30 engine::TaskProcessor& tp_;
31 rcu::Variable<std::vector<RequestsSource*>> requests_sources_;
32
33 std::chrono::steady_clock::time_point last_fetch_tp_;
34 std::uint64_t last_overloads_{0};
35 std::uint64_t last_no_overloads_{0};
36 std::uint64_t last_requests_{0};
37};
38
39} // namespace server::congestion_control
40
41USERVER_NAMESPACE_END