libreoffice-online/loolwsd/Admin.hpp
Pranav Kant ea29196fed loolwsd: Periodic memory usage subscription
By default, queries and stores the total memory usage in
AdminModel every 5 seconds, and caches the last 100 such values.
Both cache size and interval can be changed by simple commands
from the clients.

Change-Id: I86cf8228d0129dc8aab0a03856c12dfeb240b169
2016-03-13 19:40:13 +05:30

115 lines
2.4 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_ADMIN_HPP
#define INCLUDED_ADMIN_HPP
#include <Poco/Net/HTTPServer.h>
#include <Poco/Runnable.h>
#include <Poco/Types.h>
#include <Poco/Util/Timer.h>
#include <Poco/Util/TimerTask.h>
#include "AdminModel.hpp"
const std::string FIFO_NOTIFY = "loolnotify.fifo";
/// An admin command processor.
class Admin : public Poco::Runnable
{
public:
Admin(const Poco::Process::PID brokerPid, const int brokerPipe, const int notifyPipe);
~Admin();
static int getBrokerPid() { return Admin::BrokerPid; }
static int getBrokerPipe() { return Admin::BrokerPipe; }
unsigned getTotalMemoryUsage(AdminModel&);
void run() override;
/// Callers must ensure that modelMutex is acquired
AdminModel& getModel();
unsigned getMemStatsInterval();
unsigned getCpuStatsInterval();
void rescheduleMemTimer(unsigned interval);
void rescheduleCpuTimer(unsigned interval);
public:
std::mutex modelMutex;
private:
void handleInput(std::string& message);
private:
Poco::Net::HTTPServer _srv;
AdminModel _model;
Poco::Util::Timer _memStatsTimer;
Poco::Util::TimerTask::Ptr _memStatsTask;
unsigned _memStatsTaskInterval = 5000;
Poco::Util::Timer _cpuStatsTimer;
Poco::Util::TimerTask::Ptr _cpuStatsTask;
unsigned _cpuStatsTaskInterval = 5000;
static Poco::Process::PID BrokerPid;
static int BrokerPipe;
static int NotifyPipe;
};
class MemoryStats : public Poco::Util::TimerTask
{
public:
MemoryStats(Admin* admin)
: _admin(admin)
{
Log::info("Memory stat ctor");
}
~MemoryStats()
{
Log::info("Memory stat dtor");
}
void run() override;
private:
Admin* _admin;
};
class CpuStats : public Poco::Util::TimerTask
{
public:
CpuStats(Admin* admin)
: _admin(admin)
{
Log::info("Cpu stat ctor");
}
~CpuStats()
{
Log::info("Cpu stat dtor");
}
void run() override;
private:
Admin* _admin;
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */