Sha256: a98998435dfe8d2390601e099c54d86044bd27ea8b999493daf0f1b4d77c0f56

Contents?: true

Size: 1.64 KB

Versions: 16

Compression:

Stored size: 1.64 KB

Contents

#include <internal/facts/linux/memory_resolver.hpp>
#include <leatherman/file_util/file.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>

using namespace std;

using boost::lexical_cast;
using boost::bad_lexical_cast;

namespace lth_file = leatherman::file_util;

namespace facter { namespace facts { namespace linux {

    memory_resolver::data memory_resolver::collect_data(collection& facts)
    {
        data result;
        lth_file::each_line("/proc/meminfo", [&](string& line) {
            uint64_t* variable = nullptr;
            if (boost::starts_with(line, "MemTotal:")) {
                variable = &result.mem_total;
            } else if (boost::starts_with(line, "MemFree:") ||
                       boost::starts_with(line, "Buffers:") ||
                       boost::starts_with(line, "Cached:")) {
                variable = &result.mem_free;
            } else if (boost::starts_with(line, "SwapTotal:")) {
                variable = &result.swap_total;
            } else if (boost::starts_with(line, "SwapFree:")) {
                variable = &result.swap_free;
            }
            if (!variable) {
                return true;
            }

            vector<boost::iterator_range<string::iterator>> parts;
            boost::split(parts, line, boost::is_space(), boost::token_compress_on);
            if (parts.size() < 2) {
                return true;
            }

            try {
                *variable += lexical_cast<uint64_t>(parts[1]) * 1024;
            } catch (bad_lexical_cast&) {
            }
            return true;
        });
        return result;
    }

}}}  // namespace facter::facts::linux

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
facter-3.12.2.cfacter.20181217 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc
facter-3.12.1.cfacter.20181031 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc
facter-3.11.6.cfacter.20181031 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc
facter-3.12.1.cfacter.20181023 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc
facter-3.11.5.cfacter.20181022 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc
facter-3.12.0.cfacter.20181004 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc
facter-3.12.0.cfacter.20181001 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc
facter-3.12.0.cfacter.20180918 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc
facter-3.11.4.cfacter.20180821 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc
facter-3.11.3.cfacter.20180716 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc
facter-3.11.2.cfacter.20180612 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc
facter-3.9.6.cfacter.20180612 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc
facter-3.11.2.cfacter.20180606 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc
facter-3.9.6.cfacter.20180606 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc
facter-3.11.0.cfacter.20180319 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc
cfacter-3.11.0.rc.20180314 ext/facter/facter/lib/src/facts/linux/memory_resolver.cc