|
|
|
@ -7,6 +7,7 @@
|
|
|
|
#include "telegram-bot-api/Stats.h"
|
|
|
|
#include "telegram-bot-api/Stats.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
#include "td/utils/common.h"
|
|
|
|
|
|
|
|
#include "td/utils/logging.h"
|
|
|
|
#include "td/utils/port/thread.h"
|
|
|
|
#include "td/utils/port/thread.h"
|
|
|
|
#include "td/utils/SliceBuilder.h"
|
|
|
|
#include "td/utils/SliceBuilder.h"
|
|
|
|
#include "td/utils/StringBuilder.h"
|
|
|
|
#include "td/utils/StringBuilder.h"
|
|
|
|
@ -19,17 +20,24 @@ ServerCpuStat::ServerCpuStat() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ServerCpuStat::add_event(const td::CpuStat &cpu_stat, double now) {
|
|
|
|
void ServerCpuStat::update(double now) {
|
|
|
|
std::lock_guard<std::mutex> guard(mutex_);
|
|
|
|
auto r_cpu_stat = td::cpu_stat();
|
|
|
|
for (auto &stat : stat_) {
|
|
|
|
if (r_cpu_stat.is_error()) {
|
|
|
|
stat.add_event(cpu_stat, now);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto &cpu_stat = instance();
|
|
|
|
|
|
|
|
std::lock_guard<std::mutex> guard(cpu_stat.mutex_);
|
|
|
|
|
|
|
|
for (auto &stat : cpu_stat.stat_) {
|
|
|
|
|
|
|
|
stat.add_event(r_cpu_stat.ok(), now);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG(WARNING) << "CPU usage: " << cpu_stat.stat_[1].get_stat(now).as_vector()[0].value_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
td::string ServerCpuStat::get_description() const {
|
|
|
|
td::string ServerCpuStat::get_description() {
|
|
|
|
td::string res = "DURATION";
|
|
|
|
td::string res = "DURATION";
|
|
|
|
for (auto &descr : DESCR) {
|
|
|
|
for (auto &descr : DESCR) {
|
|
|
|
res += "\t";
|
|
|
|
res += '\t';
|
|
|
|
res += descr;
|
|
|
|
res += descr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
@ -37,7 +45,7 @@ td::string ServerCpuStat::get_description() const {
|
|
|
|
|
|
|
|
|
|
|
|
static td::string to_percentage(td::uint64 ticks, td::uint64 total_ticks) {
|
|
|
|
static td::string to_percentage(td::uint64 ticks, td::uint64 total_ticks) {
|
|
|
|
static double multiplier = 100.0 * (td::thread::hardware_concurrency() ? td::thread::hardware_concurrency() : 1);
|
|
|
|
static double multiplier = 100.0 * (td::thread::hardware_concurrency() ? td::thread::hardware_concurrency() : 1);
|
|
|
|
return PSTRING() << (static_cast<double>(ticks) / static_cast<double>(total_ticks) * multiplier) << "%";
|
|
|
|
return PSTRING() << (static_cast<double>(ticks) / static_cast<double>(total_ticks) * multiplier) << '%';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
td::vector<StatItem> CpuStat::as_vector() const {
|
|
|
|
td::vector<StatItem> CpuStat::as_vector() const {
|
|
|
|
@ -140,7 +148,7 @@ td::vector<StatItem> BotStatActor::as_vector(double now) {
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
td::string BotStatActor::get_description() const {
|
|
|
|
td::string BotStatActor::get_description() {
|
|
|
|
td::string res = "DURATION";
|
|
|
|
td::string res = "DURATION";
|
|
|
|
for (auto &descr : DESCR) {
|
|
|
|
for (auto &descr : DESCR) {
|
|
|
|
res += "\t";
|
|
|
|
res += "\t";
|
|
|
|
|