MySQL 26.10.0
Source Code Documentation
hm::System_Collector Class Reference

System Collector. More...

#include <health_monitor_system.h>

Inheritance diagram for hm::System_Collector:
[legend]

Public Member Functions

 System_Collector ()
 
void set_buffer_size () final
 Resize the stat buffers if necessary. More...
 
void set_cpu_buffer_size ()
 
void set_disk_buffer_size ()
 
void set_memory_buffer_size ()
 
void set_process_buffer_size ()
 
bool set_rows_per_sample ()
 Set the number of rows per sample for each statistic type. More...
 
bool settings_changed () override
 Return true if the collector settings have changed. More...
 
void set_params () final
 Set collection parameters from the system variables. More...
 
bool running () const override
 Return health_monitor.system_running. More...
 
std::shared_ptr< Stat_Buffer< System_CPU_Stats > > sys_cpu_buffer ()
 
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. More...
 
std::shared_ptr< Stat_Buffer< System_Disk_Stats > > sys_disk_buffer ()
 
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. More...
 
std::shared_ptr< Stat_Buffer< System_Memory_Stats > > sys_memory_buffer ()
 
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. More...
 
std::shared_ptr< Stat_Buffer< System_Process_Stats > > sys_process_buffer ()
 
int get_process_stats (std::vector< System_Process_Stats > &sys_process_stats)
 Get the mysqld process stats. More...
 
int get_process_stats (std::vector< System_Process_Stats > &sys_process_stats, const time_t &timestamp)
 Get the mysqld process stats. More...
 
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. More...
 
void set_state (ss::System_State &new_state)
 Set the next state. More...
 
void set_start_state ()
 
void set_stop_state ()
 
void set_normal_state ()
 
void set_warning_state ()
 
void set_error_state ()
 
void log_resource_status () override
 System status, depending on state. More...
 
void log_warning_error_condition ()
 Error condition warning. More...
 
std::string format_settings () override
 System Collector settings formatted string. More...
 
std::string format_status_info () override
 System Collector status formatted string. More...
 
std::string tag_collector_state () override
 Collector state tag. 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 int get_cpu_stats (std::vector< System_CPU_Stats > &sys_cpu_stats)
 Get the system CPU stats. More...
 
static int get_cpu_stats (std::vector< System_CPU_Stats > &sys_cpu_stats, const time_t &timestamp)
 Get the system CPU stats. More...
 
static int get_disk_stats (std::vector< System_Disk_Stats > &sys_disk_stats)
 Get storage device stats. More...
 
static int get_disk_stats (std::vector< System_Disk_Stats > &sys_disk_stats, const time_t &timestamp)
 Get storage statistics for all available devices. More...
 
static int get_memory_stats (System_Memory_Stats &mem_stats)
 Get the system memory stats. More...
 
static int get_memory_stats (System_Memory_Stats &mem_stats, const time_t &timestamp)
 Get the system memory stats. 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

ss::System_State * m_current_state {nullptr}
 
ss::Start_State m_start_state
 
ss::Stop_State m_stop_state
 
ss::Normal_State m_normal_state
 
ss::Warning_State m_warning_state
 
ss::Error_State m_error_state
 
bool m_process_stats_history {true}
 
bool m_cpu_stats_history {true}
 
bool m_disk_stats_history {true}
 
bool m_memory_stats_history {true}
 
std::atomic< bool > m_settings_changed {false}
 
bool m_rows_per_sample_set {false}
 
uint32_t m_cpu_rows_per_sample {1}
 
uint32_t m_disk_rows_per_sample {1}
 
uint32_t m_memory_rows_per_sample {1}
 
uint32_t m_process_rows_per_sample {1}
 
bool m_sysinfo_error {false}
 
bool m_sysinfo_warning {false}
 
bool m_cpu_stats_error {false}
 
bool m_disk_stats_error {false}
 
bool m_memory_stats_error {false}
 
bool m_process_stats_error {false}
 
- 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 system 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< System_CPU_Stats > > m_sys_cpu_buffer {nullptr}
 
std::shared_ptr< Stat_Buffer< System_Disk_Stats > > m_sys_disk_buffer {nullptr}
 
std::shared_ptr< Stat_Buffer< System_Memory_Stats > > m_sys_memory_buffer
 
