MySQL 26.10.0
Source Code Documentation
health_monitor_system.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 2026, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#pragma once
25
29
30namespace hm {
31
32using System_CPU_Stats_Buffer = std::shared_ptr<Stat_Buffer<System_CPU_Stats>>;
34 std::shared_ptr<Stat_Buffer<System_Disk_Stats>>;
36 std::shared_ptr<Stat_Buffer<System_Process_Stats>>;
38 std::shared_ptr<Stat_Buffer<System_Memory_Stats>>;
39
40/**
41 System Collector
42
43 The System Collector collects and publishes CPU, disk I/O, memory, and process
44 statistics. It does not issue resource warnings or take corrective action
45 based on these values.
46*/
48 public:
50
51 protected:
52 // Sample collection
53 void pre_process() override;
54 void process() override;
55 void post_process() override;
56
57 public:
58 // Settings
59 void set_buffer_size() final;
65 bool settings_changed() override;
66 void set_params() final;
67 bool running() const override;
68
69 // CPU stats
70 std::shared_ptr<Stat_Buffer<System_CPU_Stats>> sys_cpu_buffer() {
71 return m_sys_cpu_buffer;
72 }
73 static int get_cpu_stats(std::vector<System_CPU_Stats> &sys_cpu_stats);
74 static int get_cpu_stats(std::vector<System_CPU_Stats> &sys_cpu_stats,
75 const time_t &timestamp);
76 std::shared_ptr<Stat_Buffer<System_CPU_Stats>> get_cpu_stats_buffer();
77
78 // Disk stats
79 std::shared_ptr<Stat_Buffer<System_Disk_Stats>> sys_disk_buffer() {
80 return m_sys_disk_buffer;
81 }
82 static int get_disk_stats(std::vector<System_Disk_Stats> &sys_disk_stats);
83 static int get_disk_stats(std::vector<System_Disk_Stats> &sys_disk_stats,
84 const time_t &timestamp);
85 std::shared_ptr<Stat_Buffer<System_Disk_Stats>> get_disk_stats_buffer();
86
87 // Memory stats
88 std::shared_ptr<Stat_Buffer<System_Memory_Stats>> sys_memory_buffer() {
90 }
91 static int get_memory_stats(System_Memory_Stats &mem_stats);
92 static int get_memory_stats(System_Memory_Stats &mem_stats,
93 const time_t &timestamp);
94 std::shared_ptr<Stat_Buffer<System_Memory_Stats>> get_memory_stats_buffer();
95
96 // Process stats
97 std::shared_ptr<Stat_Buffer<System_Process_Stats>> sys_process_buffer() {
99 }
100 int get_process_stats(std::vector<System_Process_Stats> &sys_process_stats);
101 int get_process_stats(std::vector<System_Process_Stats> &sys_process_stats,
102 const time_t &timestamp);
103 std::shared_ptr<Stat_Buffer<System_Process_Stats>> get_process_stats_buffer();
104
105 // Collector state
106 void set_state(ss::System_State &new_state);
112
119
120 // Logging
121 void log_resource_status() override;
123 std::string format_settings() override;
124 std::string format_status_info() override;
125 std::string tag_collector_state() override;
126
127 // System variables
132 std::atomic<bool> m_settings_changed{false};
133
134 // Sample sizes
140
141 // Error states
142 bool m_sysinfo_error{false};
143 bool m_sysinfo_warning{false};
144 bool m_cpu_stats_error{false};
148
149 private:
150 std::shared_ptr<Stat_Buffer<System_CPU_Stats>> m_sys_cpu_buffer{nullptr};
151 std::shared_ptr<Stat_Buffer<System_Disk_Stats>> m_sys_disk_buffer{nullptr};
152 std::shared_ptr<Stat_Buffer<System_Memory_Stats>> m_sys_memory_buffer{
153 nullptr};
154 std::shared_ptr<Stat_Buffer<System_Process_Stats>> m_sys_process_buffer{
155 nullptr};
156
169};
170
171} // namespace hm
Definition: health_monitor_collector.h:41
System Collector.
Definition: health_monitor_system.h:47
ss::Normal_State m_normal_state
Definition: health_monitor_system.h:116
std::shared_ptr< Stat_Buffer< System_Memory_Stats > > sys_memory_buffer()
Definition: health_monitor_system.h:88
bool m_cpu_stats_error
Definition: health_monitor_system.h:144
std::shared_ptr< Stat_Buffer< System_CPU_Stats > > sys_cpu_buffer()
Definition: health_monitor_system.h:70
void set_state(ss::System_State &new_state)
Set the next state.
Definition: health_monitor_system.cc:553
bool m_disk_stats_history
Definition: health_monitor_system.h:130
std::string format_status_info() override
System Collector status formatted string.
Definition: health_monitor_system.cc:489
void log_warning_error_condition()
Error condition warning.
Definition: health_monitor_system.cc:516
void set_memory_buffer_size()
Definition: health_monitor_system.cc:183
std::shared_ptr< Stat_Buffer< System_Memory_Stats > > m_sys_memory_buffer
Definition: health_monitor_system.h:152
void set_disk_buffer_size()
Definition: health_monitor_system.cc:173
int get_process_stats(std::vector< System_Process_Stats > &sys_process_stats)
Get the mysqld process stats.
Definition: health_monitor_system.cc:414
void set_cpu_buffer_size()
Definition: health_monitor_system.cc:163
void log_resource_status() override
System status, depending on state.
Definition: health_monitor_system.cc:525
PSI_memory_key m_memory_key_memory_stats_history
Definition: health_monitor_system.h:166
PSI_rwlock_key m_rwlock_key
Definition: health_monitor_system.h:157
void pre_process() override
Tasks before starting the collection loop.
Definition: health_monitor_system.cc:79
System_Collector()
Definition: health_monitor_system.cc:42
void set_normal_state()
Definition: health_monitor_system.h:109
bool set_rows_per_sample()
Set the number of rows per sample for each statistic type.
Definition: health_monitor_system.cc:208
PSI_memory_key m_memory_key_process_stats
Definition: health_monitor_system.h:167
void set_params() final
Set collection parameters from the system variables.
Definition: health_monitor_system.cc:247
void set_buffer_size() final
Resize the stat buffers if necessary.
Definition: health_monitor_system.cc:156
PSI_memory_key m_memory_key_cpu_stats
Definition: health_monitor_system.h:161
bool m_disk_stats_error
Definition: health_monitor_system.h:145
bool m_sysinfo_error
Definition: health_monitor_system.h:142
std::string format_settings() override
System Collector settings formatted string.
Definition: health_monitor_system.cc:477
std::shared_ptr< Stat_Buffer< System_Process_Stats > > m_sys_process_buffer
Definition: health_monitor_system.h:154
static int get_cpu_stats(std::vector< System_CPU_Stats > &sys_cpu_stats)
Get the system CPU stats.
Definition: health_monitor_system.cc:271
std::shared_ptr< Stat_Buffer< System_Disk_Stats > > m_sys_disk_buffer
Definition: health_monitor_system.h:151
std::shared_ptr< Stat_Buffer< System_CPU_Stats > > get_cpu_stats_buffer()
Get the system CPU statistics and return them in a local stat buffer.
Definition: health_monitor_system.cc:294
bool m_sysinfo_warning
Definition: health_monitor_system.h:143
ss::Stop_State m_stop_state
Definition: health_monitor_system.h:115
std::atomic< bool > m_settings_changed
Definition: health_monitor_system.h:132
static int get_memory_stats(System_Memory_Stats &mem_stats)
Get the system memory stats.
Definition: health_monitor_system.cc:369
PSI_memory_key m_memory_key_process_stats_history
Definition: health_monitor_system.h:168
std::shared_ptr< Stat_Buffer< System_Memory_Stats > > get_memory_stats_buffer()
Get the system memory statistics and return them in a local stat buffer.
Definition: health_monitor_system.cc:391
bool settings_changed() override
Return true if the collector settings have changed.
Definition: health_monitor_system.cc:231
ss::System_State * m_current_state
Definition: health_monitor_system.h:113
std::string tag_collector_state() override
Collector state tag.
Definition: health_monitor_system.cc:498
bool m_memory_stats_error
Definition: health_monitor_system.h:146
std::shared_ptr< Stat_Buffer< System_CPU_Stats > > m_sys_cpu_buffer
Definition: health_monitor_system.h:150
std::shared_ptr< Stat_Buffer< System_Disk_Stats > > get_disk_stats_buffer()
Get the system disk statistics and return them in a local stat buffer.
Definition: health_monitor_system.cc:344
uint32_t m_disk_rows_per_sample
Definition: health_monitor_system.h:137
ss::Error_State m_error_state
Definition: health_monitor_system.h:118
void set_process_buffer_size()
Definition: health_monitor_system.cc:193
void process() override
Collect the current system stats and write to the stat buffer.
Definition: health_monitor_system.cc:87
bool m_cpu_stats_history
Definition: health_monitor_system.h:129
static int get_disk_stats(std::vector< System_Disk_Stats > &sys_disk_stats)
Get storage device stats.
Definition: health_monitor_system.cc:319
void set_stop_state()
Definition: health_monitor_system.h:108
ss::Warning_State m_warning_state
Definition: health_monitor_system.h:117
PSI_memory_key m_memory_key_cpu_stats_history
Definition: health_monitor_system.h:162
void post_process() override
Final tasks before exiting the thread.
Definition: health_monitor_system.cc:147
PSI_memory_key m_memory_key_memory_stats
Definition: health_monitor_system.h:165
std::shared_ptr< Stat_Buffer< System_Process_Stats > > get_process_stats_buffer()
Get the mysqld process statistics and return them in a local stat buffer.
Definition: health_monitor_system.cc:454
std::shared_ptr< Stat_Buffer< System_Process_Stats > > sys_process_buffer()
Definition: health_monitor_system.h:97
bool running() const override
Return health_monitor.system_running.
Definition: health_monitor_system.cc:262
PSI_memory_key m_memory_key_disk_stats
Definition: health_monitor_system.h:163
void set_start_state()
Definition: health_monitor_system.h:107
PSI_memory_key m_memory_key_disk_stats_history
Definition: health_monitor_system.h:164
uint32_t m_process_rows_per_sample
Definition: health_monitor_system.h:139
void set_warning_state()
Definition: health_monitor_system.h:110
ss::Start_State m_start_state
Definition: health_monitor_system.h:114
bool m_process_stats_error
Definition: health_monitor_system.h:147
uint32_t m_memory_rows_per_sample
Definition: health_monitor_system.h:138
std::shared_ptr< Stat_Buffer< System_Disk_Stats > > sys_disk_buffer()
Definition: health_monitor_system.h:79
PSI_rwlock_info m_rwlock_info
Definition: health_monitor_system.h:158
bool m_process_stats_history
Definition: health_monitor_system.h:128
bool m_rows_per_sample_set
Definition: health_monitor_system.h:135
uint32_t m_cpu_rows_per_sample
Definition: health_monitor_system.h:136
void set_error_state()
Definition: health_monitor_system.h:111
bool m_memory_stats_history
Definition: health_monitor_system.h:131
Error State.
Definition: health_monitor_system_state.h:108
Normal State.
Definition: health_monitor_system_state.h:83
Start State.
Definition: health_monitor_system_state.h:61
Stop State.
Definition: health_monitor_system_state.h:72
Definition: health_monitor_system_state.h:34
Warning State.
Definition: health_monitor_system_state.h:95
#define PSI_DOCUMENT_ME
Definition: component_common.h:29
#define PSI_FLAG_SINGLETON
Singleton flag.
Definition: component_common.h:35
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:49
unsigned int PSI_rwlock_key
Instrumented rwlock key.
Definition: psi_rwlock_bits.h:44
#define PSI_VOLATILITY_PROVISIONING
Definition: psi_bits.h:155
constexpr value_type timestamp
Definition: classic_protocol_constants.h:278
Definition: component_command.h:29
std::shared_ptr< Stat_Buffer< System_CPU_Stats > > System_CPU_Stats_Buffer
Definition: health_monitor_system.h:32
std::shared_ptr< Stat_Buffer< System_Memory_Stats > > System_Memory_Stats_Buffer
Definition: health_monitor_system.h:38
std::shared_ptr< Stat_Buffer< System_Disk_Stats > > System_Disk_Stats_Buffer
Definition: health_monitor_system.h:34
std::shared_ptr< Stat_Buffer< System_Process_Stats > > System_Process_Stats_Buffer
Definition: health_monitor_system.h:36
Rwlock information.
Definition: psi_rwlock_bits.h:162
Definition: health_monitor_system_bits.h:72