MySQL 26.10.0
Source Code Documentation
health_monitor_system_vars.h
Go to the documentation of this file.
1/* Copyright (c) 2021, 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
26#include <atomic>
27#include <cstdint>
28#include <string>
29
33#include "component_sysvar.h"
35
36namespace hm {
37
39 public:
40 Sysvar_base() = default;
41 explicit Sysvar_base(void *val) : val_ptr(val) {}
42 const char *name{nullptr};
43 const char *desc{nullptr};
44 int type{0};
45 void *val_ptr{nullptr};
46 bool registered{false};
47 bool dynamic{false};
50};
51
52template <typename T>
53class Sysvar : public Sysvar_base {
54 public:
55 Sysvar() : Sysvar_base(reinterpret_cast<void *>(&val)) {}
56 T val{};
57 T min{};
58 T max{};
59 T def{};
60};
61
67
69 public:
70 System_vars() = default;
71
72 static int initialize_all();
73 static int register_all();
74 static int unregister_all();
75
76 // Accessors (single source of truth; no static data members)
77 static sv_int &status_interval();
78
79 static sv_bool &disk_running();
81 static sv_int &disk_retention();
82 static sv_char &disk_monitored();
83 /**
84 Read and store the global data directory for automatic path selection.
85 This runs during registration. Runtime updates request an asynchronous
86 refresh through the collector settings path.
87 @param[in] thd THD handle or nullptr for the global value
88 */
90
91 /** Request an automatic monitored path refresh after a system variable SET.
92 */
94
95 /** Return the generation of the cached automatic monitored path. */
96 static uint64_t disk_monitored_generation();
97
98 /**
99 Select the effective path monitored by the Disk Collector.
100 @param[in] configured_path Configured disk_monitored value
101 @param[out] effective_path Configured path or stored data directory
102 @param[out] generation Current monitored-path cache generation
103 @return true if a usable effective path is available, false otherwise
104 */
105 static bool select_disk_monitored_path(const std::string &configured_path,
106 std::string &effective_path,
107 uint64_t &generation);
108
115 static sv_int &disk_warn_level_1();
116 static sv_int &disk_warn_level_2();
117 static sv_int &disk_warn_level_3();
119 static sv_int &disk_recovery_level();
125
131
132 static sv_bool &memory_running();
134 static sv_int &memory_retention();
138
139 static sv_bool &memory_reporting();
141
142 static sv_bool &periodic_reporting();
144
145 static sv_bool &system_running();
147 static sv_int &system_retention();
152
153 private:
154 struct Vars {
155 // General
157
158 // Disk Collector
180
181 // Disk Forecaster
187
188 // Memory Collector
195
196 // Memory Reporter
199
200 // Periodic Reporter
203
204 // System Collector
212
213 bool registered{false};
214 };
215
216 static Vars &vars(); // lazy singleton of all variables
217};
218
219} // namespace hm
#define MYSQL_THD
Definition: backup_page_tracker.h:38
Store and synchronize the effective automatic monitored path.
Definition: health_monitor_monitored_path.h:36
Definition: health_monitor_system_vars.h:68
static void refresh_disk_monitored_datadir(MYSQL_THD thd)
Read and store the global data directory for automatic path selection.
Definition: health_monitor_system_vars.cc:63
static sv_char & memory_report_definition()
Definition: health_monitor_system_vars.cc:144
static int unregister_all()
Definition: health_monitor_system_vars.cc:807
static sv_char & disk_monitored()
Definition: health_monitor_system_vars.cc:60
static bool select_disk_monitored_path(const std::string &configured_path, std::string &effective_path, uint64_t &generation)
Select the effective path monitored by the Disk Collector.
Definition: health_monitor_system_vars.cc:93
static sv_bool & system_disk_stats_history()
Definition: health_monitor_system_vars.cc:155
static uint64_t disk_monitored_generation()
Return the generation of the cached automatic monitored path.
Definition: health_monitor_system_vars.cc:88
static Vars & vars()
Definition: health_monitor_system_vars.cc:46
static int register_all()
Definition: health_monitor_system_vars.cc:608
static sv_int & memory_retention()
Definition: health_monitor_system_vars.cc:137
static sv_ulong & disk_low_space_level()
Definition: health_monitor_system_vars.cc:113
static sv_ulong & disk_forecast_run_mode()
Definition: health_monitor_system_vars.cc:131
static sv_ulong & disk_low_space_critical_level()
Definition: health_monitor_system_vars.cc:115
static sv_int & disk_forecast_sample_interval()
Definition: health_monitor_system_vars.cc:129
static sv_bool & disk_forecast_running()
Definition: health_monitor_system_vars.cc:128
static sv_int & disk_recovery_time_2()
Definition: health_monitor_system_vars.cc:122
static sv_int & memory_sample_interval()
Definition: health_monitor_system_vars.cc:136
static sv_int & disk_forecast_report_interval()
Definition: health_monitor_system_vars.cc:130
static sv_ulong & memory_warn_level_2()
Definition: health_monitor_system_vars.cc:139
static sv_int & disk_recovery_level()
Definition: health_monitor_system_vars.cc:120
static sv_int & status_interval()
Definition: health_monitor_system_vars.cc:54
static int initialize_all()
Definition: health_monitor_system_vars.cc:243
static sv_bool & periodic_reporting()
Definition: health_monitor_system_vars.cc:147
static sv_bool & system_process_stats_history()
Definition: health_monitor_system_vars.cc:157
static sv_int & disk_retention()
Definition: health_monitor_system_vars.cc:59
static sv_int & disk_recovery_time_1()
Definition: health_monitor_system_vars.cc:121
static sv_bool & system_running()
Definition: health_monitor_system_vars.cc:151
static sv_bool & disk_running()
Definition: health_monitor_system_vars.cc:57
static sv_ulong & memory_warn_level_3()
Definition: health_monitor_system_vars.cc:140
static sv_bool & system_cpu_stats_history()
Definition: health_monitor_system_vars.cc:154
static sv_int & disk_recovery_max_cycles()
Definition: health_monitor_system_vars.cc:123
static sv_bool & disk_fallback_force()
Definition: health_monitor_system_vars.cc:111
static sv_bool & memory_running()
Definition: health_monitor_system_vars.cc:135
static void request_disk_monitored_datadir_refresh()
Request an automatic monitored path refresh after a system variable SET.
Definition: health_monitor_system_vars.cc:84
static sv_int & disk_low_space_percent()
Definition: health_monitor_system_vars.cc:114
static sv_ulong & disk_recovery_window()
Definition: health_monitor_system_vars.cc:125
static sv_ulong & memory_warn_level_1()
Definition: health_monitor_system_vars.cc:138
static sv_char & disk_forecast_test_filename()
Definition: health_monitor_system_vars.cc:132
static sv_int & system_sample_interval()
Definition: health_monitor_system_vars.cc:152
static sv_int & system_retention()
Definition: health_monitor_system_vars.cc:153
static sv_int & disk_sample_interval()
Definition: health_monitor_system_vars.cc:58
static sv_bool & system_memory_stats_history()
Definition: health_monitor_system_vars.cc:156
static sv_char & periodic_report_definition()
Definition: health_monitor_system_vars.cc:148
static sv_bool & memory_reporting()
Definition: health_monitor_system_vars.cc:143
static sv_int & disk_low_space_duration()
Definition: health_monitor_system_vars.cc:112
static sv_bool & disk_fallback_enable()
Definition: health_monitor_system_vars.cc:110
static sv_int & disk_warn_level_3()
Definition: health_monitor_system_vars.cc:118
static sv_bool & disk_recovery_enable()
Definition: health_monitor_system_vars.cc:119
System_vars()=default
static sv_int & disk_recovery_increment()
Definition: health_monitor_system_vars.cc:124
static sv_int & disk_warn_level_2()
Definition: health_monitor_system_vars.cc:117
static sv_int & disk_warn_level_1()
Definition: health_monitor_system_vars.cc:116
Definition: health_monitor_system_vars.h:38
const char * desc
Definition: health_monitor_system_vars.h:43
Sysvar_base(void *val)
Definition: health_monitor_system_vars.h:41
void * val_ptr
Definition: health_monitor_system_vars.h:45
const char * name
Definition: health_monitor_system_vars.h:42
bool dynamic
Definition: health_monitor_system_vars.h:47
bool registered
Definition: health_monitor_system_vars.h:46
Sysvar_base()=default
int type
Definition: health_monitor_system_vars.h:44
mysql_sys_var_check_func check_func
Definition: health_monitor_system_vars.h:48
mysql_sys_var_update_func update_func
Definition: health_monitor_system_vars.h:49
Definition: health_monitor_system_vars.h:53
T def
Definition: health_monitor_system_vars.h:59
T min
Definition: health_monitor_system_vars.h:57
Sysvar()
Definition: health_monitor_system_vars.h:55
T max
Definition: health_monitor_system_vars.h:58
T val
Definition: health_monitor_system_vars.h:56
Specifies macros to define Components.
int(* mysql_sys_var_check_func)(MYSQL_THD thd, SYS_VAR *var, void *save, struct st_mysql_value *value)
Signature for the check function.
Definition: component_sys_var_service.h:78
void(* mysql_sys_var_update_func)(MYSQL_THD thd, SYS_VAR *var, void *val_ptr, const void *save)
Signature for the update function.
Definition: component_sys_var_service.h:106
#define T
Definition: jit_executor_value.cc:373
Definition: component_command.h:29
Specifies macros to define Service Implementations.
Definition: health_monitor_system_vars.h:154
sv_int system_sample_interval
Definition: health_monitor_system_vars.h:206
sv_ulong disk_forecast_run_mode
Definition: health_monitor_system_vars.h:185
sv_int disk_low_space_percent
Definition: health_monitor_system_vars.h:168
sv_ulong disk_low_space_level
Definition: health_monitor_system_vars.h:167
sv_int status_interval
Definition: health_monitor_system_vars.h:156
sv_int disk_recovery_level
Definition: health_monitor_system_vars.h:174
sv_bool disk_forecast_running
Definition: health_monitor_system_vars.h:182
sv_int disk_low_space_duration
Definition: health_monitor_system_vars.h:166
sv_bool disk_fallback_force
Definition: health_monitor_system_vars.h:165
sv_char memory_report_definition
Definition: health_monitor_system_vars.h:198
sv_char disk_monitored
Definition: health_monitor_system_vars.h:162
sv_bool disk_running
Definition: health_monitor_system_vars.h:159
sv_bool memory_reporting
Definition: health_monitor_system_vars.h:197
sv_int disk_recovery_increment
Definition: health_monitor_system_vars.h:178
sv_int disk_retention
Definition: health_monitor_system_vars.h:161
sv_ulong memory_warn_level_3
Definition: health_monitor_system_vars.h:194
sv_ulong disk_low_space_critical_level
Definition: health_monitor_system_vars.h:169
sv_bool system_disk_stats_history
Definition: health_monitor_system_vars.h:209
sv_bool system_memory_stats_history
Definition: health_monitor_system_vars.h:210
sv_bool memory_running
Definition: health_monitor_system_vars.h:189
sv_bool system_running
Definition: health_monitor_system_vars.h:205
sv_int memory_sample_interval
Definition: health_monitor_system_vars.h:190
sv_int disk_recovery_time_1
Definition: health_monitor_system_vars.h:175
sv_int disk_warn_level_1
Definition: health_monitor_system_vars.h:170
sv_bool system_process_stats_history
Definition: health_monitor_system_vars.h:211
sv_ulong memory_warn_level_1
Definition: health_monitor_system_vars.h:192
sv_ulong memory_warn_level_2
Definition: health_monitor_system_vars.h:193
sv_bool disk_recovery_enable
Definition: health_monitor_system_vars.h:173
Monitored_path_cache disk_monitored_datadir
Definition: health_monitor_system_vars.h:163
sv_bool periodic_reporting
Definition: health_monitor_system_vars.h:201
sv_int disk_forecast_sample_interval
Definition: health_monitor_system_vars.h:183
sv_int disk_recovery_time_2
Definition: health_monitor_system_vars.h:176
sv_char periodic_report_definition
Definition: health_monitor_system_vars.h:202
sv_int system_retention
Definition: health_monitor_system_vars.h:207
bool registered
Definition: health_monitor_system_vars.h:213
sv_bool disk_fallback_enable
Definition: health_monitor_system_vars.h:164
sv_int disk_recovery_max_cycles
Definition: health_monitor_system_vars.h:177
sv_bool system_cpu_stats_history
Definition: health_monitor_system_vars.h:208
sv_int disk_forecast_report_interval
Definition: health_monitor_system_vars.h:184
sv_int memory_retention
Definition: health_monitor_system_vars.h:191
sv_int disk_warn_level_3
Definition: health_monitor_system_vars.h:172
sv_ulong disk_recovery_window
Definition: health_monitor_system_vars.h:179
sv_int disk_sample_interval
Definition: health_monitor_system_vars.h:160
sv_char disk_forecast_test_filename
Definition: health_monitor_system_vars.h:186
sv_int disk_warn_level_2
Definition: health_monitor_system_vars.h:171