MySQL 26.10.0
Source Code Documentation
hm::Memory_Collector Class Reference

Memory Collector. More...

#include <health_monitor_memory.h>

Inheritance diagram for hm::Memory_Collector:
[legend]

Public Member Functions

 Memory_Collector ()
 
void set_buffer_size () final
 Resize the stat buffer if necessary. More...
 
bool settings_changed () override
 Indicate if the Memory Collector settings have changed. More...
 
void set_params () final
 Set collection parameters from the system variables. More...
 
bool running () const override
 Return health_monitor.memory_running. More...
 
std::shared_ptr< Stat_Buffer< Process_Memory_Info > > proc_buffer ()
 
std::shared_ptr< Stat_Buffer< System_Memory_Info > > sys_buffer ()
 
int get_memory_info (Memory_Info &memory_info)
 Get the current system and process memory info. More...
 
int get_process_memory_info (Process_Memory_Info &process_info, bool &unavailable)
 Get the physical memory used by the current process. More...
 
int get_system_memory_info (System_Memory_Info &sys_memory_info)
 Get memory stats for the system. More...
 
void update_per_sample_totals (const Memory_Info &memory_info)
 Update totals used for status and warning messages, convert to MiB. More...
 
void set_memory_profile (const Memory_Info &memory_info)
 Update the memory warning thresholds, convert to MiB. More...
 
void set_state (ms::Memory_State &new_state)
 Set the next state based on the available memory. More...
 
void set_start_state ()
 
void set_stop_state ()
 
void set_normal_state ()
 
void set_warning_state ()
 
void set_error_state ()
 
void check_memory_levels () const
 Check the available memory against the memory thresholds. More...
 
void log_resource_status () override
 Memory status, depending on state. More...
 
std::string format_settings () override
 Memory Collector settings formatted string. More...
 
std::string format_status_info () override
 Memory info formatted string. More...
 
std::string tag_collector_state () override
 Collector state tag. More...
 
void log_warning_level (int)
 Low memory warning level 1/2/3. More...
 
void log_warning_level ()
 
void log_warning_error_condition ()
 Error condition warning. More...
 
- Public Member Functions inherited from hm::Collector
 Collector ()=default
 
 Collector (const char *name, const char *resource_name, const char *instr_name, const char *os_name, const char *description)
 
 ~Collector () override=default
 
 Collector (const Collector &)=delete
 
Collector & operator= (const Collector &)=delete
 
 Collector (Collector &&)=delete
 
Collector & operator= (Collector &&)=delete
 
const char * resource_name () const
 
void run_process () override
 Sample collection loop. More...
 
virtual bool dynamic_settings_changed ()
 
virtual bool static_settings_changed ()
 
void mark_settings_pending ()
 Mark a settings update for evaluation by the Supervisor. More...
 
bool settings_pending () const
 
void set_settings_pending (bool pending)
 
virtual bool update_settings ()
 Update system variable settings for the Collector. More...
 
int base_interval () const
 
int sample_interval () const
 
void set_sample_interval (int sample_interval)
 Set the sample interval, adjust to the nearest multiple of the base interval. More...
 
void set_collector_intervals (int base_interval, int sample_interval)
 Set the base and sample intervals together to ensure that the sample interval is a multiple of the base interval. More...
 
virtual void log_collector_status (bool settings)
 Collector status with optional settings. More...
 
virtual void log_collector_status (const std::string &state_msg, bool settings)
 Collector status with optional message and optional settings. More...
 
virtual void log_status ()
 Issue a log status message for the collector. More...
 
virtual void log_resource_levels ()
 Log general resource status with state, mode (Fallback, Recovery, ...) and levels. More...
 
virtual std::string build_collector_message (const std::string &status, const std::string &mode, const std::string &message, bool settings)
 Formatted collector message with optional settings. More...
 
virtual std::string build_resource_message (const std::string &status, const std::string &mode, const std::string &message, bool levels)
 Formatted resource message, no levels or settings. More...
 
virtual std::string tag_resource_state ()
 
virtual std::string tag_mode ()
 
- Public Member Functions inherited from hm::Thread
 Thread ()=default
 
 Thread (const char *name, const char *instr_name, const char *os_name, const char *desc)
 
virtual ~Thread ()=0
 
const char * name () const
 
virtual int start ()
 
virtual void stop ()
 
void signal ()
 Signal the processing loop to end the current cycle. More...
 

Static Public Member Functions

static void set_state_params ()
 Set threshold params for all memory states. More...
 
- Static Public Member Functions inherited from hm::Collector
static std::string format_level (uint64_t mbytes)
 Format storage amount in MiB, no units. More...
 
