72 [[nodiscard]]
auto to_json() const -> std::
string
74 std::ostringstream json;
79 const auto time_t = std::chrono::system_clock::to_time_t(
timestamp);
82 localtime_s(&tm, &time_t);
84 localtime_r(&time_t, &tm);
86 json <<
" \"timestamp\": \""
87 << std::put_time(&tm,
"%Y-%m-%dT%H:%M:%S")
91 json <<
" \"metrics\": {\n";
94 for (
const auto& [key, value] :
values) {
100 json <<
" \"" << key <<
"\": ";
103 std::visit([&json](
const auto& v) {
104 using T = std::decay_t<
decltype(v)>;
105 if constexpr (std::is_same_v<T, std::int64_t>) {
107 }
else if constexpr (std::is_same_v<T, double>) {
108 json << std::fixed << std::setprecision(6) << v;
109 }
else if constexpr (std::is_same_v<T, std::string>) {
110 json <<
"\"" << v <<
"\"";
111 }
else if constexpr (std::is_same_v<T, bool>) {
112 json << (v ?
"true" :
"false");