MySQL 26.10.0
Source Code Documentation
health_monitor.h
Go to the documentation of this file.
1/* Copyright (c) 2020, 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 <memory>
28#include <mutex>
29#include <string>
30
31#include "component_service.h"
33
34namespace hm {
35
36class Health_Monitor;
37class Disk_Collector;
38class Disk_Forecaster;
39class Memory_Collector;
40class System_Collector;
41class Log;
42class Periodic_Reporter;
43class Status_vars;
44class Supervisor;
45class System_vars;
46class Tables;
47class Triggered_Reporter;
48
49/**
50 Own the objects used by one Health Monitor component instance.
51
52 Component initialization and deinitialization control their lifetime.
53 Accessors return borrowed pointers, which can be null during initialization
54 and teardown. Callers must not retain them beyond the component lifetime.
55 Accessors do not synchronize access with component deinitialization.
56*/
58 public:
61
62 [[nodiscard]] static Health_Monitor *instance() noexcept {
63 return m_instance;
64 }
65 [[nodiscard]] static Disk_Collector *disk_collector() noexcept {
66 return m_instance != nullptr ? m_instance->m_disk_collector.get() : nullptr;
67 }
68 [[nodiscard]] static Disk_Forecaster *disk_forecaster() noexcept {
69 return m_instance != nullptr ? m_instance->m_disk_forecaster.get()
70 : nullptr;
71 }
72 [[nodiscard]] static Memory_Collector *memory_collector() noexcept {
73 return m_instance != nullptr ? m_instance->m_memory_collector.get()
74 : nullptr;
75 }
76 [[nodiscard]] static System_Collector *system_collector() noexcept {
77 return m_instance != nullptr ? m_instance->m_system_collector.get()
78 : nullptr;
79 }
80 [[nodiscard]] static Log *log() noexcept {
81 return m_instance != nullptr ? m_instance->m_log.get() : nullptr;
82 }
84 return m_instance != nullptr ? m_instance->m_periodic_reporter.get()
85 : nullptr;
86 }
87 [[nodiscard]] static Status_vars *status_vars() noexcept {
88 return m_instance != nullptr ? m_instance->m_status_vars.get() : nullptr;
89 }
90 [[nodiscard]] static Supervisor *supervisor() noexcept {
91 return m_instance != nullptr ? m_instance->m_supervisor.get() : nullptr;
92 }
93 [[nodiscard]] static Tables *tables() noexcept {
94 return m_instance != nullptr ? m_instance->m_tables.get() : nullptr;
95 }
97 return m_instance != nullptr ? m_instance->m_memory_reporter.get()
98 : nullptr;
99 }
100
101 [[nodiscard]] const char *name() const { return m_name.c_str(); }
102 [[nodiscard]] const char *sysvar_prefix() const {
103 return m_sysvar_prefix.c_str();
104 }
105
106 static int system_vars_update();
107
109 [[nodiscard]] bool initialized() const {
110 return m_hm_initialized.load(std::memory_order_acquire);
111 }
112 static bool available() noexcept;
113
114 private:
118 Health_Monitor &operator=(const Health_Monitor &) = delete;
120 Health_Monitor &operator=(Health_Monitor &&) = delete;
121
124
125 int collectors_init();
126 int collectors_deinit();
127 int collectors_start();
128 int collectors_stop();
129
130 int log_init();
131 int log_deinit();
132
133 int reporters_init();
134 int reporters_deinit();
135
136 int status_vars_init();
137 int status_vars_deinit();
140
141 int supervisor_init();
142 int supervisor_deinit();
143
144 int system_vars_init();
145 // No need for system_vars_deinit() since System_vars has no state
148
149 int tables_init();
150 int tables_deinit();
151 int tables_register();
152 int tables_unregister();
153
154 int metrics_register();
155 int metrics_unregister();
156
157 void server_utils_init();
158 void server_utils_deinit();
159
162
163 // The component entry points create and destroy this instance explicitly.
164 // A raw pointer avoids a destructor running after component services unload.
166
177
178 const std::string m_name{"Health Monitor"};
179 const std::string m_sysvar_prefix{"health_monitor"};
180 static std::atomic<bool> m_hm_initialized;
181 static std::atomic<bool> m_server_shutting_down;
189};
190
191} // namespace hm
Definition: logger.h:49
Disk Collector.
Definition: health_monitor_disk.h:245
Definition: health_monitor_disk_forecaster.h:40
Own the objects used by one Health Monitor component instance.
Definition: health_monitor.h:57
int log_init()
Initialize the log manager.
Definition: health_monitor.cc:276
int supervisor_init()
Initialize the task supervisor.
Definition: health_monitor.cc:387
std::unique_ptr< Tables > m_tables
Definition: health_monitor.h:175
static Periodic_Reporter * periodic_reporter() noexcept
Definition: health_monitor.h:83
const char * sysvar_prefix() const
Definition: health_monitor.h:102
static Health_Monitor * m_instance
Definition: health_monitor.h:165
int option_usage_tracker_deinit()
Deregister option usage tracker.
Definition: health_monitor.cc:605
int status_vars_unregister()
Deregister all status variables.
Definition: health_monitor.cc:376
const std::string m_name
Definition: health_monitor.h:178
bool m_collectors_started
Definition: health_monitor.h:185
int system_vars_unregister()
Deregister all system variables.
Definition: health_monitor.cc:429
int log_deinit()
Deinitialize the log manager.
Definition: health_monitor.cc:289
static Supervisor * supervisor() noexcept
Definition: health_monitor.h:90
bool m_tables_initialized
Definition: health_monitor.h:186
bool m_tables_registered
Definition: health_monitor.h:187
void server_utils_deinit()
Deinitialize the server utility functions.
Definition: health_monitor.cc:578
bool initialized() const
Definition: health_monitor.h:109
const char * name() const
Definition: health_monitor.h:101
static Status_vars * status_vars() noexcept
Definition: health_monitor.h:87
bool m_status_vars_registered
Definition: health_monitor.h:182
void set_server_shutting_down(bool shutdown)
Notify all Collectors that the server is shutting down and to stop work immediately.
Definition: health_monitor.cc:726
bool m_collectors_initialized
Definition: health_monitor.h:184
std::unique_ptr< Disk_Forecaster > m_disk_forecaster
Definition: health_monitor.h:168
std::unique_ptr< Triggered_Reporter > m_memory_reporter
Definition: health_monitor.h:176
int tables_init()
Initialize the table manager.
Definition: health_monitor.cc:496
int tables_unregister()
Deregister all Health Monitor tables.
Definition: health_monitor.cc:533
int status_vars_init()
Initialize the status variable manager and initialize (but do not register) all status variables.
Definition: health_monitor.cc:338
int collectors_init()
Initialize the Health Monitor collectors.
Definition: health_monitor.cc:104
std::unique_ptr< Log > m_log
Definition: health_monitor.h:171
std::unique_ptr< Disk_Collector > m_disk_collector
Definition: health_monitor.h:167
void server_utils_init()
Initialize the server utility functions.
Definition: health_monitor.cc:565
static Triggered_Reporter * memory_reporter() noexcept
Definition: health_monitor.h:96
bool m_system_vars_registered
Definition: health_monitor.h:183
static mysql_service_status_t component_init()
Create the component owner before publishing any of its objects to callbacks.
Definition: health_monitor.cc:74
std::unique_ptr< Memory_Collector > m_memory_collector
Definition: health_monitor.h:169
int system_vars_init()
Initialize but do not register all system variables.
Definition: health_monitor.cc:410
int tables_deinit()
Deinitialize the table manager after all tables have been deregistered.
Definition: health_monitor.cc:509
static Tables * tables() noexcept
Definition: health_monitor.h:93
int collectors_start()
Start the Health Monitor collectors.
Definition: health_monitor.cc:159
int tables_register()
Register all Health Monitor tables in the Performance Schema.
Definition: health_monitor.cc:519
std::unique_ptr< System_Collector > m_system_collector
Definition: health_monitor.h:170
mysql_service_status_t initialize()
Health monitor initialization:
Definition: health_monitor.cc:625
int collectors_deinit()
Deinitialize the Health Monitor collectors.
Definition: health_monitor.cc:140
int reporters_deinit()
Deinitialize the reporters.
Definition: health_monitor.cc:324
static int system_vars_update()
Notify collectors of pending system variable updates.
Definition: health_monitor.cc:446
int system_vars_register()
Register all system variables.
Definition: health_monitor.cc:415
static Health_Monitor * instance() noexcept
Definition: health_monitor.h:62
int collectors_stop()
Shut down the collectors.
Definition: health_monitor.cc:247
static System_Collector * system_collector() noexcept
Definition: health_monitor.h:76
std::unique_ptr< Status_vars > m_status_vars
Definition: health_monitor.h:173
static std::atomic< bool > m_server_shutting_down
Definition: health_monitor.h:181
int status_vars_deinit()
Deinitialize the status variable manager after all status variables have been deregistered.
Definition: health_monitor.cc:352
const std::string m_sysvar_prefix
Definition: health_monitor.h:179
static Disk_Collector * disk_collector() noexcept
Definition: health_monitor.h:65
static std::atomic< bool > m_hm_initialized
Definition: health_monitor.h:180
int metrics_unregister()
Deregister metric sources exposed by the component.
Definition: health_monitor.cc:556
static Log * log() noexcept
Definition: health_monitor.h:80
mysql_service_status_t deinitialize()
Health monitor deinitialization.
Definition: health_monitor.cc:747
int status_vars_register()
Register all status variables.
Definition: health_monitor.cc:362
int option_usage_tracker_init()
Register option usage tracker.
Definition: health_monitor.cc:591
int reporters_init()
Initialize the report manager.
Definition: health_monitor.cc:299
static Disk_Forecaster * disk_forecaster() noexcept
Definition: health_monitor.h:68
std::unique_ptr< Supervisor > m_supervisor
Definition: health_monitor.h:174
std::unique_ptr< Periodic_Reporter > m_periodic_reporter
Definition: health_monitor.h:172
bool m_metrics_registered
Definition: health_monitor.h:188
static Memory_Collector * memory_collector() noexcept
Definition: health_monitor.h:72
int metrics_register()
Register metric sources exposed by the component.
Definition: health_monitor.cc:544
int supervisor_deinit()
Deinitialize the task supervisor.
Definition: health_monitor.cc:400
static mysql_service_status_t component_deinit()
Stop workers and unregister callbacks before destroying the component owner.
Definition: health_monitor.cc:92
static bool available() noexcept
The Health Monitor is available if it is initialized and the server is not shutting down.
Definition: health_monitor.cc:739
Definition: health_monitor_log.h:34
Memory Collector.
Definition: health_monitor_memory.h:110
The Periodic_Reporter has a framework for printing reports to some destination.
Definition: health_monitor_periodic_reporter.h:44
Definition: health_monitor_status_vars.h:48
Definition: health_monitor_supervisor.h:30
System Collector.
Definition: health_monitor_system.h:47
Table manager for all Health Monitor tables in the Performance Schema.
Definition: health_monitor_tables.h:35
The Triggered_Reporter overrides run_process to react only to signals.
Definition: health_monitor_triggered_reporter.h:36
Definition: component_command.h:29
MYSQL_STRINGS_EXPORT void shutdown()
Shutdown character set/collation library.
Definition: collations.cc:67
noexcept
The return type for any call_and_catch(f, args...) call where f(args...) returns Type.
Definition: call_and_catch.h:76
Define std::hash<Gtid>.
Definition: gtid.h:355
std::conditional_t< !std::is_array< T >::value, std::unique_ptr< T, detail::Deleter< T > >, std::conditional_t< detail::is_unbounded_array_v< T >, std::unique_ptr< T, detail::Array_deleter< std::remove_extent_t< T > > >, void > > unique_ptr
The following is a common type that is returned by all the ut::make_unique (non-aligned) specializati...
Definition: ut0new.h:2284
int mysql_service_status_t
Specific type for the service status return values.
Definition: service.h:34