From 4c9085b3d82c1577e0e262bf7c8c962f122c1285 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 10 Sep 2017 00:15:18 +0800 Subject: [PATCH] common/util: port collect_sys_info() to osx Signed-off-by: Kefu Chai --- src/common/util.cc | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/common/util.cc b/src/common/util.cc index 25578cb5d5a4b..97b476c3e996c 100644 --- a/src/common/util.cc +++ b/src/common/util.cc @@ -28,6 +28,10 @@ #if defined(__APPLE__) || defined(__FreeBSD__) #include #include +#if defined(__APPLE__) +#include +#include +#endif #endif #include @@ -203,7 +207,35 @@ void collect_sys_info(map *m, CephContext *cct) (*m)["hostname"] = u.nodename; (*m)["arch"] = u.machine; } - +#ifdef __APPLE__ + // memory + { + uint64_t size; + size_t len = sizeof(size); + r = sysctlbyname("hw.memsize", &size, &len, NULL, 0); + if (r == 0) { + (*m)["mem_total_kb"] = std::to_string(size); + } + } + { + xsw_usage vmusage; + size_t len = sizeof(vmusage); + r = sysctlbyname("vm.swapusage", &vmusage, &len, NULL, 0); + if (r == 0) { + (*m)["mem_swap_kb"] = std::to_string(vmusage.xsu_total); + } + } + // processor + { + char buf[100]; + size_t len = sizeof(buf); + r = sysctlbyname("machdep.cpu.brand_string", buf, &len, NULL, 0); + if (r == 0) { + buf[len - 1] = '\0'; + (*m)["cpu"] = buf; + } + } +#else // memory FILE *f = fopen(PROCPREFIX "/proc/meminfo", "r"); if (f) { @@ -248,7 +280,7 @@ void collect_sys_info(map *m, CephContext *cct) } fclose(f); } - +#endif // distro info distro_detect(m, cct); } -- 2.39.5