userver: userver/utils/statistics/system_statistics_collector.hpp Source File
Loading...
Searching...
No Matches
system_statistics_collector.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/utils/statistics/system_statistics_collector.hpp
4/// @brief @copybrief components::SystemStatisticsCollector
5
6#include <userver/components/component_base.hpp>
7#include <userver/components/component_fwd.hpp>
8#include <userver/concurrent/variable.hpp>
9#include <userver/engine/task/task_processor_fwd.hpp>
10#include <userver/utils/periodic_task.hpp>
11#include <userver/utils/statistics/entry.hpp>
12#include <utils/statistics/system_statistics.hpp>
13
14USERVER_NAMESPACE_BEGIN
15
16namespace components {
17
18/// @ingroup userver_components
19///
20/// @brief Component for system resource usage statistics collection.
21///
22/// Periodically queries resource usage info and reports is as a set of metrics.
23///
24/// ## Static options of components::SystemStatisticsCollector :
25/// @include{doc} scripts/docs/en/components_schema/core/src/utils/statistics/system_statistics_collector.md
26///
27/// Options inherited from @ref components::ComponentBase :
28/// @include{doc} scripts/docs/en/components_schema/core/src/components/impl/component_base.md
29///
30/// ## Static configuration example:
31///
32/// @snippet components/common_component_list_test.cpp Sample system statistics component config
33class SystemStatisticsCollector final : public ComponentBase {
34public:
35 /// @ingroup userver_component_names
36 /// @brief The default name of @ref components::SystemStatisticsCollector
37 static constexpr std::string_view kName = "system-statistics-collector";
38
39 SystemStatisticsCollector(const ComponentConfig&, const ComponentContext&);
40 ~SystemStatisticsCollector() override;
41
42 static yaml_config::Schema GetStaticConfigSchema();
43
44private:
45 void ExtendStatistics(utils::statistics::Writer& writer);
46
47 void ProcessTimer();
48
49 struct Data {
50 utils::statistics::impl::SystemStats last_stats{};
51 utils::statistics::impl::SystemStats last_nginx_stats{};
52 };
53
54 const bool with_nginx_;
55 engine::TaskProcessor& fs_task_processor_;
56 utils::statistics::Entry statistics_holder_;
57 concurrent::Variable<Data> data_;
58 utils::PeriodicTask periodic_;
59};
60
61template <>
62inline constexpr bool kHasValidate<SystemStatisticsCollector> = true;
63
64} // namespace components
65
66USERVER_NAMESPACE_END