Open Source alternative to Algolia + Pinecone and an Easier-to-Use alternative to ElasticSearch ⚡ 🔍 ✨ Fast, typo tolerant, in-memory fuzzy Search Engine for building delightful search experiences
C++ algoliadatastoreelasticsearchenterprise-searchfacetingfull-text-searchfuzzy-searchgeosearchin-memoryinstantsearchmerchandisingpineconesearchsearch-enginesemantic-searchsimilarity-searchsite-searchsynonymstypo-tolerancevector-search
Get swap usage from sysinfo.
Kishore Nallanf7b7cb8aa2c8
diff --git a/include/system_metrics.h b/include/system_metrics.hindex 721e8e08..94363afa 100644--- a/include/system_metrics.h+++ b/include/system_metrics.h@@ -143,8 +143,6 @@ private:static uint64_t get_memory_non_proc_bytes();- static uint64_t linux_get_swap_used_bytes();-public:SystemMetrics() {diff --git a/src/system_metrics.cpp b/src/system_metrics.cppindex 97781b4a..13262a45 100644--- a/src/system_metrics.cpp+++ b/src/system_metrics.cpp@@ -73,8 +73,11 @@ void SystemMetrics::get(const std::string &data_dir_path, nlohmann::json &resultresult["system_memory_used_bytes"] = std::to_string(get_memory_used_bytes());#ifdef __linux__- auto swap_bytes = linux_get_swap_used_bytes();- result["system_memory_used_swap_bytes"] = std::to_string(swap_bytes);+ struct sysinfo sys_info;+ sysinfo(&sys_info);+ auto swap_used_bytes = sys_info.totalswap - sys_info.freeswap;+ result["system_memory_total_swap_bytes"] = std::to_string(sys_info.totalswap);+ result["system_memory_used_swap_bytes"] = std::to_string(swap_used_bytes);#endif// CPU and Network metrics#if __linux__@@ -231,18 +234,3 @@ void SystemMetrics::linux_get_network_data(const std::string & stat_path,}}}--uint64_t SystemMetrics::linux_get_swap_used_bytes() {- std::string filename = "/proc/" + std::to_string(::getpid()) + "/status";- std::string token;- std::ifstream file(filename);- while(file >> token) {- if(token == "VmSwap:") {- uint64_t mem_kB;- if(file >> mem_kB) {- return mem_kB * 1024;- }- }- }- return 0;-}\ No newline at end of file