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 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
|
|
|
|
2020-06-03 09:43:52 -05:00
|
|
|
#include <cmath>
|
|
|
|
#include <ctime>
|
|
|
|
#include <list>
|
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>
|
2020-06-03 09:43:52 -05:00
|
|
|
#include <utility>
|
2022-12-06 06:00:32 -06:00
|
|
|
#include <Poco/URI.h>
|
|
|
|
|
2020-06-03 09:43:52 -05:00
|
|
|
#include <common/Log.hpp>
|
2016-02-24 10:58:05 -06:00
|
|
|
#include "Util.hpp"
|
2020-06-03 09:43:52 -05:00
|
|
|
#include "net/WebSocketHandler.hpp"
|
2016-02-24 10:58:05 -06:00
|
|
|
|
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:
|
2023-05-02 08:29:40 -05:00
|
|
|
View(std::string sessionId, std::string userName, std::string userId, bool readOnly)
|
2020-06-03 09:46:23 -05:00
|
|
|
: _sessionId(std::move(sessionId))
|
|
|
|
, _userName(std::move(userName))
|
|
|
|
, _userId(std::move(userId))
|
|
|
|
, _start(std::time(nullptr))
|
|
|
|
, _loadDuration(0)
|
2023-05-02 08:29:40 -05:00
|
|
|
, _readOnly(readOnly)
|
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; }
|
2023-05-02 08:29:40 -05:00
|
|
|
bool isReadOnly() const { return _readOnly; }
|
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;
|
2023-05-02 08:29:40 -05:00
|
|
|
bool _readOnly = false;
|
2016-03-03 12:01:37 -06:00
|
|
|
};
|
|
|
|
|
2020-06-08 05:41:03 -05:00
|
|
|
struct DocCleanupSettings
|
|
|
|
{
|
2023-06-14 03:19:02 -05:00
|
|
|
DocCleanupSettings()
|
|
|
|
: _enable(false)
|
|
|
|
, _cleanupInterval(0)
|
|
|
|
, _badBehaviorPeriod(0)
|
|
|
|
, _idleTime(0)
|
|
|
|
, _limitDirtyMem(0)
|
|
|
|
, _limitCpu(0)
|
|
|
|
, _lostKitGracePeriod(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-06-08 05:41:03 -05:00
|
|
|
void setEnable(bool enable) { _enable = enable; }
|
|
|
|
bool getEnable() const { return _enable; }
|
|
|
|
void setCleanupInterval(size_t cleanupInterval) { _cleanupInterval = cleanupInterval; }
|
|
|
|
size_t getCleanupInterval() const { return _cleanupInterval; }
|
|
|
|
void setBadBehaviorPeriod(size_t badBehaviorPeriod) { _badBehaviorPeriod = badBehaviorPeriod; }
|
|
|
|
size_t getBadBehaviorPeriod() const { return _badBehaviorPeriod; }
|
|
|
|
void setIdleTime(size_t idleTime) { _idleTime = idleTime; }
|
|
|
|
size_t getIdleTime() { return _idleTime; }
|
|
|
|
void setLimitDirtyMem(size_t limitDirtyMem) { _limitDirtyMem = limitDirtyMem; }
|
|
|
|
size_t getLimitDirtyMem() const { return _limitDirtyMem; }
|
|
|
|
void setLimitCpu(size_t limitCpu) { _limitCpu = limitCpu; }
|
|
|
|
size_t getLimitCpu() const { return _limitCpu; }
|
2021-03-26 11:57:08 -05:00
|
|
|
void setLostKitGracePeriod(size_t lostKitGracePeriod) { _lostKitGracePeriod = lostKitGracePeriod; }
|
|
|
|
size_t getLostKitGracePeriod() { return _lostKitGracePeriod; }
|
2020-06-08 05:41:03 -05:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool _enable;
|
|
|
|
size_t _cleanupInterval;
|
|
|
|
size_t _badBehaviorPeriod;
|
|
|
|
size_t _idleTime;
|
|
|
|
size_t _limitDirtyMem;
|
|
|
|
size_t _limitCpu;
|
2021-03-26 11:57:08 -05:00
|
|
|
size_t _lostKitGracePeriod;
|
2020-06-08 05:41:03 -05:00
|
|
|
};
|
|
|
|
|
2017-06-11 21:51:38 -05:00
|
|
|
struct DocProcSettings
|
|
|
|
{
|
2023-06-14 03:19:02 -05:00
|
|
|
DocProcSettings()
|
|
|
|
: _limitVirtMemMb(0)
|
|
|
|
, _limitStackMemKb(0)
|
|
|
|
, _limitFileSizeMb(0)
|
|
|
|
, _limitNumberOpenFiles(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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; }
|
|
|
|
|
2020-06-08 05:41:03 -05:00
|
|
|
DocCleanupSettings& getCleanupSettings() { return _docCleanupSettings; }
|
|
|
|
|
2019-01-08 02:05:40 -06:00
|
|
|
private:
|
|
|
|
size_t _limitVirtMemMb;
|
|
|
|
size_t _limitStackMemKb;
|
|
|
|
size_t _limitFileSizeMb;
|
|
|
|
size_t _limitNumberOpenFiles;
|
2020-06-08 05:41:03 -05:00
|
|
|
|
|
|
|
DocCleanupSettings _docCleanupSettings;
|
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:
|
2020-06-03 09:46:23 -05:00
|
|
|
DocBasicInfo(std::string docKey, std::time_t idleTime, int mem, bool saved)
|
|
|
|
: _docKey(std::move(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:
|
2022-12-06 06:00:32 -06:00
|
|
|
Document(std::string docKey, pid_t pid, std::string filename, Poco::URI wopiSrc)
|
2020-06-03 09:46:23 -05:00
|
|
|
: _docKey(std::move(docKey))
|
|
|
|
, _pid(pid)
|
|
|
|
, _activeViews(0)
|
|
|
|
, _filename(std::move(filename))
|
2022-12-06 06:00:32 -06:00
|
|
|
, _wopiSrc(std::move(wopiSrc))
|
2020-06-03 09:46:23 -05:00
|
|
|
, _memoryDirty(0)
|
|
|
|
, _lastJiffy(0)
|
|
|
|
, _lastCpuPercentage(0)
|
|
|
|
, _start(std::time(nullptr))
|
|
|
|
, _lastActivity(_start)
|
|
|
|
, _end(0)
|
|
|
|
, _sentBytes(0)
|
|
|
|
, _recvBytes(0)
|
|
|
|
, _wopiDownloadDuration(0)
|
|
|
|
, _wopiUploadDuration(0)
|
|
|
|
, _procSMaps(nullptr)
|
|
|
|
, _lastTimeSMapsRead(0)
|
|
|
|
, _isModified(false)
|
|
|
|
, _hasMemDirtyChanged(true)
|
|
|
|
, _badBehaviorDetectionTime(0)
|
|
|
|
, _abortTime(0)
|
2023-04-27 08:11:18 -05:00
|
|
|
, _isUploaded(0)
|
2016-03-03 12:01:37 -06:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-04-23 05:35:42 -05:00
|
|
|
~Document()
|
|
|
|
{
|
|
|
|
if (_procSMaps)
|
|
|
|
fclose(_procSMaps);
|
|
|
|
}
|
|
|
|
|
2020-06-03 09:43:52 -05:00
|
|
|
std::string getDocKey() const { return _docKey; }
|
2017-07-07 06:42:19 -05:00
|
|
|
|
2019-11-26 07:15:38 -06:00
|
|
|
pid_t 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
|
|
|
|
2022-12-06 06:00:32 -06:00
|
|
|
std::string getHostName() const { return _wopiSrc.getHost(); }
|
|
|
|
|
|
|
|
std::string getWopiSrc() const { return _wopiSrc.toString(); }
|
2021-09-02 08:35:41 -05: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; }
|
|
|
|
|
2023-05-02 08:29:40 -05:00
|
|
|
void addView(const std::string& sessionId, const std::string& userName, const std::string& userId, bool readOnly);
|
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
|
|
|
|
2022-09-01 16:44:11 -05:00
|
|
|
size_t getLastJiffies() const { return _lastJiffy; }
|
2020-06-08 05:41:03 -05:00
|
|
|
void setLastJiffies(size_t newJ);
|
|
|
|
unsigned getLastCpuPercentage(){ return _lastCpuPercentage; }
|
2017-06-05 20:17:42 -05:00
|
|
|
|
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-05-29 06:32:04 -05:00
|
|
|
void updateMemoryDirty();
|
2020-06-08 05:41:03 -05:00
|
|
|
size_t getMemoryDirty() const { return _memoryDirty; }
|
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; }
|
|
|
|
|
2023-04-27 08:11:18 -05:00
|
|
|
void setUploaded(bool value) { _isUploaded = value; }
|
|
|
|
bool getUploadedStatus() const { return _isUploaded; }
|
|
|
|
|
2017-06-03 16:53:57 -05:00
|
|
|
void addBytes(uint64_t sent, uint64_t recv)
|
|
|
|
{
|
|
|
|
_sentBytes += sent;
|
|
|
|
_recvBytes += recv;
|
|
|
|
}
|
|
|
|
|
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"); }
|
2020-05-29 06:32:04 -05:00
|
|
|
bool hasMemDirtyChanged() const { return _hasMemDirtyChanged; }
|
|
|
|
void setMemDirtyChanged(bool changeStatus) { _hasMemDirtyChanged = changeStatus; }
|
2021-10-27 08:52:20 -05:00
|
|
|
time_t getBadBehaviorDetectionTime() const { return _badBehaviorDetectionTime; }
|
2020-06-08 05:41:03 -05:00
|
|
|
void setBadBehaviorDetectionTime(time_t badBehaviorDetectionTime){ _badBehaviorDetectionTime = badBehaviorDetectionTime;}
|
2021-10-27 08:52:20 -05:00
|
|
|
time_t getAbortTime() const { return _abortTime; }
|
2020-06-08 05:41:03 -05:00
|
|
|
void setAbortTime(time_t abortTime) { _abortTime = abortTime; }
|
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;
|
2019-11-26 07:15:38 -06:00
|
|
|
const pid_t _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;
|
2021-09-02 08:35:41 -05:00
|
|
|
|
2022-12-06 06:00:32 -06:00
|
|
|
Poco::URI _wopiSrc;
|
2017-02-07 08:39:56 -06:00
|
|
|
/// The dirty (ie. un-shared) memory of the document's Kit process.
|
2020-06-08 05:41:03 -05:00
|
|
|
size_t _memoryDirty;
|
2017-06-05 20:17:42 -05:00
|
|
|
/// Last noted Jiffy count
|
2022-09-01 16:44:11 -05:00
|
|
|
size_t _lastJiffy;
|
2020-12-06 13:51:54 -06:00
|
|
|
std::chrono::steady_clock::time_point _lastJiffyTime;
|
2020-06-08 05:41:03 -05:00
|
|
|
unsigned _lastCpuPercentage;
|
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;
|
2020-05-29 06:32:04 -05:00
|
|
|
std::time_t _lastTimeSMapsRead;
|
2020-04-23 05:35:42 -05:00
|
|
|
|
2018-01-02 20:33:09 -06:00
|
|
|
bool _isModified;
|
2020-05-29 06:32:04 -05:00
|
|
|
bool _hasMemDirtyChanged;
|
2020-06-08 05:41:03 -05:00
|
|
|
|
|
|
|
std::time_t _badBehaviorDetectionTime;
|
|
|
|
std::time_t _abortTime;
|
2023-04-27 08:11:18 -05:00
|
|
|
|
|
|
|
bool _isUploaded;
|
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:
|
2020-06-03 09:46:23 -05:00
|
|
|
explicit Subscriber(std::weak_ptr<WebSocketHandler> ws)
|
|
|
|
: _ws(std::move(ws))
|
|
|
|
, _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; }
|
|
|
|
|
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
|
|
|
|
2021-11-18 06:08:14 -06:00
|
|
|
/// Returns memory consumed by all active coolkit 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
|
|
|
|
2019-11-26 07:15:38 -06:00
|
|
|
void modificationAlert(const std::string& docKey, pid_t pid, bool value);
|
2017-05-12 08:59:01 -05:00
|
|
|
|
2023-04-27 08:11:18 -05:00
|
|
|
void uploadedAlert(const std::string& docKey, pid_t 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
|
|
|
|
2019-11-26 07:15:38 -06:00
|
|
|
void addDocument(const std::string& docKey, pid_t pid, const std::string& filename,
|
2020-04-28 08:55:47 -05:00
|
|
|
const std::string& sessionId, const std::string& userName, const std::string& userId,
|
2023-05-02 08:29:40 -05:00
|
|
|
const int smapsFD, const Poco::URI& wopiSrc, bool readOnly);
|
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; }
|
|
|
|
|
2020-12-06 13:51:54 -06:00
|
|
|
static double getServerUptimeSecs();
|
2019-07-19 05:39:59 -05:00
|
|
|
|
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;
|
2020-06-08 05:41:03 -05:00
|
|
|
void cleanupResourceConsumingDocs();
|
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; }
|
2021-03-26 11:57:08 -05:00
|
|
|
void addLostKitsTerminated(unsigned lostKitsTerminated);
|
2019-11-12 03:50:33 -06:00
|
|
|
|
|
|
|
void getMetrics(std::ostringstream &oss);
|
|
|
|
|
2020-04-08 02:03:07 -05:00
|
|
|
std::set<pid_t> getDocumentPids() const;
|
2020-05-29 06:32:04 -05:00
|
|
|
void UpdateMemoryDirty();
|
|
|
|
void notifyDocsMemDirtyChanged();
|
2020-04-08 02:03:07 -05:00
|
|
|
|
2020-06-08 05:41:03 -05:00
|
|
|
const DocProcSettings& getDefDocProcSettings() const { return _defDocProcSettings; }
|
|
|
|
void setDefDocProcSettings(const DocProcSettings& docProcSettings) { _defDocProcSettings = docProcSettings; }
|
|
|
|
|
2019-11-12 03:50:33 -06:00
|
|
|
static int getPidsFromProcName(const std::regex& procNameRegEx, std::vector<int> *pids);
|
2021-03-26 11:57:08 -05:00
|
|
|
static int getAssignedKitPids(std::vector<int> *pids);
|
|
|
|
static int getUnassignedKitPids(std::vector<int> *pids);
|
|
|
|
static int getKitPidsFromSystem(std::vector<int> *pids);
|
2023-05-02 08:29:40 -05:00
|
|
|
bool isDocSaved(const std::string&);
|
|
|
|
bool isDocReadOnly(const std::string&);
|
2023-06-06 02:12:26 -05:00
|
|
|
void setCurrentMigDoc(const std::string& docKey) { _currentMigDoc = docKey; }
|
|
|
|
std::string getCurrentMigDoc() { return _currentMigDoc; }
|
2023-06-07 06:29:39 -05:00
|
|
|
void setCurrentMigToken(const std::string& routeToken) { _currentMigToken = routeToken; }
|
|
|
|
std::string getCurrentMigToken() { return _currentMigToken; }
|
|
|
|
void sendMigrateMsgAfterSave(bool lastSaveSuccessful, const std::string& docKey);
|
2023-06-12 06:57:47 -05:00
|
|
|
std::string getWopiSrcMap();
|
2019-11-12 03:50:33 -06:00
|
|
|
|
2016-04-14 15:29:31 -05:00
|
|
|
private:
|
2020-05-04 03:11:00 -05:00
|
|
|
void doRemove(std::map<std::string, std::unique_ptr<Document>>::iterator &docIt);
|
|
|
|
|
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
|
|
|
|
2020-05-04 09:18:51 -05:00
|
|
|
uint64_t _sentBytesTotal = 0;
|
|
|
|
uint64_t _recvBytesTotal = 0;
|
2017-06-03 16:53:57 -05:00
|
|
|
|
2020-05-04 09:18:51 -05:00
|
|
|
uint64_t _segFaultCount = 0;
|
2021-03-26 11:57:08 -05:00
|
|
|
uint64_t _lostKitsTerminatedCount = 0;
|
2020-04-07 16:21:17 -05:00
|
|
|
|
2020-05-04 09:18:51 -05:00
|
|
|
pid_t _forKitPid = 0;
|
2019-11-12 03:50:33 -06:00
|
|
|
|
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;
|
2020-06-08 05:41:03 -05:00
|
|
|
|
|
|
|
DocProcSettings _defDocProcSettings;
|
2023-06-06 02:12:26 -05:00
|
|
|
|
|
|
|
std::string _currentMigDoc = std::string();
|
2023-06-07 06:29:39 -05:00
|
|
|
|
|
|
|
std::string _currentMigToken = std::string();
|
2016-02-24 10:58:05 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|