MySQL 26.10.0
Source Code Documentation
hm::Collector Class Referenceabstract

#include <health_monitor_collector.h>

Inheritance diagram for hm::Collector:
[legend]

Public Member Functions

 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...
 
void process () override
 
virtual void set_buffer_size ()
 
virtual bool settings_changed ()
 
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 void set_params ()
 
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_resource_status ()=0
 
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 format_settings ()
 
virtual std::string format_status_info ()
 
virtual std::string tag_collector_state ()
 
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 bool running () const
 
virtual int start ()
 
virtual void stop ()
 
void signal ()
 Signal the processing loop to end the current cycle. More...
 

Static Public Member Functions

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

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
 

Static Public Attributes

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 Member Functions

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...
 
virtual void pre_process ()
 
virtual void post_process ()
 

Protected Attributes

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
 

Private Member Functions

void set_base_interval (int base_interval)
 Set the base monitoring interval if different than the sample interval. More...
 

Private Attributes

int m_base_interval {k_default_base_interval}
 
int m_sample_interval {k_default_sample_interval}
 
bool m_custom_base_interval {false}
 

Constructor & Destructor Documentation

◆ Collector() [1/4]

hm::Collector::Collector ( )
default

◆ Collector() [2/4]

hm::Collector::Collector ( const char *  name,
const char *  resource_name,
const char *  instr_name,
const char *  os_name,
const char *  description 
)

◆ ~Collector()

hm::Collector::~Collector ( )
overridedefault

◆ Collector() [3/4]

hm::Collector::Collector ( const Collector &  )
delete

◆ Collector() [4/4]

hm::Collector::Collector ( Collector &&  )
delete

Member Function Documentation

◆ advance_sample_timers()

void hm::Collector::advance_sample_timers ( )
protected

Process collector sample and status timers.

◆ apply_pending_settings()

void hm::Collector::apply_pending_settings ( )
protected

Apply settings while the collector command lock is held.

◆ base_interval()

int hm::Collector::base_interval ( ) const
inline

◆ build_collector_message()

std::string hm::Collector::build_collector_message ( const std::string &  status,
const std::string &  mode,
const std::string &  message,
bool  settings 
)
virtual

Formatted collector message with optional settings.

Parameters
statusCollector status such as Started, Stopped, etc.
modeMode name, if any, such as Fallback, Recovery, etc.
messageMessage text, if any
settingsIf true then append message with collector system variables
Returns
Message string assembled from all parameters, prefixed with the collector name such as Disk Collector, Memory Collector.

◆ build_resource_message()

std::string hm::Collector::build_resource_message ( const std::string &  status,
const std::string &  mode,
const std::string &  message,
bool  levels 
)
virtual

Formatted resource message, no levels or settings.

Parameters
statusResource status, if any, such as Warning Level, Normal Level
modeMode name, if any, such as Fallback, Recovery
messageMessage text, if any
levelsIf true then append message with resource levels
Returns
Message string assembled from non-empty parameters, prefixed with the resource name, such as Disk, Memory, System

◆ consume_settings_pending()

void hm::Collector::consume_settings_pending ( )
protected

Consume one pending notification without clearing a concurrent update.

◆ dynamic_settings_changed()

virtual bool hm::Collector::dynamic_settings_changed ( )
inlinevirtual

Reimplemented in hm::Disk_Forecaster.

◆ format_level()

std::string hm::Collector::format_level ( uint64_t  mbytes)
static

Format storage amount in MiB, no units.

Parameters
[in]mbytesStorage amount in megabytes
Returns
Formatted string

◆ format_mb()

std::string hm::Collector::format_mb ( uint64_t  mbytes,
int  prec,
bool  show_units 
)
static

Format storage amount.

Parameters
[in]mbytesStorage amount in megabytes
[in]precDigits after the decimal, -1 for variable wrt units
[in]show_unitsTrue to append units
Returns
Formatted string

◆ format_settings()

virtual std::string hm::Collector::format_settings ( )
inlinevirtual

◆ format_status_info()

virtual std::string hm::Collector::format_status_info ( )
inlinevirtual

◆ initialize_sample_timers()

void hm::Collector::initialize_sample_timers ( )
protected

Initialize collection timers.

◆ log_collector_status() [1/2]

void hm::Collector::log_collector_status ( bool  settings)
virtual

Collector status with optional settings.

◆ log_collector_status() [2/2]

void hm::Collector::log_collector_status ( const std::string &  state_msg,
bool  settings 
)
virtual

Collector status with optional message and optional settings.

◆ log_resource_levels()

void hm::Collector::log_resource_levels ( )
virtual

Log general resource status with state, mode (Fallback, Recovery, ...) and levels.

Reimplemented in hm::Disk_Collector, and hm::Disk_Forecaster.

◆ log_resource_status()

virtual void hm::Collector::log_resource_status ( )
pure virtual

◆ log_status()

void hm::Collector::log_status ( )
virtual

Issue a log status message for the collector.

  • Status messages are used by the collector state machines to report storage level changes.
  • The status timer advances every collection cycle and expires after status_interval * sample_interval seconds to limit repeated messages.
  • Status messages can be forced with m_force_status = true.

◆ mark_settings_pending()

void hm::Collector::mark_settings_pending ( )

Mark a settings update for evaluation by the Supervisor.

Do not inspect collector settings or acquire the command lock in the system variable callback. The Supervisor evaluates the current values while it holds the command lock.

