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_fwd.hpp>
7#include <userver/components/loggable_component_base.hpp>
8#include <userver/engine/task/task_processor_fwd.hpp>
9#include <userver/utils/statistics/entry.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace components {
14
15// clang-format off
16
17/// @ingroup userver_components
18///
19/// @brief Component for system resource usage statistics collection.
20///
21/// Periodically queries resource usage info and reports is as a set of metrics.
22///
23/// ## Static options:
24/// Name | Description | Default value
25/// ---- | ----------- | -------------
26/// fs-task-processor | Task processor to use for statistics gathering | -
27/// with-nginx | Whether to collect and report nginx processes statistics | false
28///
29/// Note that `with-nginx` is a relatively expensive option as it requires full
30/// process list scan.
31///
32/// ## Static configuration example:
33///
34/// @snippet components/common_component_list_test.cpp Sample system statistics component config
35
36// clang-format on
37
38class SystemStatisticsCollector final : public LoggableComponentBase {
39 public:
40 /// @ingroup userver_component_names
41 /// @brief The default name of components::SystemStatisticsCollector
42 static constexpr std::string_view kName = "system-statistics-collector";
43
44 SystemStatisticsCollector(const ComponentConfig&, const ComponentContext&);
45 ~SystemStatisticsCollector() override;
46
47 static yaml_config::Schema GetStaticConfigSchema();
48
49 private:
50 void ExtendStatistics(utils::statistics::Writer& writer);
51
52 const bool with_nginx_;
53 engine::TaskProcessor& fs_task_processor_;
54 utils::statistics::Entry statistics_holder_;
55};
56
57template <>
58inline constexpr bool kHasValidate<SystemStatisticsCollector> = true;
59
60} // namespace components
61
62USERVER_NAMESPACE_END