27 static const std::string system_mem_stat_file =
"/proc/meminfo";
28 const int mem_total = 0, available = 2, line_count = 3;
29 const auto stat_lines =
GetStatsLines(system_mem_stat_file, line_count);
30 if (stat_lines.size() < line_count) {
31 AERROR <<
"failed to load contents from " << system_mem_stat_file;
34 const auto total_memory = GetMemoryValueFromLine(stat_lines[mem_total]);
35 const auto available_memory = GetMemoryValueFromLine(stat_lines[available]);
36 if (available_memory > total_memory) {
37 AERROR <<
"available memory is larger than total memory";
40 const auto used_memory = total_memory - available_memory;
41 mem_metric->set_total_mb(total_memory >> 10);
42 mem_metric->set_used_mb(used_memory >> 10);
43 mem_metric->set_available_mb((total_memory - used_memory) >> 10);
44 mem_metric->set_usage(100.f * (
static_cast<float>(used_memory) / total_memory));
50 const std::vector<std::string> stats = absl::StrSplit(stat_line,
' ', absl::SkipWhitespace());