2016-02-24 10:58:05 -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/.
|
|
|
|
*/
|
|
|
|
|
2020-04-18 03:39:50 -05:00
|
|
|
#pragma once
|
2016-02-24 10:58:05 -06:00
|
|
|
|
2016-03-03 12:01:37 -06:00
|
|
|
#include <memory>
|
2016-03-05 09:21:25 -06:00
|
|
|
#include <set>
|
2016-03-03 12:01:37 -06:00
|
|
|
#include <string>
|
2019-11-12 03:50:33 -06:00
|
|
|
#include <cmath>
|
2020-02-23 05:28:30 -06:00
|
|
|
#include <list>
|
2016-03-03 12:01:37 -06:00
|
|
|
|
|
|
|
#include <Poco/Process.h>
|
|
|
|
|
loolwsd: include cleanup and organization
A source file (.cpp) must include its own header first.
This insures that the header is self-contained and
doesn't depend on arbitrary (and accidental) includes
before it to compile.
Furthermore, system headers should go next, followed by
C then C++ headers, then libraries (Poco, etc) and, finally,
project headers come last.
This makes sure that headers and included in the same dependency
order to avoid side-effects. For example, Poco should never rely on
anything from our project in the same way that a C header should
never rely on anything in C++, Poco, or project headers.
Also, includes ought to be sorted where possible, to improve
readability and avoid accidental duplicates (of which there
were a few).
Change-Id: I62cc1343e4a091d69195e37ed659dba20cfcb1ef
Reviewed-on: https://gerrit.libreoffice.org/25262
Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Tested-by: Ashod Nakashian <ashnakash@gmail.com>
2016-05-21 09:23:07 -05:00
|
|
|
#include "Log.hpp"
|
2017-03-15 09:58:55 -05:00
|
|
|
#include "net/WebSocketHandler.hpp"
|
2016-02-24 10:58:05 -06:00
|
|
|
#include "Util.hpp"
|
|
|
|
|
2019-11-25 08:02:02 -06:00
|
|
|
struct DocumentAggregateStats;
|
2019-11-12 03:50:33 -06:00
|
|
|
|
2016-08-13 23:01:13 -05:00
|
|
|
/// A client view in Admin controller.
|
2016-03-03 12:01:37 -06:00
|
|
|
class View
|
|
|
|
{
|
|
|
|
public:
|
2017-06-23 07:32:44 -05:00
|
|
|
View(const std::string& sessionId, const std::string& userName, const std::string& userId) :
|
2016-04-17 21:11:10 -05:00
|
|
|
_sessionId(sessionId),
|
2017-04-07 09:19:04 -05:00
|
|
|
_userName(userName),
|
2017-06-23 07:32:44 -05:00
|
|
|
_userId(userId),
|
2019-11-12 03:50:33 -06:00
|
|
|
_start(std::time(nullptr)),
|
|
|
|
_loadDuration(0)
|
2016-04-17 21:11:10 -05:00
|
|
|
{
|
|
|
|
}
|
2016-03-03 12:01:37 -06:00
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
void expire() { _end = std::time(nullptr); }
|
2017-04-07 09:19:04 -05:00
|
|
|
std::string getUserName() const { return _userName; }
|
2017-06-23 07:32:44 -05:00
|
|
|
std::string getUserId() const { return _userId; }
|
2017-04-07 09:19:04 -05:00
|
|
|
std::string getSessionId() const { return _sessionId; }
|
2016-04-17 21:11:10 -05:00
|
|
|
bool isExpired() const { return _end != 0 && std::time(nullptr) >= _end; }
|
2019-11-12 03:50:33 -06:00
|
|
|
std::chrono::milliseconds getLoadDuration() const { return _loadDuration; }
|
|
|
|
void setLoadDuration(std::chrono::milliseconds loadDuration) { _loadDuration = loadDuration; }
|
2016-03-03 12:01:37 -06:00
|
|
|
|
|
|
|
private:
|
2016-04-17 21:11:10 -05:00
|
|
|
const std::string _sessionId;
|
2017-04-07 09:19:04 -05:00
|
|
|
const std::string _userName;
|
2017-06-23 07:32:44 -05:00
|
|
|
const std::string _userId;
|
2016-04-17 21:11:10 -05:00
|
|
|
const std::time_t _start;
|
2016-03-03 12:01:37 -06:00
|
|
|
std::time_t _end = 0;
|
2019-11-12 03:50:33 -06:00
|
|
|
std::chrono::milliseconds _loadDuration;
|
2016-03-03 12:01:37 -06:00
|
|
|
};
|
|
|
|
|
2017-06-11 21:51:38 -05:00
|
|
|
struct DocProcSettings
|
|
|
|
{
|
2019-01-08 02:05:40 -06:00
|
|
|
void setLimitVirtMemMb(size_t limitVirtMemMb) { _limitVirtMemMb = limitVirtMemMb; }
|
|
|
|
size_t getLimitVirtMemMb() const { return _limitVirtMemMb; }
|
|
|
|
void setLimitStackMemKb(size_t limitStackMemKb) { _limitStackMemKb = limitStackMemKb; }
|
|
|
|
size_t getLimitStackMemKb() const { return _limitStackMemKb; }
|
|
|
|
void setLimitFileSizeMb(size_t limitFileSizeMb) { _limitFileSizeMb = limitFileSizeMb; }
|
|
|
|
size_t getLimitFileSizeMb() const { return _limitFileSizeMb; }
|
|
|
|
void setLimitNumberOpenFiles(size_t limitNumberOpenFiles) { _limitNumberOpenFiles = limitNumberOpenFiles; }
|
|
|
|
size_t getLimitNumberOpenFiles() const { return _limitNumberOpenFiles; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
size_t _limitVirtMemMb;
|
|
|
|
size_t _limitStackMemKb;
|
|
|
|
size_t _limitFileSizeMb;
|
|
|
|
size_t _limitNumberOpenFiles;
|
2017-06-11 21:51:38 -05:00
|
|
|
};
|
|
|
|
|
2017-07-07 06:42:19 -05:00
|
|
|
/// Containing basic information about document
|
2018-12-21 02:07:34 -06:00
|
|
|
class DocBasicInfo
|
2017-07-07 06:42:19 -05:00
|
|
|
{
|
2018-12-21 02:07:34 -06:00
|
|
|
std::string _docKey;
|
|
|
|
std::time_t _idleTime;
|
|
|
|
int _mem;
|
|
|
|
bool _saved;
|
2018-01-10 22:53:47 -06:00
|
|
|
|
2018-12-21 02:07:34 -06:00
|
|
|
public:
|
2018-01-10 22:53:47 -06:00
|
|
|
DocBasicInfo(const std::string& docKey, std::time_t idleTime, int mem, bool saved) :
|
2018-12-21 02:07:34 -06:00
|
|
|
_docKey(docKey),
|
|
|
|
_idleTime(idleTime),
|
|
|
|
_mem(mem),
|
|
|
|
_saved(saved)
|
2018-01-10 22:53:47 -06:00
|
|
|
{
|
|
|
|
}
|
2018-12-21 02:07:34 -06:00
|
|
|
|
|
|
|
const std::string& getDocKey() const { return _docKey; }
|
|
|
|
|
|
|
|
std::time_t getIdleTime() const { return _idleTime; }
|
|
|
|
|
|
|
|
int getMem() const { return _mem; }
|
|
|
|
|
|
|
|
bool getSaved() const { return _saved; }
|
2017-07-07 06:42:19 -05:00
|
|
|
};
|
|
|
|
|
2016-08-13 23:01:13 -05:00
|
|
|
/// A document in Admin controller.
|
2016-03-03 12:01:37 -06:00
|
|
|
class Document
|
|
|
|
{
|
2020-04-25 01:45:43 -05:00
|
|
|
// cf. FILE* member.
|
|
|
|
Document(const Document &) = delete;
|
|
|
|
Document& operator = (const Document &) = delete;
|
|
|
|
|
2016-03-03 12:01:37 -06:00
|
|
|
public:
|
2016-11-23 21:42:27 -06:00
|
|
|
Document(const std::string& docKey,
|
|
|
|
Poco::Process::PID pid,
|
|
|
|
const std::string& filename)
|
|
|
|
: _docKey(docKey),
|
2016-04-15 04:00:22 -05:00
|
|
|
_pid(pid),
|
2018-01-02 20:33:09 -06:00
|
|
|
_activeViews(0),
|
2016-11-23 21:42:27 -06:00
|
|
|
_filename(filename),
|
2017-02-07 08:39:56 -06:00
|
|
|
_memoryDirty(0),
|
2017-06-05 20:17:42 -05:00
|
|
|
_lastJiffy(0),
|
2016-12-05 14:11:07 -06:00
|
|
|
_start(std::time(nullptr)),
|
2017-06-03 16:53:57 -05:00
|
|
|
_lastActivity(_start),
|
2018-01-02 20:33:09 -06:00
|
|
|
_end(0),
|
2017-06-03 16:53:57 -05:00
|
|
|
_sentBytes(0),
|
2018-01-02 20:33:09 -06:00
|
|
|
_recvBytes(0),
|
2019-11-12 03:50:33 -06:00
|
|
|
_wopiDownloadDuration(0),
|
|
|
|
_wopiUploadDuration(0),
|
2020-04-23 05:35:42 -05:00
|
|
|
_procSMaps(nullptr),
|
|
|
|
_lastTimeSMapsRead(0),
|
2018-01-02 20:33:09 -06:00
|
|
|
_isModified(false)
|
2016-03-03 12:01:37 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-04-23 05:35:42 -05:00
|
|
|
~Document()
|
|
|
|
{
|
|
|
|
if (_procSMaps)
|
|
|
|
fclose(_procSMaps);
|
|
|
|
}
|
|
|
|
|
2017-07-07 06:42:19 -05:00
|
|
|
const std::string getDocKey() const { return _docKey; }
|
|
|
|
|
2016-04-15 04:00:22 -05:00
|
|
|
Poco::Process::PID getPid() const { return _pid; }
|
2016-03-03 12:01:37 -06:00
|
|
|
|
2016-04-15 04:00:22 -05:00
|
|
|
std::string getFilename() const { return _filename; }
|
2016-03-03 12:01:37 -06:00
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
bool isExpired() const { return _end != 0 && std::time(nullptr) >= _end; }
|
2016-03-03 12:01:37 -06:00
|
|
|
|
2016-04-01 02:50:14 -05:00
|
|
|
std::time_t getElapsedTime() const { return std::time(nullptr) - _start; }
|
|
|
|
|
2016-12-05 14:11:07 -06:00
|
|
|
std::time_t getIdleTime() const { return std::time(nullptr) - _lastActivity; }
|
|
|
|
|
2017-06-23 07:32:44 -05:00
|
|
|
void addView(const std::string& sessionId, const std::string& userName, const std::string& userId);
|
2016-03-03 12:01:37 -06:00
|
|
|
|
2016-04-17 21:11:10 -05:00
|
|
|
int expireView(const std::string& sessionId);
|
2016-03-03 12:01:37 -06:00
|
|
|
|
2016-04-15 04:00:22 -05:00
|
|
|
unsigned getActiveViews() const { return _activeViews; }
|
2016-03-03 12:01:37 -06:00
|
|
|
|
2017-06-05 20:17:42 -05:00
|
|
|
unsigned getLastJiffies() const { return _lastJiffy; }
|
|
|
|
void setLastJiffies(size_t newJ) { _lastJiffy = newJ; }
|
|
|
|
|
2016-04-17 21:32:58 -05:00
|
|
|
const std::map<std::string, View>& getViews() const { return _views; }
|
|
|
|
|
2016-12-05 14:11:07 -06:00
|
|
|
void updateLastActivityTime() { _lastActivity = std::time(nullptr); }
|
2020-04-23 05:35:42 -05:00
|
|
|
int getMemoryDirty() const;
|
2016-12-05 14:11:07 -06:00
|
|
|
|
2017-04-17 13:36:04 -05:00
|
|
|
std::pair<std::time_t, std::string> getSnapshot() const;
|
|
|
|
const std::string getHistory() const;
|
|
|
|
void takeSnapshot();
|
|
|
|
|
2017-05-12 08:59:01 -05:00
|
|
|
void setModified(bool value) { _isModified = value; }
|
|
|
|
bool getModifiedStatus() const { return _isModified; }
|
|
|
|
|
2017-06-03 16:53:57 -05:00
|
|
|
void addBytes(uint64_t sent, uint64_t recv)
|
|
|
|
{
|
|
|
|
_sentBytes += sent;
|
|
|
|
_recvBytes += recv;
|
|
|
|
}
|
|
|
|
|
2017-06-11 21:51:38 -05:00
|
|
|
const DocProcSettings& getDocProcSettings() const { return _docProcSettings; }
|
|
|
|
void setDocProcSettings(const DocProcSettings& docProcSettings) { _docProcSettings = docProcSettings; }
|
|
|
|
|
2019-11-12 03:50:33 -06:00
|
|
|
std::time_t getOpenTime() const { return isExpired() ? _end - _start : getElapsedTime(); }
|
|
|
|
uint64_t getSentBytes() const { return _sentBytes; }
|
|
|
|
uint64_t getRecvBytes() const { return _recvBytes; }
|
|
|
|
void setViewLoadDuration(const std::string& sessionId, std::chrono::milliseconds viewLoadDuration);
|
|
|
|
void setWopiDownloadDuration(std::chrono::milliseconds wopiDownloadDuration) { _wopiDownloadDuration = wopiDownloadDuration; }
|
|
|
|
std::chrono::milliseconds getWopiDownloadDuration() const { return _wopiDownloadDuration; }
|
|
|
|
void setWopiUploadDuration(const std::chrono::milliseconds wopiUploadDuration) { _wopiUploadDuration = wopiUploadDuration; }
|
|
|
|
std::chrono::milliseconds getWopiUploadDuration() const { return _wopiUploadDuration; }
|
2020-04-23 05:35:42 -05:00
|
|
|
void setProcSMapsFD(const int smapsFD) { _procSMaps = fdopen(smapsFD, "r"); }
|
2019-11-12 03:50:33 -06:00
|
|
|
|
2017-04-17 13:36:04 -05:00
|
|
|
std::string to_string() const;
|
|
|
|
|
2016-03-03 12:01:37 -06:00
|
|
|
private:
|
2016-04-15 04:00:22 -05:00
|
|
|
const std::string _docKey;
|
|
|
|
const Poco::Process::PID _pid;
|
2016-03-03 12:01:37 -06:00
|
|
|
/// SessionId mapping to View object
|
2016-04-17 21:11:10 -05:00
|
|
|
std::map<std::string, View> _views;
|
2016-03-03 12:01:37 -06:00
|
|
|
/// Total number of active views
|
2018-01-02 20:33:09 -06:00
|
|
|
unsigned _activeViews;
|
2016-04-14 15:29:31 -05:00
|
|
|
/// Hosted filename
|
2016-04-15 04:00:22 -05:00
|
|
|
std::string _filename;
|
2017-02-07 08:39:56 -06:00
|
|
|
/// The dirty (ie. un-shared) memory of the document's Kit process.
|
2020-04-23 05:35:42 -05:00
|
|
|
mutable int _memoryDirty;
|
2017-06-05 20:17:42 -05:00
|
|
|
/// Last noted Jiffy count
|
|
|
|
unsigned _lastJiffy;
|
2016-03-03 12:01:37 -06:00
|
|
|
|
|
|
|
std::time_t _start;
|
2016-12-05 14:11:07 -06:00
|
|
|
std::time_t _lastActivity;
|
2018-01-02 20:33:09 -06:00
|
|
|
std::time_t _end;
|
2017-04-17 13:36:04 -05:00
|
|
|
std::map<std::time_t,std::string> _snapshots;
|
2017-06-03 16:53:57 -05:00
|
|
|
|
|
|
|
/// Total bytes sent and recv'd by this document.
|
|
|
|
uint64_t _sentBytes, _recvBytes;
|
2017-06-11 21:51:38 -05:00
|
|
|
|
2019-11-12 03:50:33 -06:00
|
|
|
//Download/upload duration from/to storage for this document
|
|
|
|
std::chrono::milliseconds _wopiDownloadDuration;
|
|
|
|
std::chrono::milliseconds _wopiUploadDuration;
|
|
|
|
|
2020-04-23 05:35:42 -05:00
|
|
|
FILE* _procSMaps;
|
|
|
|
mutable std::time_t _lastTimeSMapsRead;
|
|
|
|
|
2017-06-11 21:51:38 -05:00
|
|
|
/// Per-doc kit process settings.
|
|
|
|
DocProcSettings _docProcSettings;
|
2018-01-02 20:33:09 -06:00
|
|
|
bool _isModified;
|
2016-03-03 12:01:37 -06:00
|
|
|
};
|
|
|
|
|
2016-08-13 23:01:13 -05:00
|
|
|
/// An Admin session subscriber.
|
2016-03-03 12:01:37 -06:00
|
|
|
class Subscriber
|
|
|
|
{
|
|
|
|
public:
|
2017-11-10 02:41:33 -06:00
|
|
|
Subscriber(const std::weak_ptr<WebSocketHandler>& ws)
|
|
|
|
: _ws(ws),
|
2016-03-05 09:21:25 -06:00
|
|
|
_start(std::time(nullptr))
|
2016-03-03 12:01:37 -06:00
|
|
|
{
|
2017-01-30 07:10:10 -06:00
|
|
|
LOG_INF("Subscriber ctor.");
|
2016-03-03 12:01:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
~Subscriber()
|
|
|
|
{
|
2017-01-30 07:10:10 -06:00
|
|
|
LOG_INF("Subscriber dtor.");
|
2016-03-03 12:01:37 -06:00
|
|
|
}
|
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
bool notify(const std::string& message);
|
2016-03-03 12:01:37 -06:00
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
bool subscribe(const std::string& command);
|
2016-03-05 09:21:25 -06:00
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
void unsubscribe(const std::string& command);
|
2016-03-05 09:21:25 -06:00
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
void expire() { _end = std::time(nullptr); }
|
2016-03-05 09:21:25 -06:00
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
bool isExpired() const { return _end != 0 && std::time(nullptr) >= _end; }
|
2016-03-05 09:21:25 -06:00
|
|
|
|
2016-03-03 12:01:37 -06:00
|
|
|
private:
|
2017-03-15 09:58:55 -05:00
|
|
|
/// The underlying AdminRequestHandler
|
|
|
|
std::weak_ptr<WebSocketHandler> _ws;
|
2016-03-03 12:01:37 -06:00
|
|
|
|
2016-03-05 09:21:25 -06:00
|
|
|
std::set<std::string> _subscriptions;
|
|
|
|
|
|
|
|
std::time_t _start;
|
|
|
|
std::time_t _end = 0;
|
2016-03-03 12:01:37 -06:00
|
|
|
};
|
|
|
|
|
2016-08-13 23:01:13 -05:00
|
|
|
/// The Admin controller implementation.
|
2016-02-24 10:58:05 -06:00
|
|
|
class AdminModel
|
|
|
|
{
|
2020-04-25 01:45:43 -05:00
|
|
|
AdminModel(const AdminModel &) = delete;
|
|
|
|
AdminModel& operator = (const AdminModel &) = delete;
|
2016-02-24 10:58:05 -06:00
|
|
|
public:
|
2017-04-03 12:21:20 -05:00
|
|
|
AdminModel() :
|
2020-04-07 16:21:17 -05:00
|
|
|
_segFaultCount(0),
|
2017-04-03 12:21:20 -05:00
|
|
|
_owner(std::this_thread::get_id())
|
2016-02-24 10:58:05 -06:00
|
|
|
{
|
2017-01-30 07:10:10 -06:00
|
|
|
LOG_INF("AdminModel ctor.");
|
2016-02-24 10:58:05 -06:00
|
|
|
}
|
|
|
|
|
2017-04-17 13:36:04 -05:00
|
|
|
~AdminModel();
|
2016-02-26 00:25:13 -06:00
|
|
|
|
2017-04-03 12:21:20 -05:00
|
|
|
/// All methods here must be called from the Admin socket-poll
|
|
|
|
void setThreadOwner(const std::thread::id &id) { _owner = id; }
|
|
|
|
|
|
|
|
/// In debug mode check that code is running in the correct thread.
|
2017-04-05 07:48:49 -05:00
|
|
|
/// Asserts in the debug builds, otherwise just logs.
|
|
|
|
void assertCorrectThread() const;
|
2017-04-03 12:21:20 -05:00
|
|
|
|
2016-04-12 01:09:39 -05:00
|
|
|
std::string query(const std::string& command);
|
2017-04-17 13:36:04 -05:00
|
|
|
std::string getAllHistory() const;
|
2016-03-03 12:01:37 -06:00
|
|
|
|
2016-03-04 12:49:01 -06:00
|
|
|
/// Returns memory consumed by all active loolkit processes
|
2017-01-29 23:01:49 -06:00
|
|
|
unsigned getKitsMemoryUsage();
|
2017-06-05 20:17:42 -05:00
|
|
|
size_t getKitsJiffies();
|
2016-03-03 12:01:37 -06:00
|
|
|
|
2017-03-15 09:58:55 -05:00
|
|
|
void subscribe(int sessionId, const std::weak_ptr<WebSocketHandler>& ws);
|
2016-04-14 15:29:31 -05:00
|
|
|
void subscribe(int sessionId, const std::string& command);
|
2016-03-03 12:01:37 -06:00
|
|
|
|
2016-04-14 15:29:31 -05:00
|
|
|
void unsubscribe(int sessionId, const std::string& command);
|
2016-03-03 12:01:37 -06:00
|
|
|
|
2017-05-12 08:59:01 -05:00
|
|
|
void modificationAlert(const std::string& docKey, Poco::Process::PID pid, bool value);
|
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
void clearMemStats() { _memStats.clear(); }
|
2016-03-05 09:21:25 -06:00
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
void clearCpuStats() { _cpuStats.clear(); }
|
2016-03-05 09:21:25 -06:00
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
void addMemStats(unsigned memUsage);
|
2016-03-05 09:21:25 -06:00
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
void addCpuStats(unsigned cpuUsage);
|
2016-03-03 12:01:37 -06:00
|
|
|
|
2017-06-09 20:28:16 -05:00
|
|
|
void addSentStats(uint64_t sent);
|
|
|
|
|
|
|
|
void addRecvStats(uint64_t recv);
|
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
void setCpuStatsSize(unsigned size);
|
2016-03-05 14:39:35 -06:00
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
void setMemStatsSize(unsigned size);
|
2016-03-05 14:39:35 -06:00
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
void notify(const std::string& message);
|
2016-03-05 14:39:35 -06:00
|
|
|
|
2020-04-28 08:55:47 -05:00
|
|
|
void addDocument(const std::string& docKey, Poco::Process::PID pid, const std::string& filename,
|
|
|
|
const std::string& sessionId, const std::string& userName, const std::string& userId,
|
|
|
|
const int smapsFD);
|
2016-04-14 15:29:31 -05:00
|
|
|
|
2016-04-17 21:11:10 -05:00
|
|
|
void removeDocument(const std::string& docKey, const std::string& sessionId);
|
2016-04-17 21:32:58 -05:00
|
|
|
void removeDocument(const std::string& docKey);
|
2016-03-05 14:39:35 -06:00
|
|
|
|
2016-12-05 14:11:07 -06:00
|
|
|
void updateLastActivityTime(const std::string& docKey);
|
|
|
|
|
2017-06-03 16:53:57 -05:00
|
|
|
void addBytes(const std::string& docKey, uint64_t sent, uint64_t recv);
|
|
|
|
|
|
|
|
uint64_t getSentBytesTotal() { return _sentBytesTotal; }
|
|
|
|
uint64_t getRecvBytesTotal() { return _recvBytesTotal; }
|
|
|
|
|
2019-07-19 05:39:59 -05:00
|
|
|
double getServerUptime();
|
|
|
|
|
2017-07-07 06:42:19 -05:00
|
|
|
/// Document basic info list sorted by most idle time
|
2018-01-10 22:53:47 -06:00
|
|
|
std::vector<DocBasicInfo> getDocumentsSortedByIdle() const;
|
2017-07-07 06:42:19 -05:00
|
|
|
|
2019-11-12 03:50:33 -06:00
|
|
|
void setViewLoadDuration(const std::string& docKey, const std::string& sessionId, std::chrono::milliseconds viewLoadDuration);
|
|
|
|
void setDocWopiDownloadDuration(const std::string& docKey, std::chrono::milliseconds wopiDownloadDuration);
|
|
|
|
void setDocWopiUploadDuration(const std::string& docKey, const std::chrono::milliseconds wopiUploadDuration);
|
2020-04-07 16:21:17 -05:00
|
|
|
void addSegFaultCount(unsigned segFaultCount);
|
2019-11-12 03:50:33 -06:00
|
|
|
void setForKitPid(pid_t pid) { _forKitPid = pid; }
|
|
|
|
|
|
|
|
void getMetrics(std::ostringstream &oss);
|
|
|
|
|
2020-04-08 02:03:07 -05:00
|
|
|
std::set<pid_t> getDocumentPids() const;
|
|
|
|
|
2019-11-12 03:50:33 -06:00
|
|
|
static int getPidsFromProcName(const std::regex& procNameRegEx, std::vector<int> *pids);
|
|
|
|
|
2016-04-14 15:29:31 -05:00
|
|
|
private:
|
2016-03-31 02:25:35 -05:00
|
|
|
std::string getMemStats();
|
2016-03-05 14:39:35 -06:00
|
|
|
|
2017-06-09 20:28:16 -05:00
|
|
|
std::string getSentActivity();
|
|
|
|
|
|
|
|
std::string getRecvActivity();
|
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
std::string getCpuStats();
|
2016-03-04 12:49:01 -06:00
|
|
|
|
2016-03-31 02:25:35 -05:00
|
|
|
unsigned getTotalActiveViews();
|
2016-03-04 12:49:01 -06:00
|
|
|
|
2016-11-09 20:12:09 -06:00
|
|
|
std::string getDocuments() const;
|
2016-02-26 00:25:13 -06:00
|
|
|
|
2019-11-12 03:50:33 -06:00
|
|
|
void CalcDocAggregateStats(DocumentAggregateStats& stats);
|
|
|
|
|
2016-02-26 00:25:13 -06:00
|
|
|
private:
|
2016-03-05 09:21:25 -06:00
|
|
|
std::map<int, Subscriber> _subscribers;
|
2020-04-25 01:45:43 -05:00
|
|
|
std::map<std::string, std::unique_ptr<Document>> _documents;
|
|
|
|
std::map<std::string, std::unique_ptr<Document>> _expiredDocuments;
|
2016-03-03 12:01:37 -06:00
|
|
|
|
2017-02-07 08:39:56 -06:00
|
|
|
/// The last N total memory Dirty size.
|
2016-03-05 14:39:35 -06:00
|
|
|
std::list<unsigned> _memStats;
|
|
|
|
unsigned _memStatsSize = 100;
|
|
|
|
|
|
|
|
std::list<unsigned> _cpuStats;
|
|
|
|
unsigned _cpuStatsSize = 100;
|
2017-04-03 12:21:20 -05:00
|
|
|
|
2017-06-09 20:28:16 -05:00
|
|
|
std::list<unsigned> _sentStats;
|
2020-02-25 23:47:21 -06:00
|
|
|
unsigned _sentStatsSize = 200;
|
2017-06-09 20:28:16 -05:00
|
|
|
|
|
|
|
std::list<unsigned> _recvStats;
|
2020-02-25 23:47:21 -06:00
|
|
|
unsigned _recvStatsSize = 200;
|
2017-06-09 20:28:16 -05:00
|
|
|
|
2017-06-03 16:53:57 -05:00
|
|
|
uint64_t _sentBytesTotal;
|
|
|
|
uint64_t _recvBytesTotal;
|
|
|
|
|
2020-04-07 16:21:17 -05:00
|
|
|
uint64_t _segFaultCount;
|
|
|
|
|
2019-11-12 03:50:33 -06:00
|
|
|
pid_t _forKitPid;
|
|
|
|
|
2017-04-10 07:54:17 -05:00
|
|
|
/// We check the owner even in the release builds, needs to be always correct.
|
2017-04-03 12:21:20 -05:00
|
|
|
std::thread::id _owner;
|
2016-02-24 10:58:05 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|