2016-02-17 09:27:27 -06:00
|
|
|
/* -*- 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
|
|
|
|
|
2016-03-20 05:59:32 -05:00
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
|
|
|
#include <Poco/Net/HTTPRequestHandler.h>
|
2016-02-17 09:27:27 -06:00
|
|
|
#include <Poco/Net/HTTPServer.h>
|
2016-02-26 00:25:13 -06:00
|
|
|
#include <Poco/Runnable.h>
|
|
|
|
#include <Poco/Types.h>
|
2016-03-05 14:39:35 -06:00
|
|
|
#include <Poco/Util/Timer.h>
|
|
|
|
#include <Poco/Util/TimerTask.h>
|
2016-02-17 09:27:27 -06:00
|
|
|
|
2016-02-24 10:58:05 -06:00
|
|
|
#include "AdminModel.hpp"
|
2016-02-17 09:27:27 -06:00
|
|
|
|
2016-02-24 10:58:05 -06:00
|
|
|
const std::string FIFO_NOTIFY = "loolnotify.fifo";
|
|
|
|
|
2016-03-20 05:59:32 -05:00
|
|
|
class Admin;
|
|
|
|
|
|
|
|
class AdminRequestHandler: public Poco::Net::HTTPRequestHandler
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AdminRequestHandler(Admin* adminManager);
|
|
|
|
|
|
|
|
void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void handleWSRequests(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response, int nSessionId);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Admin* _admin;
|
|
|
|
};
|
|
|
|
|
2016-02-17 09:27:27 -06:00
|
|
|
/// An admin command processor.
|
2016-02-26 00:25:13 -06:00
|
|
|
class Admin : public Poco::Runnable
|
2016-02-17 09:27:27 -06:00
|
|
|
{
|
|
|
|
public:
|
2016-03-20 05:59:32 -05:00
|
|
|
Admin(const Poco::Process::PID brokerPid, const int notifyPipe);
|
2016-02-17 09:27:27 -06:00
|
|
|
|
2016-02-26 00:25:13 -06:00
|
|
|
~Admin();
|
2016-02-17 09:27:27 -06:00
|
|
|
|
2016-03-04 12:49:01 -06:00
|
|
|
static int getBrokerPid() { return Admin::BrokerPid; }
|
2016-02-17 09:27:27 -06:00
|
|
|
|
2016-03-05 14:39:35 -06:00
|
|
|
unsigned getTotalMemoryUsage(AdminModel&);
|
|
|
|
|
2016-02-26 00:25:13 -06:00
|
|
|
void run() override;
|
2016-02-24 10:58:05 -06:00
|
|
|
|
2016-03-05 14:39:35 -06:00
|
|
|
/// Callers must ensure that modelMutex is acquired
|
2016-03-03 12:01:37 -06:00
|
|
|
AdminModel& getModel();
|
|
|
|
|
2016-03-05 14:39:35 -06:00
|
|
|
unsigned getMemStatsInterval();
|
|
|
|
|
|
|
|
unsigned getCpuStatsInterval();
|
|
|
|
|
|
|
|
void rescheduleMemTimer(unsigned interval);
|
|
|
|
|
|
|
|
void rescheduleCpuTimer(unsigned interval);
|
|
|
|
|
2016-03-20 05:59:32 -05:00
|
|
|
AdminRequestHandler* createRequestHandler();
|
|
|
|
|
2016-03-05 14:39:35 -06:00
|
|
|
public:
|
2016-03-21 02:57:03 -05:00
|
|
|
std::mutex _modelMutex;
|
2016-03-05 14:39:35 -06:00
|
|
|
|
2016-02-26 00:25:13 -06:00
|
|
|
private:
|
|
|
|
void handleInput(std::string& message);
|
2016-02-17 09:27:27 -06:00
|
|
|
|
|
|
|
private:
|
2016-02-24 10:58:05 -06:00
|
|
|
AdminModel _model;
|
|
|
|
|
2016-03-05 14:39:35 -06:00
|
|
|
Poco::Util::Timer _memStatsTimer;
|
|
|
|
Poco::Util::TimerTask::Ptr _memStatsTask;
|
|
|
|
unsigned _memStatsTaskInterval = 5000;
|
|
|
|
|
|
|
|
Poco::Util::Timer _cpuStatsTimer;
|
|
|
|
Poco::Util::TimerTask::Ptr _cpuStatsTask;
|
|
|
|
unsigned _cpuStatsTaskInterval = 5000;
|
|
|
|
|
2016-03-04 12:49:01 -06:00
|
|
|
static Poco::Process::PID BrokerPid;
|
2016-02-17 09:27:27 -06:00
|
|
|
static int BrokerPipe;
|
2016-02-24 10:58:05 -06:00
|
|
|
static int NotifyPipe;
|
2016-02-17 09:27:27 -06:00
|
|
|
};
|
|
|
|
|
2016-03-05 14:39:35 -06:00
|
|
|
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:
|
2016-03-16 03:11:50 -05:00
|
|
|
CpuStats(Admin* /*admin*/)
|
2016-03-05 14:39:35 -06:00
|
|
|
{
|
|
|
|
Log::info("Cpu stat ctor");
|
|
|
|
}
|
|
|
|
|
|
|
|
~CpuStats()
|
|
|
|
{
|
|
|
|
Log::info("Cpu stat dtor");
|
|
|
|
}
|
|
|
|
|
|
|
|
void run() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
};
|
|
|
|
|
2016-02-17 09:27:27 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|