mirror of
https://github.com/typesense/typesense.git
synced 2025-05-19 13:12:22 +08:00
Expose all metric values only as string for consistency.
This commit is contained in:
parent
1ab9b65098
commit
6a4dbaf29c
@ -20,14 +20,20 @@ void SystemMetrics::get(const std::string &data_dir_path, nlohmann::json &result
|
||||
statvfs(data_dir_path.c_str(), &st);
|
||||
uint64_t disk_total_bytes = st.f_blocks * st.f_frsize;
|
||||
uint64_t disk_used_bytes = (st.f_blocks - st.f_bavail) * st.f_frsize;
|
||||
result["disk_total_bytes"] = disk_total_bytes;
|
||||
result["disk_used_bytes"] = disk_used_bytes;
|
||||
result["disk_total_bytes"] = std::to_string(disk_total_bytes);
|
||||
result["disk_used_bytes"] = std::to_string(disk_used_bytes);
|
||||
|
||||
// MEMORY METRICS
|
||||
|
||||
rusage r_usage;
|
||||
getrusage(RUSAGE_SELF, &r_usage);
|
||||
result["typesense_memory_used_bytes"] = r_usage.ru_maxrss * 1000;
|
||||
|
||||
// `ru_maxrss` is in bytes on OSX but in kilobytes on Linux
|
||||
#ifdef __APPLE__
|
||||
result["typesense_memory_used_bytes"] = std::to_string(r_usage.ru_maxrss);
|
||||
#elif __linux__
|
||||
result["typesense_memory_used_bytes"] = std::to_string(r_usage.ru_maxrss * 1000);
|
||||
#endif
|
||||
|
||||
uint64_t memory_available_bytes = 0;
|
||||
uint64_t memory_total_bytes = 0;
|
||||
@ -55,8 +61,8 @@ void SystemMetrics::get(const std::string &data_dir_path, nlohmann::json &result
|
||||
memory_total_bytes = sys_info.totalram;
|
||||
#endif
|
||||
|
||||
result["memory_available_bytes"] = memory_available_bytes;
|
||||
result["memory_total_bytes"] = memory_total_bytes;
|
||||
result["memory_available_bytes"] = std::to_string(memory_available_bytes);
|
||||
result["memory_total_bytes"] = std::to_string(memory_total_bytes);
|
||||
|
||||
// CPU METRICS
|
||||
#if __linux__
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "string_utils.h"
|
||||
#include <iconv.h>
|
||||
#include <unicode/translit.h>
|
||||
#include <json.hpp>
|
||||
|
||||
TEST(StringUtilsTest, ShouldNormalizeString) {
|
||||
StringUtils string_utils;
|
||||
@ -59,3 +60,21 @@ TEST(StringUtilsTest, UInt32Validation) {
|
||||
std::string big_num = "99999999999999999999999999999999";
|
||||
ASSERT_FALSE(StringUtils::is_uint32_t(big_num));
|
||||
}
|
||||
|
||||
TEST(StringUtilsTest, ShouldSplitString) {
|
||||
nlohmann::json obj1;
|
||||
obj1["s"] = "Line one.\nLine two.\n";
|
||||
|
||||
nlohmann::json obj2;
|
||||
obj2["s"] = "Line 1.\nLine 2.\n";
|
||||
|
||||
std::string text;
|
||||
text = obj1.dump();
|
||||
text += "\n" + obj2.dump();
|
||||
|
||||
std::vector<std::string> lines;
|
||||
StringUtils::split(text, lines, "\n");
|
||||
|
||||
ASSERT_STREQ("{\"s\":\"Line one.\\nLine two.\\n\"}", lines[0].c_str());
|
||||
ASSERT_STREQ("{\"s\":\"Line 1.\\nLine 2.\\n\"}", lines[1].c_str());
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user