обновил сбор статистики, теперь он выполняется отдельно от загрузки состояния и может работать на FULL RATE. К тому же, статистика доступна только на SCPC модеме
This commit is contained in:
parent
a204c4002b
commit
70a2257255
@ -480,7 +480,7 @@ public:
|
|||||||
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
rep.headers.push_back({.name = "Content-Type", .value = toString(mime_types::json)});
|
||||||
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
rep.content.insert(rep.content.end(), result.c_str(), result.c_str() + result.size());
|
||||||
}));
|
}));
|
||||||
|
#ifdef MODEM_IS_SCPC
|
||||||
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/dev/settings", this->auth, http::auth::User::DEVELOPER, [this](const auto& req, auto& rep) {
|
s.resources.emplace_back(std::make_unique<http::auth::AuthRequiredResource>("/dev/settings", this->auth, http::auth::User::DEVELOPER, [this](const auto& req, auto& rep) {
|
||||||
std::string result;
|
std::string result;
|
||||||
if (req.method == "GET") {
|
if (req.method == "GET") {
|
||||||
@ -519,6 +519,7 @@ public:
|
|||||||
rep.content.clear();
|
rep.content.clear();
|
||||||
http::resource::loadFile("/tmp/weblog-statistics.csv", rep.content);
|
http::resource::loadFile("/tmp/weblog-statistics.csv", rep.content);
|
||||||
}));
|
}));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
~ServerResources() = default;
|
~ServerResources() = default;
|
||||||
|
@ -136,6 +136,7 @@ std::string makeTimepointFromMillis(int64_t unix_time_ms) {
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef MODEM_IS_SCPC
|
||||||
class api_driver::StatisticsLogger {
|
class api_driver::StatisticsLogger {
|
||||||
public:
|
public:
|
||||||
StatisticsLogger(): timeStart(TIME_NOW()) {}
|
StatisticsLogger(): timeStart(TIME_NOW()) {}
|
||||||
@ -238,6 +239,7 @@ private:
|
|||||||
std::fstream logFile{};
|
std::fstream logFile{};
|
||||||
std::shared_mutex mutex;
|
std::shared_mutex mutex;
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Этот демон нужен для того, чтобы получать статистику из API, а так же корректно сохранять настройки
|
* Этот демон нужен для того, чтобы получать статистику из API, а так же корректно сохранять настройки
|
||||||
@ -266,9 +268,8 @@ private:
|
|||||||
std::string tmpDevState;
|
std::string tmpDevState;
|
||||||
logCpApiError("api_driver::TerminalApiDaemon::updateState()->CP_GetDmaDebug(status_init)", CP_GetDmaDebug(sid, "status_init", &tmpDevState));
|
logCpApiError("api_driver::TerminalApiDaemon::updateState()->CP_GetDmaDebug(status_init)", CP_GetDmaDebug(sid, "status_init", &tmpDevState));
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODEM_IS_SCPC
|
|
||||||
logCpApiError("api_driver::TerminalApiDaemon::updateState()->CP_GetDebugMetrics()", CP_GetDebugMetrics(sid, debugMetrics));
|
|
||||||
|
|
||||||
|
#ifdef MODEM_IS_SCPC
|
||||||
bool isCinC = getIsCinC();
|
bool isCinC = getIsCinC();
|
||||||
if (isCinC) {
|
if (isCinC) {
|
||||||
logCpApiError("api_driver::TerminalApiDaemon::updateState()->CP_GetCinCState()", CP_GetCinCState(sid, cinc));
|
logCpApiError("api_driver::TerminalApiDaemon::updateState()->CP_GetCinCState()", CP_GetCinCState(sid, cinc));
|
||||||
@ -443,6 +444,7 @@ private:
|
|||||||
std::function<void()> callback;
|
std::function<void()> callback;
|
||||||
|
|
||||||
bool checkNeedUpdate(int64_t now) const {
|
bool checkNeedUpdate(int64_t now) const {
|
||||||
|
if (periodMs < 0) return false;
|
||||||
// тут нет смысла спать меньше чем на 20мс, поэтому можно разрешить чтение на некоторое время раньше
|
// тут нет смысла спать меньше чем на 20мс, поэтому можно разрешить чтение на некоторое время раньше
|
||||||
return now - lastUpdate >= (periodMs - 20);
|
return now - lastUpdate >= (periodMs - 20);
|
||||||
}
|
}
|
||||||
@ -457,6 +459,22 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
IntervalUpdate_t updaters[] = {
|
IntervalUpdate_t updaters[] = {
|
||||||
|
#ifdef MODEM_IS_SCPC
|
||||||
|
// обновление логов
|
||||||
|
{.lastUpdate = 0, .periodMs = -1, .callback = [this]() {
|
||||||
|
try {
|
||||||
|
{
|
||||||
|
std::lock_guard _alock(this->cpApiMutex);
|
||||||
|
std::lock_guard _slock(this->stateMutex);
|
||||||
|
logCpApiError("api_driver::TerminalApiDaemon->statsLogs.putItem()->CP_GetDebugMetrics()", CP_GetDebugMetrics(sid, debugMetrics));
|
||||||
|
}
|
||||||
|
this->statsLogs.putItem(debugMetrics);
|
||||||
|
BOOST_LOG_TRIVIAL(debug) << "api_driver::TerminalApiDaemon->statsLogs.putItem(): success write statistics state to log!";
|
||||||
|
} catch (std::exception& e) {
|
||||||
|
BOOST_LOG_TRIVIAL(error) << "api_driver::TerminalApiDaemon->statsLogs.putItem() failed to log: " << e.what();
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
#endif
|
||||||
// обновление статистики
|
// обновление статистики
|
||||||
{.lastUpdate = 0, .periodMs = CACHE_STATISTICS_UPDATE_MS, .callback = [this]() {
|
{.lastUpdate = 0, .periodMs = CACHE_STATISTICS_UPDATE_MS, .callback = [this]() {
|
||||||
try {
|
try {
|
||||||
@ -465,22 +483,6 @@ private:
|
|||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
BOOST_LOG_TRIVIAL(error) << "api_driver::TerminalApiDaemon::updateState(): " << e.what();
|
BOOST_LOG_TRIVIAL(error) << "api_driver::TerminalApiDaemon::updateState(): " << e.what();
|
||||||
}
|
}
|
||||||
|
|
||||||
// запись статистики в лог, если нужно
|
|
||||||
try {
|
|
||||||
static int uc = 0;
|
|
||||||
if (uc == 0) {
|
|
||||||
this->statsLogs.putItem(debugMetrics);
|
|
||||||
|
|
||||||
BOOST_LOG_TRIVIAL(debug) << "api_driver::TerminalApiDaemon::updateState(): success write statistics state to log!";
|
|
||||||
}
|
|
||||||
uc++;
|
|
||||||
if (uc * CACHE_STATISTICS_UPDATE_MS >= this->statsLogs.logPeriodMs) {
|
|
||||||
uc = 0;
|
|
||||||
}
|
|
||||||
} catch (std::exception& e) {
|
|
||||||
BOOST_LOG_TRIVIAL(error) << "api_driver::TerminalApiDaemon::updateState() failed to log: " << e.what();
|
|
||||||
}
|
|
||||||
}},
|
}},
|
||||||
// обновление состояния устройства (обновления, температура)
|
// обновление состояния устройства (обновления, температура)
|
||||||
{.lastUpdate = 0, .periodMs = CACHE_DEV_STATE_UPDATE_MS, .callback = [this]() {
|
{.lastUpdate = 0, .periodMs = CACHE_DEV_STATE_UPDATE_MS, .callback = [this]() {
|
||||||
@ -526,7 +528,9 @@ private:
|
|||||||
CP_Logout(this->sid);
|
CP_Logout(this->sid);
|
||||||
this->connectToApi();
|
this->connectToApi();
|
||||||
}
|
}
|
||||||
|
#ifdef MODEM_IS_SCPC
|
||||||
|
updaters[0].periodMs = this->statsLogs.logEn ? this->statsLogs.logPeriodMs.load() : -1;
|
||||||
|
#endif
|
||||||
int64_t sleepTime = 60000; // минута по-умолчанию
|
int64_t sleepTime = 60000; // минута по-умолчанию
|
||||||
auto now = TIME_NOW();
|
auto now = TIME_NOW();
|
||||||
for (auto& u: updaters) {
|
for (auto& u: updaters) {
|
||||||
@ -555,8 +559,8 @@ private:
|
|||||||
demodulator_state demodState{};
|
demodulator_state demodState{};
|
||||||
device_state devState{};
|
device_state devState{};
|
||||||
std::string deviceInitState;
|
std::string deviceInitState;
|
||||||
debug_metrics debugMetrics{};
|
|
||||||
#ifdef MODEM_IS_SCPC
|
#ifdef MODEM_IS_SCPC
|
||||||
|
debug_metrics debugMetrics{};
|
||||||
CinC_state cincState{};
|
CinC_state cincState{};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -580,7 +584,9 @@ private:
|
|||||||
TerminalFirmwareVersion firmware;
|
TerminalFirmwareVersion firmware;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
#ifdef MODEM_IS_SCPC
|
||||||
StatisticsLogger statsLogs;
|
StatisticsLogger statsLogs;
|
||||||
|
#endif
|
||||||
|
|
||||||
std::mutex cpApiMutex;
|
std::mutex cpApiMutex;
|
||||||
TSID sid;
|
TSID sid;
|
||||||
@ -1371,7 +1377,7 @@ void api_driver::ApiDriver::executeInApi(const std::function<void(TSID sid)>& ca
|
|||||||
BOOST_LOG_TRIVIAL(error) << "ApiDriver::executeInApi(): failed to exec with error: " << e.what();
|
BOOST_LOG_TRIVIAL(error) << "ApiDriver::executeInApi(): failed to exec with error: " << e.what();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#ifdef MODEM_IS_SCPC
|
||||||
std::string api_driver::ApiDriver::getLoggingStatisticsSettings() {
|
std::string api_driver::ApiDriver::getLoggingStatisticsSettings() {
|
||||||
return this->daemon->statsLogs.getSettings();
|
return this->daemon->statsLogs.getSettings();
|
||||||
}
|
}
|
||||||
@ -1379,6 +1385,7 @@ std::string api_driver::ApiDriver::getLoggingStatisticsSettings() {
|
|||||||
void api_driver::ApiDriver::setLoggingStatisticsSettings(boost::property_tree::ptree &pt) {
|
void api_driver::ApiDriver::setLoggingStatisticsSettings(boost::property_tree::ptree &pt) {
|
||||||
this->daemon->statsLogs.setSettings(pt);
|
this->daemon->statsLogs.setSettings(pt);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
std::string api_driver::ApiDriver::loadSysInfo() {
|
std::string api_driver::ApiDriver::loadSysInfo() {
|
||||||
std::stringstream result;
|
std::stringstream result;
|
||||||
|
@ -72,6 +72,7 @@ namespace api_driver {
|
|||||||
|
|
||||||
void executeInApi(const std::function<void(TSID sid)> &callback);
|
void executeInApi(const std::function<void(TSID sid)> &callback);
|
||||||
|
|
||||||
|
#ifdef MODEM_IS_SCPC
|
||||||
std::string getLoggingStatisticsSettings();
|
std::string getLoggingStatisticsSettings();
|
||||||
void setLoggingStatisticsSettings(boost::property_tree::ptree &pt);
|
void setLoggingStatisticsSettings(boost::property_tree::ptree &pt);
|
||||||
|
|
||||||
@ -84,6 +85,7 @@ namespace api_driver {
|
|||||||
* @param maxItems
|
* @param maxItems
|
||||||
*/
|
*/
|
||||||
void readLoggingStatistics(std::vector<uint8_t>& out, int timeStart = -1, int timeEnd = -1, bool ordering = false, int maxItems = -1);
|
void readLoggingStatistics(std::vector<uint8_t>& out, int timeStart = -1, int timeEnd = -1, bool ordering = false, int maxItems = -1);
|
||||||
|
#endif
|
||||||
|
|
||||||
static std::string loadSysInfo();
|
static std::string loadSysInfo();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user