Fixing reading of /proc/meminfo

This commit is contained in:
Mike Kot 2021-08-06 22:33:21 +03:00
parent 71e5cfe3ca
commit e2cee2576d

View File

@ -779,9 +779,27 @@ void AsynchronousMetrics::update(std::chrono::system_clock::time_point update_ti
uint64_t kb = 0; uint64_t kb = 0;
readText(kb, *meminfo); readText(kb, *meminfo);
if (kb)
if (!kb)
{ {
skipToNextLineOrEOF(*meminfo);
continue;
}
skipWhitespaceIfAny(*meminfo, true); skipWhitespaceIfAny(*meminfo, true);
/**
* Not all entries in /proc/meminfo contain the kB suffix, e.g.
* HugePages_Total: 0
* HugePages_Free: 0
* We simply skip such entries as they're not needed
*/
if (*meminfo->position() == '\n')
{
skipToNextLineOrEOF(*meminfo);
continue;
}
assertString("kB", *meminfo); assertString("kB", *meminfo);
uint64_t bytes = kb * 1024; uint64_t bytes = kb * 1024;
@ -816,7 +834,6 @@ void AsynchronousMetrics::update(std::chrono::system_clock::time_point update_ti
{ {
new_values["OSMemorySwapCached"] = bytes; new_values["OSMemorySwapCached"] = bytes;
} }
}
skipToNextLineOrEOF(*meminfo); skipToNextLineOrEOF(*meminfo);
} }