MySQL 26.10.0
Source Code Documentation
health_monitor_util.h
Go to the documentation of this file.
1/* Copyright (c) 2025, 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 <cstdint> // uint64_t
27#include <iostream>
28#include <sstream>
29#include <string>
30
31namespace hm {
32
33class utl {
34 public:
35 utl() = delete; // prevent instantiation
36 static double percent(double part, double whole);
37 /** Return the absolute percentage change, or zero without a baseline. */
38 static double change_percent(uint64_t previous, uint64_t current) {
39 if (previous == 0) return 0.0;
40 const uint64_t difference =
41 current > previous ? current - previous : previous - current;
42 return static_cast<double>(difference) / previous * 100.0;
43 }
44 static bool stoi(const std::string &s, int &result);
45 static bool stoul(const std::string &s, uint64_t &result);
46 static bool stoll(const std::string &s, int64_t &result);
47 static bool stod(const std::string &s, double &result);
48 static std::string trim(const std::string &s);
49#if 0
50 static int time_interval_to_seconds(const std::string &interval,
51 uint64_t &seconds);
52#endif
53 static int convert_timestamp(const std::string &ts_str, time_t &result);
54};
55
56class fmt {
57 public:
58 fmt() = delete; // prevent instantiation
59#if 0
60 static std::string format_bytes(const std::string &bytes_str);
61 static std::string format_bytes(uint64_t bytes);
62 static std::string format_bytes_str(const std::string str) {
63 return format_bytes(str);
64 }
65#endif
66 static std::string format_percent(const std::string &percent_str);
67 static std::string format_percent(double percent);
68 static std::string format_ms(const std::string &ms_str, bool units = true);
69 static std::string format_ms(uint64_t ms, bool units = true);
70 static std::string format_ms_str(const std::string &str) {
71 return format_ms(str);
72 }
73 static std::string format_ms_str_value(const std::string &str) {
74 return format_ms(str, false);
75 }
76 static std::string format_time(time_t time_value);
77 static std::string format_time(const struct timeval &tv);
78 static std::string format_time(const std::string &tv_str);
79 static std::string format_time_str(const std::string str) {
80 return format_time(str);
81 }
82 static std::string format_horizon(int32_t minutes, bool verbose = false);
83};
84
85} // namespace hm
Definition: health_monitor_util.h:56
static std::string format_time_str(const std::string str)
Definition: health_monitor_util.h:79
fmt()=delete
static std::string format_percent(const std::string &percent_str)
Definition: health_monitor_util.cc:224
static std::string format_ms_str_value(const std::string &str)
Definition: health_monitor_util.h:73
static std::string format_ms(const std::string &ms_str, bool units=true)
Definition: health_monitor_util.cc:244
static std::string format_time(time_t time_value)
Format time - Convert seconds to YYYY-MM-DD HH:MM:SS.
Definition: health_monitor_util.cc:273
static std::string format_horizon(int32_t minutes, bool verbose=false)
Format the horizon window for external use.
Definition: health_monitor_util.cc:335
static std::string format_ms_str(const std::string &str)
Definition: health_monitor_util.h:70
Definition: health_monitor_util.h:33
utl()=delete
static bool stoul(const std::string &s, uint64_t &result)
Definition: health_monitor_util.cc:80
static std::string trim(const std::string &s)
Definition: health_monitor_util.cc:105
static bool stoll(const std::string &s, int64_t &result)
Definition: health_monitor_util.cc:88
static bool stoi(const std::string &s, int &result)
Safe conversion functions.
Definition: health_monitor_util.cc:71
static bool stod(const std::string &s, double &result)
Definition: health_monitor_util.cc:96
static int convert_timestamp(const std::string &ts_str, time_t &result)
Convert a Unix-style timestamp to time_t.
Definition: health_monitor_util.cc:168
static double percent(double part, double whole)
Compute (part / whole) * 100, clamped to [0, 100].
Definition: health_monitor_util.cc:52
static double change_percent(uint64_t previous, uint64_t current)
Return the absolute percentage change, or zero without a baseline.
Definition: health_monitor_util.h:38
static int interval
Definition: mysqladmin.cc:72
static uint verbose
Definition: mysqlcheck.cc:66
std::string str(const mysqlrouter::ConfigGenerator::Options::Endpoint &ep)
Definition: config_generator.cc:1077
collation_unordered_map< std::string, Unit > units()
A function to obtaint the supported units for the gis module.
Definition: st_units_of_measure.cc:29
bool difference(const dd::Spatial_reference_system *srs, const Geometry *g1, const Geometry *g2, const char *func_name, std::unique_ptr< Geometry > *result) noexcept
Finds the difference between two geometries.
Definition: difference.cc:36
Definition: component_command.h:29
std::chrono::minutes minutes
Definition: authorize_manager.cc:72
std::chrono::seconds seconds
Definition: authorize_manager.cc:71
Definition: result.h:30