static std::string format_mb (uint64_t mbytes, int prec, bool show_units)
 Format storage amount. More...
 
- Static Public Member Functions inherited from hm::Thread
static void cleanup ()
 Cleanup thread instrumentation. More...
 
static int join (my_thread_handle *thread, void **value_ptr)
 
static bool joinable (const my_thread_handle &thread)
 

Public Attributes

ms::Memory_State * m_current_state {nullptr}
 
ms::Start_State m_start_state
 
ms::Stop_State m_stop_state
 
ms::Normal_State m_normal_state
 
ms::Warning_State m_warning_state
 
ms::Error_State m_error_state
 
uint64_t m_warn_level_1_mb {0}
 
uint64_t m_warn_level_2_mb {0}
 
uint64_t m_warn_level_3_mb {0}
 
std::atomic< bool > m_settings_changed {false}
 
uint64_t m_total_mb {0}
 
uint64_t m_avail_mb {0}
 
uint64_t m_last_avail_mb {0}
 
float m_used_pct {0}
 
int m_delta_pct {10}
 
uint64_t m_process_mb {0}
 
uint64_t m_max_warn_level_mb {no_warn_level}
 
uint64_t m_last_warn_level_mb {no_warn_level}
 
bool m_refresh_memory_profile {false}
 
bool m_sysinfo_error {false}
 
Memory_Info m_info
 
const std::string k_warning_level {"Warning Level"}
 
- Public Attributes inherited from hm::Collector
const std::string k_started {"Started"}
 
const std::string k_stopped {"Stopped"}
 
const std::string k_offline_mode {"OFFLINE_MODE"}
 
const std::string k_super_read_only {"SUPER_READ_ONLY"}
 
const std::string k_invalid_path {"Invalid Path"}
 
const std::string k_error {"ERROR"}
 
const std::string k_system_error {"SYSTEM ERROR"}
 
const std::string k_failed {"failed"}
 
const std::string k_remaining {"attempts remaining"}
 
int m_retention {0}
 
std::atomic< bool > m_settings_pending {false}
 
int m_status_interval {0}
 
int m_status_counter {0}
 
bool m_verbose_log {false}
 
bool m_force_status {false}
 
Cycle_Timer m_sample_timer
 
Cycle_Timer m_status_timer
 

Protected Member Functions

void pre_process () override
 Tasks before starting the collection loop. More...
 
void process () override
 Collect the current memory stats and write to the stat buffer. More...
 
void post_process () override
 Final tasks before exiting the thread. More...
 
- Protected Member Functions inherited from hm::Collector
void consume_settings_pending ()
 Consume one pending notification without clearing a concurrent update. More...
 
void apply_pending_settings ()
 Apply settings while the collector command lock is held. More...
 
Cycle_Timer & sample_timer ()
 
Cycle_Timer & status_message_timer ()
 
void initialize_sample_timers ()
 Initialize collection timers. More...
 
void advance_sample_timers ()
 Process collector sample and status timers. More...
 
- Protected Member Functions inherited from hm::Thread
int start_thread ()
 
void stop_thread ()
 
void request_thread_stop ()
 Request that the worker stop without waiting for it to exit. More...
 
void join_thread ()
 Wait for a stopped worker to exit. More...
 
bool stop_requested ()
 Return true when worker shutdown has been requested. More...
 

Private Attributes

std::shared_ptr< Stat_Buffer< Process_Memory_Info > > m_proc_buffer
 
std::shared_ptr< Stat_Buffer< System_Memory_Info > > m_sys_buffer
 
PSI_rwlock_key m_rwlock_key {0}
 
PSI_rwlock_info m_rwlock_info
 
PSI_memory_key m_memory_key {0}
 
PSI_memory_info m_memory_info
 

Additional Inherited Members

- Static Public Attributes inherited from hm::Collector
static constexpr uint64_t no_warn_level {std::numeric_limits<uint64_t>::max()}
 
static constexpr int k_min_interval {1}
 
static constexpr int k_max_interval {86400}
 
static constexpr int k_default_base_interval {10}
 
static constexpr int k_default_sample_interval {k_default_base_interval * 6}
 
- Protected Attributes inherited from hm::Collector
const std::string m_resource_name
 
bool m_running {false}
 
- Protected Attributes inherited from hm::Thread
std::mutex m_command_lock
 
const std::string m_name
 
const std::string m_instr_name
 
const std::string m_os_name
 
const std::string m_description
 
std::atomic< bool > m_thread_running {false}
 
bool m_stop {false}
 
my_thread_handle m_thread
 
PSI_thread_key m_thread_key {0}
 