std::shared_ptr< Stat_Buffer< System_Process_Stats > > m_sys_process_buffer
 
PSI_rwlock_key m_rwlock_key {0}
 
PSI_rwlock_info m_rwlock_info
 
PSI_memory_key m_memory_key_cpu_stats {0}
 
PSI_memory_key m_memory_key_cpu_stats_history {0}
 
PSI_memory_key m_memory_key_disk_stats {0}
 
PSI_memory_key m_memory_key_disk_stats_history {0}
 
PSI_memory_key m_memory_key_memory_stats {0}
 
PSI_memory_key m_memory_key_memory_stats_history {0}
 
PSI_memory_key m_memory_key_process_stats {0}
 
PSI_memory_key m_memory_key_process_stats_history {0}
 

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

System Collector.

The System Collector collects and publishes CPU, disk I/O, memory, and process statistics. It does not issue resource warnings or take corrective action based on these values.

Constructor & Destructor Documentation

◆ System_Collector()

hm::System_Collector::System_Collector ( )

Member Function Documentation

◆ format_settings()

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

System Collector settings formatted string.

Reimplemented from hm::Collector.

◆ format_status_info()

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

System Collector status formatted string.

Reimplemented from hm::Collector.

◆ get_cpu_stats() [1/2]

int hm::System_Collector::get_cpu_stats ( std::vector< System_CPU_Stats > &  sys_cpu_stats)
static

Get the system CPU stats.

Parameters
[in,out]sys_cpu_statsStats for each CPU
Returns
0 success, 1 failure

◆ get_cpu_stats() [2/2]

int hm::System_Collector::get_cpu_stats ( std::vector< System_CPU_Stats > &  sys_cpu_stats,
const time_t &  timestamp 
)
static

Get the system CPU stats.

Parameters
[out]sys_cpu_statsStats for each CPU
[in]timestampTimestamp to use for the record
Returns
0 success, 1 failure

◆ get_cpu_stats_buffer()

std::shared_ptr< Stat_Buffer< System_CPU_Stats > > hm::System_Collector::get_cpu_stats_buffer ( )

Get the system CPU statistics and return them in a local stat buffer.

Returns
stat_buffer with one or more rows of stats for each CPU

◆ get_disk_stats() [1/2]

int hm::System_Collector::get_disk_stats ( std::vector< System_Disk_Stats > &  sys_disk_stats)
static

Get storage device stats.

Parameters
[in,out]sys_disk_statsStats for each available storage device
Returns
0 success, 1 failure

◆ get_disk_stats() [2/2]

int hm::System_Collector::get_disk_stats ( std::vector< System_Disk_Stats > &  sys_disk_stats,
const time_t &  timestamp 
)
static

Get storage statistics for all available devices.

Parameters
[out]sys_disk_statsStats for each available storage device
[in]timestampTimestamp to use for the record
Returns
0 success or unavailable, 1 failure

◆ get_disk_stats_buffer()

std::shared_ptr< Stat_Buffer< System_Disk_Stats > > hm::System_Collector::get_disk_stats_buffer ( )

Get the system disk statistics and return them in a local stat buffer.

Returns
stat_buffer with one or more rows of stats for each storage device

◆ get_memory_stats() [1/2]

int hm::System_Collector::get_memory_stats ( System_Memory_Stats &  mem_stats)
static

Get the system memory stats.

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

◆ get_memory_stats() [2/2]

int hm::System_Collector::get_memory_stats ( System_Memory_Stats &  mem_stats,
const time_t &  timestamp 
)
static

Get the system memory stats.

Parameters
[out]mem_statsSystem memory stats
[in]timestampTimestamp to use for the record
Returns
0 success, 1 failure

◆ get_memory_stats_buffer()

std::shared_ptr< Stat_Buffer< System_Memory_Stats > > hm::System_Collector::get_memory_stats_buffer ( )

Get the system memory statistics and return them in a local stat buffer.

Returns
stat_buffer with one record of memory stats

◆ get_process_stats() [1/2]

int hm::System_Collector::get_process_stats ( std::vector< System_Process_Stats > &  sys_process_stats)

Get the mysqld process stats.

