admin: expose total available memory to admin clients

Take into reckoning the memproportion config value for total available
memory to us.

Change-Id: Ib93c88d746268f3e9f566beed7df77357d530eba
This commit is contained in:
Pranav Kant
2017-08-29 11:17:39 +05:30
parent c61db390c9
commit 65e3f7c7df
2 changed files with 14 additions and 0 deletions

View File

@ -145,6 +145,9 @@ void AdminSocketHandler::handleMessage(bool /* fin */, WSOpCode /* code */,
else if (tokens[0] == "total_mem")
sendTextFrame("total_mem " + std::to_string(_admin->getTotalMemoryUsage()));
else if (tokens[0] == "total_avail_mem")
sendTextFrame("total_avail_mem " + std::to_string(_admin->getTotalAvailableMemory()));
else if (tokens[0] == "sent_bytes")
sendTextFrame("sent_bytes " + std::to_string(model.getSentBytesTotal() / 1024));
@ -336,6 +339,13 @@ Admin::Admin() :
_totalSysMem = Util::getTotalSystemMemory();
LOG_TRC("Total system memory : " << _totalSysMem);
const auto memLimit = LOOLWSD::getConfigValue<double>("memproportion", static_cast<double>(0.0));
_totalAvailMem = _totalSysMem;
if (memLimit != 0.0)
_totalAvailMem = _totalSysMem * memLimit/100.;
LOG_TRC("Total available memory: " << _totalAvailMem << " (memproportion: " << memLimit << ").");
const auto totalMem = getTotalMemoryUsage();
LOG_TRC("Total memory used: " << totalMem);
_model.addMemStats(totalMem);

View File

@ -70,6 +70,9 @@ public:
void pollingThread() override;
size_t getTotalMemoryUsage();
/// Takes into account the 'memproportion' property in config file to find the amount of memory
/// available to us.
size_t getTotalAvailableMemory() { return _totalAvailMem; }
size_t getTotalCpuUsage();
void modificationAlert(const std::string& dockey, Poco::Process::PID pid, bool value);
@ -134,6 +137,7 @@ private:
uint64_t _lastSentCount;
uint64_t _lastRecvCount;
size_t _totalSysMem;
size_t _totalAvailMem;
std::atomic<int> _memStatsTaskIntervalMs;
std::atomic<int> _cpuStatsTaskIntervalMs;