◆ operator=() [1/2]

Collector & hm::Collector::operator= ( Collector &&  )
delete

◆ operator=() [2/2]

Collector & hm::Collector::operator= ( const Collector &  )
delete

◆ process()

void hm::Collector::process ( )
inlineoverridevirtual

◆ resource_name()

const char * hm::Collector::resource_name ( ) const
inline

◆ run_process()

void hm::Collector::run_process ( )
overridevirtual

Sample collection loop.

Reimplemented from hm::Thread.

Reimplemented in hm::Supervisor, and hm::Triggered_Reporter.

◆ sample_interval()

int hm::Collector::sample_interval ( ) const
inline

◆ sample_timer()

Cycle_Timer & hm::Collector::sample_timer ( )
inlineprotected

◆ set_base_interval()

void hm::Collector::set_base_interval ( int  base_interval)
private

Set the base monitoring interval if different than the sample interval.

Adjust the sample interval to the nearest multiple of the base interval. If the base interval is not set, then the sample interval is used as the base interval.

◆ set_buffer_size()

virtual void hm::Collector::set_buffer_size ( )
inlinevirtual

◆ set_collector_intervals()

void hm::Collector::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.

◆ set_params()

virtual void hm::Collector::set_params ( )
inlinevirtual

◆ set_sample_interval()

void hm::Collector::set_sample_interval ( int  sample_interval)

Set the sample interval, adjust to the nearest multiple of the base interval.

◆ set_settings_pending()

void hm::Collector::set_settings_pending ( bool  pending)
inline

◆ settings_changed()

virtual bool hm::Collector::settings_changed ( )
inlinevirtual

◆ settings_pending()

bool hm::Collector::settings_pending ( ) const
inline

◆ static_settings_changed()

virtual bool hm::Collector::static_settings_changed ( )
inlinevirtual

Reimplemented in hm::Disk_Forecaster.

◆ status_message_timer()

Cycle_Timer & hm::Collector::status_message_timer ( )
inlineprotected

◆ tag_collector_state()

virtual std::string hm::Collector::tag_collector_state ( )
inlinevirtual

◆ tag_mode()

virtual std::string hm::Collector::tag_mode ( )
inlinevirtual

Reimplemented in hm::Disk_Collector.

◆ tag_resource_state()

virtual std::string hm::Collector::tag_resource_state ( )
inlinevirtual

Reimplemented in hm::Disk_Collector.

◆ update_settings()

bool hm::Collector::update_settings ( )
virtual

Update system variable settings for the Collector.

  • Static system variables require the thread to be restarted.
  • Dynamic system variables can be applied without restarting the thread.
  • Collectors that do not distinguish between static and dynamic settings use settings_changed() to detect changes and therefore require a thread restart.
  • If no variables have changed, no action is taken.
Returns
true when the pending notification was consumed

Reimplemented in hm::Disk_Forecaster.

Member Data Documentation

◆ k_default_base_interval

constexpr int hm::Collector::k_default_base_interval {10}
staticconstexpr

◆ k_default_sample_interval

constexpr int hm::Collector::k_default_sample_interval {k_default_base_interval * 6}
staticconstexpr

◆ k_error

const std::string hm::Collector::k_error {"ERROR"}

◆ k_failed

const std::string hm::Collector::k_failed {"failed"}

◆ k_invalid_path

const std::string hm::Collector::k_invalid_path {"Invalid Path"}

◆ k_max_interval

constexpr int hm::Collector::k_max_interval {86400}
staticconstexpr

◆ k_min_interval

constexpr int hm::Collector::k_min_interval {1}
staticconstexpr

◆ k_offline_mode

const std::string hm::Collector::k_offline_mode {"OFFLINE_MODE"}

◆ k_remaining

const std::string hm::Collector::k_remaining {"attempts remaining"}

◆ k_started

const std::string hm::Collector::k_started {"Started"}

◆ k_stopped

const std::string hm::Collector::k_stopped {"Stopped"}

◆ k_super_read_only

const std::string hm::Collector::k_super_read_only {"SUPER_READ_ONLY"}

◆ k_system_error

const std::string hm::Collector::k_system_error {"SYSTEM ERROR"}

◆ m_base_interval

int hm::Collector::m_base_interval {k_default_base_interval}
private

◆ m_custom_base_interval

bool hm::Collector::m_custom_base_interval {false}
private

◆ m_force_status

bool hm::Collector::m_force_status {false}

◆ m_resource_name

const std::string hm::Collector::m_resource_name
protected

◆ m_retention

int hm::Collector::m_retention {0}

◆ m_running

bool hm::Collector::m_running {false}
protected

◆ m_sample_interval

int hm::Collector::m_sample_interval {k_default_sample_interval}
private

◆ m_sample_timer

Cycle_Timer hm::Collector::m_sample_timer

◆ m_settings_pending

std::atomic<bool> hm::Collector::m_settings_pending {false}

◆ m_status_counter

int hm::Collector::m_status_counter {0}

◆ m_status_interval

int hm::Collector::m_status_interval {0}

◆ m_status_timer

Cycle_Timer hm::Collector::m_status_timer

◆ m_verbose_log

bool hm::Collector::m_verbose_log {false}

◆ no_warn_level

constexpr uint64_t hm::Collector::no_warn_level {std::numeric_limits<uint64_t>::max()}
staticconstexpr

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