Parameters
[out]sys_process_statsArray of stats for each thread
Returns
0 success, 1 failure

◆ get_process_stats() [2/2]

int hm::System_Collector::get_process_stats ( std::vector< System_Process_Stats > &  sys_process_stats,
const time_t &  timestamp 
)

Get the mysqld process stats.

Parameters
[out]sys_process_statsArray of stats for each thread
[in]timestampTimestamp to use for the record
Returns
0 success, 1 failure

◆ get_process_stats_buffer()

std::shared_ptr< Stat_Buffer< System_Process_Stats > > hm::System_Collector::get_process_stats_buffer ( )

Get the mysqld process statistics and return them in a local stat buffer.

Returns
stat_buffer with one or more rows of process stats

◆ log_resource_status()

void hm::System_Collector::log_resource_status ( )
overridevirtual

System status, depending on state.

Implements hm::Collector.

◆ log_warning_error_condition()

void hm::System_Collector::log_warning_error_condition ( )

Error condition warning.

◆ post_process()

void hm::System_Collector::post_process ( )
overrideprotectedvirtual

Final tasks before exiting the thread.

Reimplemented from hm::Thread.

◆ pre_process()

void hm::System_Collector::pre_process ( )
overrideprotectedvirtual

Tasks before starting the collection loop.

Reimplemented from hm::Thread.

◆ process()

void hm::System_Collector::process ( )
overrideprotectedvirtual

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

Reimplemented from hm::Collector.

◆ running()

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

Return health_monitor.system_running.

Reimplemented from hm::Thread.

◆ set_buffer_size()

void hm::System_Collector::set_buffer_size ( )
finalvirtual

Resize the stat buffers if necessary.

Account for the expected number of rows per sample. Must be inside collector lock.

Reimplemented from hm::Collector.

◆ set_cpu_buffer_size()

void hm::System_Collector::set_cpu_buffer_size ( )

◆ set_disk_buffer_size()

void hm::System_Collector::set_disk_buffer_size ( )

◆ set_error_state()

void hm::System_Collector::set_error_state ( )
inline

◆ set_memory_buffer_size()

void hm::System_Collector::set_memory_buffer_size ( )

◆ set_normal_state()

void hm::System_Collector::set_normal_state ( )
inline

◆ set_params()

void hm::System_Collector::set_params ( )
finalvirtual

Set collection parameters from the system variables.

Reimplemented from hm::Collector.

◆ set_process_buffer_size()

void hm::System_Collector::set_process_buffer_size ( )

◆ set_rows_per_sample()

bool hm::System_Collector::set_rows_per_sample ( )

Set the number of rows per sample for each statistic type.

The number of rows for cpu and disk stats should remain effectively constant.

Returns
true if any rows per sample changed

◆ set_start_state()

void hm::System_Collector::set_start_state ( )
inline

◆ set_state()

void hm::System_Collector::set_state ( ss::System_State &  new_state)

Set the next state.

◆ set_stop_state()

void hm::System_Collector::set_stop_state ( )
inline

◆ set_warning_state()

void hm::System_Collector::set_warning_state ( )
inline

◆ settings_changed()

bool hm::System_Collector::settings_changed ( )
overridevirtual

Return true if the collector settings have changed.

Reimplemented from hm::Collector.

◆ sys_cpu_buffer()

std::shared_ptr< Stat_Buffer< System_CPU_Stats > > hm::System_Collector::sys_cpu_buffer ( )
inline

◆ sys_disk_buffer()

std::shared_ptr< Stat_Buffer< System_Disk_Stats > > hm::System_Collector::sys_disk_buffer ( )
inline

◆ sys_memory_buffer()

std::shared_ptr< Stat_Buffer< System_Memory_Stats > > hm::System_Collector::sys_memory_buffer ( )
inline

◆ sys_process_buffer()

std::shared_ptr< Stat_Buffer< System_Process_Stats > > hm::System_Collector::sys_process_buffer ( )
inline

◆ tag_collector_state()

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

Collector state tag.

Reimplemented from hm::Collector.

Member Data Documentation

◆ m_cpu_rows_per_sample

uint32_t hm::System_Collector::m_cpu_rows_per_sample {1}

◆ m_cpu_stats_error

bool hm::System_Collector::m_cpu_stats_error {false}

