From 09701c3f2b1921292eace2788e78498158ffc5ee Mon Sep 17 00:00:00 2001 From: Cai Yudong Date: Thu, 26 Dec 2019 14:16:20 +0800 Subject: [PATCH] #216 add CLI to get system info (#806) --- CHANGELOG.md | 1 + core/src/metrics/SystemInfo.cpp | 31 ++++++++++++++----- core/src/metrics/SystemInfo.h | 12 +++---- .../server/delivery/request/CmdRequest.cpp | 4 +++ 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c6f2d82da..645a599c62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Please mark all change in change log and use the issue from GitHub - \#770 - Server unittest run failed on low-end server ## Feature +- \#216 - Add CLI to get server info - \#343 - Add Opentracing - \#665 - Support get/set config via CLI - \#766 - If partition tag is similar, wrong partition is searched diff --git a/core/src/metrics/SystemInfo.cpp b/core/src/metrics/SystemInfo.cpp index 1421cc1c95..90d670b453 100644 --- a/core/src/metrics/SystemInfo.cpp +++ b/core/src/metrics/SystemInfo.cpp @@ -16,17 +16,14 @@ // under the License. #include "metrics/SystemInfo.h" +#include "thirdparty/nlohmann/json.hpp" #include "utils/Log.h" #include -#include -#include -#include +#include +#include #include -#include -#include -#include -#include +#include #ifdef MILVUS_GPU_VERSION #include @@ -350,5 +347,25 @@ SystemInfo::Octets() { return res; } +void +SystemInfo::GetSysInfoJsonStr(std::string& result) { + std::map sys_info_map; + + sys_info_map["memory_total"] = std::to_string(GetPhysicalMemory()); + sys_info_map["memory_used"] = std::to_string(GetProcessUsedMemory()); + + std::vector gpu_mem_total = GPUMemoryTotal(); + std::vector gpu_mem_used = GPUMemoryUsed(); + for (size_t i = 0; i < gpu_mem_total.size(); i++) { + std::string key_total = "gpu" + std::to_string(i) + "_memory_total"; + std::string key_used = "gpu" + std::to_string(i) + "_memory_used"; + sys_info_map[key_total] = std::to_string(gpu_mem_total[i]); + sys_info_map[key_used] = std::to_string(gpu_mem_used[i]); + } + + nlohmann::json sys_info_json(sys_info_map); + result = sys_info_json.dump(); +} + } // namespace server } // namespace milvus diff --git a/core/src/metrics/SystemInfo.h b/core/src/metrics/SystemInfo.h index 0176475232..03cada2033 100644 --- a/core/src/metrics/SystemInfo.h +++ b/core/src/metrics/SystemInfo.h @@ -17,15 +17,8 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include #include -#include +#include #include #include @@ -127,6 +120,9 @@ class SystemInfo { GPUTemperature(); std::vector CPUTemperature(); + + void + GetSysInfoJsonStr(std::string& result); }; } // namespace server diff --git a/core/src/server/delivery/request/CmdRequest.cpp b/core/src/server/delivery/request/CmdRequest.cpp index 4263f8715c..e4e8c9cc50 100644 --- a/core/src/server/delivery/request/CmdRequest.cpp +++ b/core/src/server/delivery/request/CmdRequest.cpp @@ -16,6 +16,7 @@ // under the License. #include "server/delivery/request/CmdRequest.h" +#include "metrics/SystemInfo.h" #include "scheduler/SchedInst.h" #include "utils/Log.h" #include "utils/TimeRecorder.h" @@ -52,6 +53,9 @@ CmdRequest::OnExecute() { #else result_ = "CPU"; #endif + } else if (cmd_ == "get_system_info") { + server::SystemInfo& sys_info_inst = server::SystemInfo::GetInstance(); + sys_info_inst.GetSysInfoJsonStr(result_); } else if (cmd_ == "build_commit_id") { result_ = LAST_COMMIT_ID; } else if (cmd_.substr(0, 10) == "set_config" || cmd_.substr(0, 10) == "get_config") {