提交 09701c3f 编写于 作者: C Cai Yudong 提交者: Jin Hai

#216 add CLI to get system info (#806)

上级 03ec4107
......@@ -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
......
......@@ -16,17 +16,14 @@
// under the License.
#include "metrics/SystemInfo.h"
#include "thirdparty/nlohmann/json.hpp"
#include "utils/Log.h"
#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/sysinfo.h>
#include <sys/times.h>
#include <unistd.h>
#include <fstream>
#include <iostream>
#include <string>
#include <utility>
#include <map>
#ifdef MILVUS_GPU_VERSION
#include <nvml.h>
......@@ -350,5 +347,25 @@ SystemInfo::Octets() {
return res;
}
void
SystemInfo::GetSysInfoJsonStr(std::string& result) {
std::map<std::string, std::string> sys_info_map;
sys_info_map["memory_total"] = std::to_string(GetPhysicalMemory());
sys_info_map["memory_used"] = std::to_string(GetProcessUsedMemory());
std::vector<uint64_t> gpu_mem_total = GPUMemoryTotal();
std::vector<uint64_t> 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
......@@ -17,15 +17,8 @@
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/sysinfo.h>
#include <sys/times.h>
#include <sys/types.h>
#include <sys/vtimes.h>
#include <chrono>
#include <unordered_map>
#include <string>
#include <utility>
#include <vector>
......@@ -127,6 +120,9 @@ class SystemInfo {
GPUTemperature();
std::vector<float>
CPUTemperature();
void
GetSysInfoJsonStr(std::string& result);
};
} // namespace server
......
......@@ -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") {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册