![]() |
MySQL 26.10.0
Source Code Documentation
|
#include <health_monitor_disk_forecaster.h>
Classes | |
| struct | Status_snapshot |
Public Types | |
| enum class | Dfx_Run_Mode { NONE , NORMAL , TEST , STANDBY } |
| enum class | Dfx_Test_State { NONE , IDLE , RUNNING } |
Public Member Functions | |
| Disk_Forecaster () | |
| virtual | ~Disk_Forecaster () override |
| Disk_Forecaster (const Disk_Forecaster &)=delete | |
| Disk_Forecaster & | operator= (const Disk_Forecaster &)=delete |
| Disk_Forecaster (Disk_Forecaster &&)=delete | |
| Disk_Forecaster & | operator= (Disk_Forecaster &&)=delete |
| void | initialize () |
| Initialize the Disk Forecaster. More... | |
| void | initialize_timers () |
| Initialize the forecast and report timers. More... | |
| void | advance_cycle_timers () |
| Advance the timers driven by the base interval. More... | |
| void | pre_process () override |
| Issue status before starting the collection cycle. More... | |
| void | process_normal_cycle () |
| Normal processing cycle. More... | |
| void | process () override |
| Main processing loop, 10 second interval. More... | |
| void | post_process () override |
| Issue a status message after stopping the collection cycle. More... | |
| void | set_disk_input_available (bool available) |
| Dfx_Run_Mode | run_mode () const |
| bool | is_new_run_mode () const |
| Dfx_Test_State | test_state () const |
| void | set_run_mode (Dfx_Run_Mode mode) |
| void | set_is_new_run_mode (bool is_new) |
| void | set_test_state (Dfx_Test_State state) |
| const std::string & | run_mode_name () |
| const std::string & | test_state_name () |
| const char * | run_mode_name_ptr () const |
| const char * | test_state_name_ptr () const |
| const std::string & | forecast_status_name (Dfx_Status status) |
| bool | running () const override |
| Return health_monitor.disk_forecast_running. More... | |
| int | report_interval () const |
| std::string | test_filename () |
| std::string | volume () |
| bool | dynamic_settings_changed () override |
| Indicate if the dynamic Disk Forecast settings have changed. More... | |
| bool | static_settings_changed () override |
| Indicate if the static Disk Forecast settings have changed. More... | |
| void | set_params () final |
| Set collection parameters from the system variables. More... | |
| bool | update_settings () override |
| Apply pending settings unless a Disk Forecaster processing cycle is active. More... | |
| Disk_Metric_Buffer | disk_metric_buffer () |
| Disk_Metric_Aggregate_Buffer | disk_metric_aggregate_buffer () |
| Disk_Forecast_Buffer | disk_forecast_buffer () |
| Disk_Forecast_Summary_Buffer | disk_forecast_summary_buffer () |
| void | reset_filesystem_series () |
| Reset disk metrics and forecasts before sampling a different filesystem. More... | |
| Status_snapshot | status_snapshot () const |
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 void | set_buffer_size () |
| virtual bool | 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) |
| 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 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_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 int | start () |
| virtual void | stop () |
| void | signal () |
| Signal the processing loop to end the current cycle. More... | |
Static Public Member Functions | |
| static constexpr int | default_sample_interval () |
| static constexpr int | default_report_interval () |
| static void | reset_filesystem_series (Disk_forecast_reset_context &context) |
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) |
Static Public Attributes | |
| static const std::array< std::string, 4 > | RUN_MODE_NAMES |
| static const std::array< std::string, 3 > | TEST_STATE_NAMES |
| static const char * | dfx_run_mode_names [5] |
| static const std::array< std::string, 4 > | FORECAST_STATUS_NAMES |
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 Member Functions | |
| void | log_info_message (const std::string &msg, bool levels) |
| Informational message with collector state and optional forecast status. More... | |
| void | log_info_message (const std::string &msg) |
| Informational message with collector state and forecast status. More... | |
| void | log_resource_status () override |
| Collector or forecast status. More... | |
| void | log_resource_levels () override |
| Forecast status, no message. More... | |
| std::string | format_settings () override |
| std::string | format_status_info () override |
| Cycle_Timer & | forecast_timer () |
| Cycle_Timer & | report_timer () |
| Cycle_Timer & | short_report_timer () |
| std::string | generate_report (std::vector< Disk_Forecast > &forecasts, Disk_Forecast_Summary &summary) |
| Format the disk forecast report for the diagnostic log. More... | |
| void | log_forecast_status (std::vector< Disk_Forecast > &forecasts, Disk_Forecast_Summary &summary) |
| Send disk usage forecast summary to the error log. More... | |
| std::string | format_disk_forecast (const Disk_Forecast &dfx) |
| Generate a human-readable log message from a Disk_Forecast value. More... | |
| std::string | format_forecast_summary (const Disk_Forecast_Summary &dfxs) |
| Generate a human-readable log message from a Disk_Forecast_Summary. More... | |
| int | initialize_test () |
| Initialize the unit test. More... | |
| int | process_test_cycle () |
| Runs the unit test driven by the test data file. More... | |
| int | load_unit_test_data () |
| Load the unit test data into the disk metrics buffer. More... | |
| int | read_unit_test_file (std::vector< Disk_Metric > &disk_metrics) |
| Read the unit test file and populate the disk metrics buffer. More... | |
| void | run_unit_test () |
| Run the unit test: Generate forecasts from the uploaded disk metric data, update the forecast tables with results, write the forecast report to the diagnostics log. 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 Member Functions | |
| void | set_disk_metric_buffer_size () |
| Resize the disk metric time series buffer if sample interval changes. More... | |
| void | set_disk_metric_aggregate_buffer_size () |
| Set the disk metric aggregated buffer size to include rows for all 3 aggregation tiers. More... | |
| void | set_disk_forecast_buffer_size () |
| Set the sizes for the disk forecast and disk forecast summary buffers. More... | |
| bool | volume_size_changed () const |
| void | set_volume_size_changed (bool change) |
| Holt_Winters_Forecaster & | forecaster () |
| Dfx_Status | compute_status (double current_usage_pct, bool has_depletion_eta, double days_to_full, double usage_rate_pct_per_day) |
| Determine disk status based on usage and forecast metrics. More... | |
| Disk_Forecast_Summary | compute_summary (const Holt_Winters_State &model, double volume_size_mb, double current_usage_mb) |
| Compute a summary of the forecast model and current usage. More... | |
| int | generate_forecast (std::vector< Disk_Forecast > &disk_forecasts, Disk_Forecast_Summary &summary) |
| Terminology level - Baseline ('real') value with trend and seasonal components removed. More... | |
| bool | ready_to_forecast (bool log_warning=true) |
| Check if the forecaster is ready to produce forecasts. More... | |
| void | update_forecast_tables (std::vector< Disk_Forecast > &forecasts, Disk_Forecast_Summary &summary) |
| Update disk forecast buffers with the lastest forecast and summary. More... | |
| void | update_storage_totals (const Disk_Metric &disk_metric) |
| Update storage totals, convert to MiB. More... | |
| void | set_total_metric_count (size_t metric_count) |
| void | save_forecast_status (const std::vector< Disk_Forecast > &forecasts, const Disk_Forecast_Summary &summary) |
Static Private Member Functions | |
| static mysql_rwlock_t * | model_lock () |
Static Private Attributes | |
| static char | m_dfx_run_mode_name [32] {} |
| static char | m_dfx_test_state_name [32] {} |
| static constexpr int | k_disk_forecast_base_interval_seconds {10} |
| static constexpr int | k_time_series_interval_seconds {60} |
| static constexpr size_t | k_metric_retention_seconds {seconds_per_day * 14} |
| static constexpr int | k_forecast_interval_seconds {seconds_per_hour} |
| static constexpr int | k_report_interval_seconds {seconds_per_hour * 4} |
| static constexpr int | k_forecast_retention_seconds {seconds_per_day * 14} |
| static constexpr int | k_tier_1_days {23} |
| static constexpr int | k_tier_2_days {60} |
| static constexpr int | k_tier_3_days {275} |
| static constexpr int | k_tier_1_rows {minutes_per_day / k_tier_1_days} |
| static constexpr int | k_tier_2_rows {minutes_per_day / k_tier_2_days} |
| static constexpr int | k_tier_3_rows {minutes_per_day / k_tier_3_days} |
| static mysql_rwlock_t | m_model_lock {} |
Additional Inherited Members | |
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 |
|
strong |
|
strong |
| hm::Disk_Forecaster::Disk_Forecaster | ( | ) |
|
inlineoverridevirtual |
|
delete |
|
delete |
| void hm::Disk_Forecaster::advance_cycle_timers | ( | ) |
Advance the timers driven by the base interval.
|
private |
Determine disk status based on usage and forecast metrics.
Status levels:
| current_usage_pct | Current disk usage as a percentage of total. |
| has_depletion_eta | Whether a depletion ETA is available. |
| days_to_full | Estimated days until full (if slope positive). |
| usage_rate_pct_per_day | Projected daily usage rate as percent of volume. |
|
private |
Compute a summary of the forecast model and current usage.
Computes:
| model | Current Holt-Winters state |
| volume_size_mb | Total volume size in MiB |
| current_usage_mb | Most recent disk usage in MiB |
|
inlinestaticconstexpr |
|
inlinestaticconstexpr |
|
inline |
|
inline |
|
inline |
|
inline |
|
overridevirtual |
Indicate if the dynamic Disk Forecast settings have changed.
Dynamic settings can be applied without restarting the collector thread.
Reimplemented from hm::Collector.
| const std::string & hm::Disk_Forecaster::forecast_status_name | ( | Dfx_Status | status | ) |
|
inlineprotected |
|
inlineprivate |
|
protected |
Generate a human-readable log message from a Disk_Forecast value.
| dfx | The forecast to log |
|
protected |
Generate a human-readable log message from a Disk_Forecast_Summary.
| dfxs | The summary to log |
|
overrideprotectedvirtual |
Reimplemented from hm::Collector.
|
overrideprotectedvirtual |
Reimplemented from hm::Collector.
|
private |
Terminology level - Baseline ('real') value with trend and seasonal components removed.
season - Fixed periodic cycle, in this case a season = 1 day = 1440 minutes. trend - Slope of the level. fitted - A prediction inside the data set, i.e. what we would have predicted one step ahead: last level + last trend + seasonal value from one day ago at this time. Actual value - fitted value gives us an idea of the forecast accuracy. residual - Difference between the actual value and the one-step-ahead fitted value. We track residuals to estimate σ for prediction intervals. Ideally, residuals are like “white noise” and approximately normal. If residuals show some kind of structure, then the model should be refined (adjust α/β/γ, season length, additive vs. multiplicative, account for events, etc.) phase - The index inside the daily (seasonal) cycle: 0..m-1. Example: At minute index t, the phase is t % m. Phases let us reuse "the same minute tomorrow" information.
Notation and inputs n - Number of disk space usage values in the time series. T = Last data point. y_t - Used disk space at time index t, where t = 0..T (T = n - 1). m - Seasonal (daily) period in samples (1440 for 24h @ 1-min).
Exponential smoothing parameters, all in [0,1]: alpha(α) for level, beta(β) for trend, gamma(γ) for season
State at time t: Level ℓ_t — Baseline (the 'de‑seasonalized' center of the series). Trend b_t — Slope per sample, how fast baseline is changing at that point. Seasonal s_t — Repeating adjustment based on phase t % m.
Fitted ŷ_{t|t-1} — The one‑step‑ahead forecast made just before seeing y_t. Residual e_t = y_t − ŷ_{t|t-1} — the forecast error at step t.
Initialize if needed, advance state over this batch, emit 3 forecasts, and compute trend/ETA/status summary.
The 'batch' time series contains only the unprocessed tail of a much larger metric stream from the Disk_Metric buffer. This function:
| [out] | forecasts | Forecasts produced for 1h, 1d, 7d |
| [out] | summary | Output summary with trend/ETA/status |
|
protected |
Format the disk forecast report for the diagnostic log.
Sort forecasts by horizon. Return "No forecasts available" if the vector is empty. Trend, accuracy and usage breakdown sections currently contain placeholders.
| [in,out] | forecasts | Vector of horizon forecasts (1h/1d/7d), sorted in place. |
| [in] | summary | Latest forecast summary (trend, rate, ETA, status). |
| void hm::Disk_Forecaster::initialize | ( | ) |
Initialize the Disk Forecaster.
Performs initialization after construction. Call this immediately after creating the collector.
|
protected |
Initialize the unit test.
Assumes run_mode = TEST
| void hm::Disk_Forecaster::initialize_timers | ( | ) |
Initialize the forecast and report timers.
|
inline |
|
protected |
Load the unit test data into the disk metrics buffer.
|
protected |
Send disk usage forecast summary to the error log.
| forecasts | The most recent forecast record |
| summary | The last forecast summary |
|
protected |
Informational message with collector state and forecast status.
|
protected |
Informational message with collector state and optional forecast status.
|
overrideprotectedvirtual |
Forecast status, no message.
Reimplemented from hm::Collector.
|
overrideprotectedvirtual |
Collector or forecast status.
Implements hm::Collector.
|
staticprivate |
|
delete |
|
delete |
|
overridevirtual |
Issue a status message after stopping the collection cycle.
Reimplemented from hm::Thread.
|
overridevirtual |
Issue status before starting the collection cycle.
Reimplemented from hm::Thread.
|
overridevirtual |
Main processing loop, 10 second interval.
Get disk metrics every minute, generate forecasts, issue forecast reports.
Reimplemented from hm::Collector.
| void hm::Disk_Forecaster::process_normal_cycle | ( | ) |
Normal processing cycle.
Get disk metrics every minute, generate forecasts, issue forecast reports.
|
protected |
Runs the unit test driven by the test data file.
|
protected |
Read the unit test file and populate the disk metrics buffer.
| disk_metrics | Vector to hold the parsed disk metrics |
|
private |
Check if the forecaster is ready to produce forecasts.
| log_warning | Whether to log a warning if not ready. |
|
inline |
|
inlineprotected |
| void hm::Disk_Forecaster::reset_filesystem_series | ( | ) |
Reset disk metrics and forecasts before sampling a different filesystem.
|
static |
|
inline |
| const std::string & hm::Disk_Forecaster::run_mode_name | ( | ) |
|
inline |
|
protected |
Run the unit test: Generate forecasts from the uploaded disk metric data, update the forecast tables with results, write the forecast report to the diagnostics log.
|
overridevirtual |
Return health_monitor.disk_forecast_running.
Reimplemented from hm::Thread.
|
inlineprivate |
|
private |
Set the sizes for the disk forecast and disk forecast summary buffers.
Must be inside collector lock.
|
inline |
|
private |
Set the disk metric aggregated buffer size to include rows for all 3 aggregation tiers.
Must be inside collector lock.
|
private |
Resize the disk metric time series buffer if sample interval changes.
Must be inside collector lock.
|
inline |
|
finalvirtual |
Set collection parameters from the system variables.
Reimplemented from hm::Collector.
| void hm::Disk_Forecaster::set_run_mode | ( | Dfx_Run_Mode | mode | ) |
| void hm::Disk_Forecaster::set_test_state | ( | Dfx_Test_State | state | ) |
|
inlineprivate |
|
inlineprivate |
|
inlineprotected |
|
overridevirtual |
Indicate if the static Disk Forecast settings have changed.
Changes to static settings require that the collector thread be restarted.
Reimplemented from hm::Collector.
| Disk_Forecaster::Status_snapshot hm::Disk_Forecaster::status_snapshot | ( | ) | const |
|
inline |
|
inline |
| const std::string & hm::Disk_Forecaster::test_state_name | ( | ) |
|
inline |
|
private |
Update disk forecast buffers with the lastest forecast and summary.
| [in] | forecasts | Vector of forecasts for 1h, 1d, 1w |
| [in] | summary | Forecast summary record |
|
overridevirtual |
Apply pending settings unless a Disk Forecaster processing cycle is active.
This method is called from the Supervisor thread.
If a cycle is active, leave the settings pending and return so the Supervisor can update other collectors. The Disk Forecaster thread signals the Supervisor after the cycle completes.
Reimplemented from hm::Collector.
|
private |
Update storage totals, convert to MiB.
|
inline |
|
inlineprivate |
|
static |
|
static |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
staticconstexprprivate |
|
protected |
|
protected |
|
private |
|
staticprivate |
|
staticprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
protected |
|
protected |
|
protected |
|
staticprivate |
|
private |
|
private |
|
private |
|
private |
|
protected |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
static |
|
static |