PSI_thread_info m_thread_info
 
mysql_mutex_t m_wait_lock
 
PSI_mutex_key m_mutex_key {0}
 
PSI_mutex_info m_mutex_info
 
mysql_cond_t m_wait
 
PSI_cond_key m_cond_key {0}
 
PSI_cond_info m_cond_info
 

Detailed Description

Memory Collector.

The Memory Collector monitors server memory usage, publishes memory statistics, and emits warnings when available memory falls below the configured thresholds. Unlike the Disk Collector, the Memory Collector does not take corrective action when memory is low.

Constructor & Destructor Documentation

◆ Memory_Collector()

hm::Memory_Collector::Memory_Collector ( )

Member Function Documentation

◆ check_memory_levels()

void hm::Memory_Collector::check_memory_levels ( ) const

Check the available memory against the memory thresholds.

If available space < any warning level, issue warning message. Otherwise issue a status message.

◆ format_settings()

std::string hm::Memory_Collector::format_settings ( )
overridevirtual

Memory Collector settings formatted string.

Reimplemented from hm::Collector.

◆ format_status_info()

std::string hm::Memory_Collector::format_status_info ( )
overridevirtual

Memory info formatted string.

Reimplemented from hm::Collector.

◆ get_memory_info()

int hm::Memory_Collector::get_memory_info ( Memory_Info &  memory_info)

Get the current system and process memory info.

Parameters
[out]memory_infoSystem and process memory info
Returns
0 success, 1 failure

◆ get_process_memory_info()

int hm::Memory_Collector::get_process_memory_info ( Process_Memory_Info &  process_info,
bool &  unavailable 
)

Get the physical memory used by the current process.

Parameters
[out]process_infoProcess memory info
[out]unavailableWhether the process memory API is unavailable
Returns
0 success, 1 failure

◆ get_system_memory_info()

int hm::Memory_Collector::get_system_memory_info ( System_Memory_Info &  sys_memory_info)

Get memory stats for the system.

Parameters
[out]sys_memory_infoSystem memory info
Returns
0 success, 1 failure

◆ log_resource_status()

void hm::Memory_Collector::log_resource_status ( )
overridevirtual

Memory status, depending on state.

Implements hm::Collector.

◆ log_warning_error_condition()

void hm::Memory_Collector::log_warning_error_condition ( )

Error condition warning.

◆ log_warning_level() [1/2]

void hm::Memory_Collector::log_warning_level ( )
inline

◆ log_warning_level() [2/2]

void hm::Memory_Collector::log_warning_level ( int  )

Low memory warning level 1/2/3.

◆ post_process()

void hm::Memory_Collector::post_process ( )
overrideprotectedvirtual

Final tasks before exiting the thread.

Reimplemented from hm::Thread.

◆ pre_process()

void hm::Memory_Collector::pre_process ( )
overrideprotectedvirtual

Tasks before starting the collection loop.

Reimplemented from hm::Thread.

◆ proc_buffer()

std::shared_ptr< Stat_Buffer< Process_Memory_Info > > hm::Memory_Collector::proc_buffer ( )
inline

◆ process()

void hm::Memory_Collector::process ( )
overrideprotectedvirtual

Collect the current memory stats and write to the stat buffer.

Reimplemented from hm::Collector.

◆ running()

bool hm::Memory_Collector::running ( ) const
overridevirtual

Return health_monitor.memory_running.

Reimplemented from hm::Thread.

◆ set_buffer_size()

void hm::Memory_Collector::set_buffer_size ( )
finalvirtual

Resize the stat buffer if necessary.

Must be inside collector lock.

Reimplemented from hm::Collector.

◆ set_error_state()

void hm::Memory_Collector::set_error_state ( )
inline

◆ set_memory_profile()

void hm::Memory_Collector::set_memory_profile ( const Memory_Info &  memory_info)

Update the memory warning thresholds, convert to MiB.

Parameters
[in]memory_infoSystem memory info

◆ set_normal_state()

void hm::Memory_Collector::set_normal_state ( )
inline

◆ set_params()

void hm::Memory_Collector::set_params ( )
finalvirtual

Set collection parameters from the system variables.

Reimplemented from hm::Collector.

◆ set_start_state()

void hm::Memory_Collector::set_start_state ( )
inline

◆ set_state()

void hm::Memory_Collector::set_state ( ms::Memory_State &  new_state)

Set the next state based on the available memory.

◆ set_state_params()

void hm::Memory_Collector::set_state_params ( )
static

Set threshold params for all memory states.

◆ set_stop_state()

void hm::Memory_Collector::set_stop_state ( )
inline

◆ set_warning_state()

