mark zfs arc size as free in memory

This commit is contained in:
Marwin Glaser
2021-10-28 19:10:46 +02:00
parent 562e4157c0
commit decb13eef0
2 changed files with 26 additions and 3 deletions

View File

@@ -1,8 +1,29 @@
#include "modules/memory.hpp"
static unsigned zfsArcSize() {
std::ifstream zfs_arc_stats{"/proc/spl/kstat/zfs/arcstats"};
if (zfs_arc_stats.is_open()) {
std::string name;
std::string type;
unsigned long data{0};
std::string line;
while (std::getline(zfs_arc_stats, line)) {
std::stringstream(line) >> name >> type >> data;
if (name == "size") {
return data / 1024; // convert to kB
}
}
}
return 0;
}
void waybar::modules::Memory::parseMeminfo() {
const std::string data_dir_ = "/proc/meminfo";
std::ifstream info(data_dir_);
std::ifstream info(data_dir_);
if (!info.is_open()) {
throw std::runtime_error("Can't open " + data_dir_);
}
@@ -17,4 +38,6 @@ void waybar::modules::Memory::parseMeminfo() {
int64_t value = std::stol(line.substr(posDelim + 1));
meminfo_[name] = value;
}
meminfo_["zfs_size"] = zfsArcSize();
}