◆ m_cpu_stats_history

bool hm::System_Collector::m_cpu_stats_history {true}

◆ m_current_state

ss::System_State* hm::System_Collector::m_current_state {nullptr}

◆ m_disk_rows_per_sample

uint32_t hm::System_Collector::m_disk_rows_per_sample {1}

◆ m_disk_stats_error

bool hm::System_Collector::m_disk_stats_error {false}

◆ m_disk_stats_history

bool hm::System_Collector::m_disk_stats_history {true}

◆ m_error_state

ss::Error_State hm::System_Collector::m_error_state

◆ m_memory_key_cpu_stats

PSI_memory_key hm::System_Collector::m_memory_key_cpu_stats {0}
private

◆ m_memory_key_cpu_stats_history

PSI_memory_key hm::System_Collector::m_memory_key_cpu_stats_history {0}
private

◆ m_memory_key_disk_stats

PSI_memory_key hm::System_Collector::m_memory_key_disk_stats {0}
private

◆ m_memory_key_disk_stats_history

PSI_memory_key hm::System_Collector::m_memory_key_disk_stats_history {0}
private

◆ m_memory_key_memory_stats

PSI_memory_key hm::System_Collector::m_memory_key_memory_stats {0}
private

◆ m_memory_key_memory_stats_history

PSI_memory_key hm::System_Collector::m_memory_key_memory_stats_history {0}
private

◆ m_memory_key_process_stats

PSI_memory_key hm::System_Collector::m_memory_key_process_stats {0}
private

◆ m_memory_key_process_stats_history

PSI_memory_key hm::System_Collector::m_memory_key_process_stats_history {0}
private

◆ m_memory_rows_per_sample

uint32_t hm::System_Collector::m_memory_rows_per_sample {1}

◆ m_memory_stats_error

bool hm::System_Collector::m_memory_stats_error {false}

◆ m_memory_stats_history

bool hm::System_Collector::m_memory_stats_history {true}

◆ m_normal_state

ss::Normal_State hm::System_Collector::m_normal_state

◆ m_process_rows_per_sample

uint32_t hm::System_Collector::m_process_rows_per_sample {1}

◆ m_process_stats_error

bool hm::System_Collector::m_process_stats_error {false}

◆ m_process_stats_history

bool hm::System_Collector::m_process_stats_history {true}

◆ m_rows_per_sample_set

bool hm::System_Collector::m_rows_per_sample_set {false}

◆ m_rwlock_info

PSI_rwlock_info hm::System_Collector::m_rwlock_info
private
Initial value:
{&m_rwlock_key, "system_collector",
PSI_rwlock_key m_rwlock_key
Definition: health_monitor_system.h:157
#define PSI_DOCUMENT_ME
Definition: component_common.h:29
#define PSI_FLAG_SINGLETON
Singleton flag.
Definition: component_common.h:35
#define PSI_VOLATILITY_PROVISIONING
Definition: psi_bits.h:155

◆ m_rwlock_key

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

◆ m_settings_changed

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

◆ m_start_state

ss::Start_State hm::System_Collector::m_start_state

◆ m_stop_state

ss::Stop_State hm::System_Collector::m_stop_state

◆ m_sys_cpu_buffer

std::shared_ptr<Stat_Buffer<System_CPU_Stats> > hm::System_Collector::m_sys_cpu_buffer {nullptr}
private

◆ m_sys_disk_buffer

std::shared_ptr<Stat_Buffer<System_Disk_Stats> > hm::System_Collector::m_sys_disk_buffer {nullptr}
private

◆ m_sys_memory_buffer

std::shared_ptr<Stat_Buffer<System_Memory_Stats> > hm::System_Collector::m_sys_memory_buffer
private
Initial value:
{
nullptr}

◆ m_sys_process_buffer

std::shared_ptr<Stat_Buffer<System_Process_Stats> > hm::System_Collector::m_sys_process_buffer
private
Initial value:
{
nullptr}

◆ m_sysinfo_error

bool hm::System_Collector::m_sysinfo_error {false}

◆ m_sysinfo_warning

bool hm::System_Collector::m_sysinfo_warning {false}

◆ m_warning_state

ss::Warning_State hm::System_Collector::m_warning_state

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