void hm::Memory_Collector::set_warning_state ( )
inline

◆ settings_changed()

bool hm::Memory_Collector::settings_changed ( )
overridevirtual

Indicate if the Memory Collector settings have changed.

Returns
true if settings have changed

Reimplemented from hm::Collector.

◆ sys_buffer()

std::shared_ptr< Stat_Buffer< System_Memory_Info > > hm::Memory_Collector::sys_buffer ( )
inline

◆ tag_collector_state()

std::string hm::Memory_Collector::tag_collector_state ( )
overridevirtual

Collector state tag.

Reimplemented from hm::Collector.

◆ update_per_sample_totals()

void hm::Memory_Collector::update_per_sample_totals ( const Memory_Info &  memory_info)

Update totals used for status and warning messages, convert to MiB.

Parameters
[in]memory_infoSystem memory info

Member Data Documentation

◆ k_warning_level

const std::string hm::Memory_Collector::k_warning_level {"Warning Level"}

◆ m_avail_mb

uint64_t hm::Memory_Collector::m_avail_mb {0}

◆ m_current_state

ms::Memory_State* hm::Memory_Collector::m_current_state {nullptr}

◆ m_delta_pct

int hm::Memory_Collector::m_delta_pct {10}

◆ m_error_state

ms::Error_State hm::Memory_Collector::m_error_state

◆ m_info

Memory_Info hm::Memory_Collector::m_info

◆ m_last_avail_mb

uint64_t hm::Memory_Collector::m_last_avail_mb {0}

◆ m_last_warn_level_mb

uint64_t hm::Memory_Collector::m_last_warn_level_mb {no_warn_level}

◆ m_max_warn_level_mb

uint64_t hm::Memory_Collector::m_max_warn_level_mb {no_warn_level}

◆ m_memory_info

PSI_memory_info hm::Memory_Collector::m_memory_info
private
Initial value:
{
&m_memory_key, "memory_collector", PSI_FLAG_ONLY_GLOBAL_STAT,
PSI_VOLATILITY_PROVISIONING, "Health Monitor system memory data buffer"}
PSI_memory_key m_memory_key
Definition: health_monitor_memory.h:199
#define PSI_VOLATILITY_PROVISIONING
Definition: psi_bits.h:155
#define PSI_FLAG_ONLY_GLOBAL_STAT
Global stat only flag.
Definition: psi_bits.h:112

◆ m_memory_key

PSI_memory_key hm::Memory_Collector::m_memory_key {0}
private

◆ m_normal_state

ms::Normal_State hm::Memory_Collector::m_normal_state

◆ m_proc_buffer

std::shared_ptr<Stat_Buffer<Process_Memory_Info> > hm::Memory_Collector::m_proc_buffer
private

◆ m_process_mb

uint64_t hm::Memory_Collector::m_process_mb {0}

◆ m_refresh_memory_profile

bool hm::Memory_Collector::m_refresh_memory_profile {false}

◆ m_rwlock_info

PSI_rwlock_info hm::Memory_Collector::m_rwlock_info
private
Initial value:
{&m_rwlock_key, "memory_collector",
PSI_rwlock_key m_rwlock_key
Definition: health_monitor_memory.h:195
#define PSI_DOCUMENT_ME
Definition: component_common.h:29
#define PSI_FLAG_SINGLETON
Singleton flag.
Definition: component_common.h:35

◆ m_rwlock_key

PSI_rwlock_key hm::Memory_Collector::m_rwlock_key {0}
private

◆ m_settings_changed

std::atomic<bool> hm::Memory_Collector::m_settings_changed {false}

◆ m_start_state

ms::Start_State hm::Memory_Collector::m_start_state

◆ m_stop_state

ms::Stop_State hm::Memory_Collector::m_stop_state

◆ m_sys_buffer

std::shared_ptr<Stat_Buffer<System_Memory_Info> > hm::Memory_Collector::m_sys_buffer
private

◆ m_sysinfo_error

bool hm::Memory_Collector::m_sysinfo_error {false}

◆ m_total_mb

uint64_t hm::Memory_Collector::m_total_mb {0}

◆ m_used_pct

float hm::Memory_Collector::m_used_pct {0}

◆ m_warn_level_1_mb

uint64_t hm::Memory_Collector::m_warn_level_1_mb {0}

◆ m_warn_level_2_mb

uint64_t hm::Memory_Collector::m_warn_level_2_mb {0}

◆ m_warn_level_3_mb

uint64_t hm::Memory_Collector::m_warn_level_3_mb {0}

◆ m_warning_state

ms::Warning_State hm::Memory_Collector::m_warning_state

The documentation for this class was generated from the following files: