Counting empty instances as well
This commit is contained in:
parent
67becd9496
commit
12d86cbfea
@ -408,6 +408,7 @@ std::shared_ptr<DatabaseHandler::UserHistory> DatabaseHandler::list_statistics_u
|
||||
continue; /* last server request is too old to be counted */
|
||||
|
||||
info->instance_online++;
|
||||
info->instance_empty += second.web_clients_online == 0 && second.clients_online == 0;
|
||||
info->queries_online += second.queries_online;
|
||||
info->bots_online += second.bots_online;
|
||||
info->web_clients_online += second.web_clients_online;
|
||||
@ -441,6 +442,7 @@ std::shared_ptr<DatabaseHandler::UserHistory> DatabaseHandler::list_statistics_u
|
||||
continue; /* last server request is too old to be counted */
|
||||
|
||||
info->instance_online++;
|
||||
info->instance_empty += second.web_clients_online == 0 && second.clients_online == 0;
|
||||
info->queries_online += second.queries_online;
|
||||
info->bots_online += second.bots_online;
|
||||
info->web_clients_online += second.web_clients_online;
|
||||
|
@ -70,7 +70,8 @@ namespace license::server::database {
|
||||
};
|
||||
|
||||
struct GlobalUserStatistics : public UserStatistics {
|
||||
uint64_t instance_online = 0;
|
||||
uint64_t instance_online{0};
|
||||
uint64_t instance_empty{0};
|
||||
};
|
||||
|
||||
struct DatabaseUserStatistics : public UserStatistics {
|
||||
|
@ -148,6 +148,7 @@ std::shared_ptr<GeneralStatistics> StatisticManager::general_statistics() {
|
||||
stats->bots += entry->bots;
|
||||
stats->clients += entry->clients;
|
||||
stats->servers += entry->servers;
|
||||
stats->empty_instances += entry->clients == 0;
|
||||
stats->instances++;
|
||||
}
|
||||
stats->age = system_clock::now();
|
||||
|
@ -5,70 +5,69 @@
|
||||
#include <chrono>
|
||||
#include "DatabaseHandler.h"
|
||||
|
||||
namespace license {
|
||||
namespace stats {
|
||||
struct GeneralStatistics {
|
||||
std::chrono::system_clock::time_point age;
|
||||
namespace license::stats {
|
||||
struct GeneralStatistics {
|
||||
std::chrono::system_clock::time_point age;
|
||||
|
||||
uint64_t instances = 0;
|
||||
uint64_t servers = 0;
|
||||
uint64_t clients = 0;
|
||||
uint64_t bots = 0;
|
||||
};
|
||||
uint64_t empty_instances{0};
|
||||
uint64_t instances{0};
|
||||
uint64_t servers{0};
|
||||
uint64_t clients{0};
|
||||
uint64_t bots{0};
|
||||
};
|
||||
|
||||
struct HistoryStatistics {
|
||||
enum HistoryPeriod {
|
||||
DAY,
|
||||
WEEK,
|
||||
MONTH,
|
||||
HALF_YEAR,
|
||||
YEAR
|
||||
};
|
||||
enum HistoryOffset {
|
||||
NOW,
|
||||
ONE_BEFORE,
|
||||
SEVEN_BEFORE,
|
||||
TWELVE_BEFORE
|
||||
};
|
||||
enum HistoryType {
|
||||
LAST_DAY,
|
||||
DAY_YESTERDAY,
|
||||
DAY_7DAYS_AGO,
|
||||
LAST_WEEK,
|
||||
LAST_MONTH,
|
||||
LAST_HALF_YEAR
|
||||
};
|
||||
static std::chrono::system_clock::time_point align_type(HistoryType type, const std::chrono::system_clock::time_point&);
|
||||
static std::chrono::milliseconds time_period(HistoryType type);
|
||||
static std::chrono::milliseconds cache_timeout(HistoryType type);
|
||||
static std::chrono::milliseconds type_duration(HistoryType type);
|
||||
struct HistoryStatistics {
|
||||
enum HistoryPeriod {
|
||||
DAY,
|
||||
WEEK,
|
||||
MONTH,
|
||||
HALF_YEAR,
|
||||
YEAR
|
||||
};
|
||||
enum HistoryOffset {
|
||||
NOW,
|
||||
ONE_BEFORE,
|
||||
SEVEN_BEFORE,
|
||||
TWELVE_BEFORE
|
||||
};
|
||||
enum HistoryType {
|
||||
LAST_DAY,
|
||||
DAY_YESTERDAY,
|
||||
DAY_7DAYS_AGO,
|
||||
LAST_WEEK,
|
||||
LAST_MONTH,
|
||||
LAST_HALF_YEAR
|
||||
};
|
||||
static std::chrono::system_clock::time_point align_type(HistoryType type, const std::chrono::system_clock::time_point&);
|
||||
static std::chrono::milliseconds time_period(HistoryType type);
|
||||
static std::chrono::milliseconds cache_timeout(HistoryType type);
|
||||
static std::chrono::milliseconds type_duration(HistoryType type);
|
||||
|
||||
std::chrono::system_clock::time_point evaluated;
|
||||
std::chrono::system_clock::time_point begin;
|
||||
std::chrono::system_clock::time_point end;
|
||||
std::chrono::milliseconds period;
|
||||
HistoryType type;
|
||||
std::chrono::system_clock::time_point evaluated;
|
||||
std::chrono::system_clock::time_point begin;
|
||||
std::chrono::system_clock::time_point end;
|
||||
std::chrono::milliseconds period;
|
||||
HistoryType type;
|
||||
|
||||
std::shared_ptr<server::database::DatabaseHandler::UserHistory> statistics;
|
||||
};
|
||||
std::shared_ptr<server::database::DatabaseHandler::UserHistory> statistics;
|
||||
};
|
||||
|
||||
class StatisticManager {
|
||||
public:
|
||||
explicit StatisticManager(std::shared_ptr<server::database::DatabaseHandler> /* manager */);
|
||||
virtual ~StatisticManager();
|
||||
class StatisticManager {
|
||||
public:
|
||||
explicit StatisticManager(std::shared_ptr<server::database::DatabaseHandler> /* manager */);
|
||||
virtual ~StatisticManager();
|
||||
|
||||
void reset_cache_general();
|
||||
std::shared_ptr<GeneralStatistics> general_statistics();
|
||||
std::shared_ptr<HistoryStatistics> history(HistoryStatistics::HistoryType);
|
||||
private:
|
||||
std::shared_ptr<server::database::DatabaseHandler> license_manager;
|
||||
void reset_cache_general();
|
||||
std::shared_ptr<GeneralStatistics> general_statistics();
|
||||
std::shared_ptr<HistoryStatistics> history(HistoryStatistics::HistoryType);
|
||||
private:
|
||||
std::shared_ptr<server::database::DatabaseHandler> license_manager;
|
||||
|
||||
std::recursive_mutex _general_statistics_lock;
|
||||
std::recursive_mutex _general_statistics_generate_lock;
|
||||
std::shared_ptr<GeneralStatistics> _general_statistics;
|
||||
std::recursive_mutex _general_statistics_lock;
|
||||
std::recursive_mutex _general_statistics_generate_lock;
|
||||
std::shared_ptr<GeneralStatistics> _general_statistics;
|
||||
|
||||
std::map<HistoryStatistics::HistoryType, std::recursive_mutex> _history_locks;
|
||||
std::map<HistoryStatistics::HistoryType, std::shared_ptr<HistoryStatistics>> _history;
|
||||
};
|
||||
}
|
||||
std::map<HistoryStatistics::HistoryType, std::recursive_mutex> _history_locks;
|
||||
std::map<HistoryStatistics::HistoryType, std::shared_ptr<HistoryStatistics>> _history;
|
||||
};
|
||||
}
|
@ -520,6 +520,7 @@ bool WebStatistics::handle_message(const std::shared_ptr<license::web::WebStatis
|
||||
auto& history_data = response["history"]["data"];
|
||||
for(index = 0; index < data->record_count; index++) {
|
||||
auto& indexed_data = history_data[index];
|
||||
indexed_data["instances_empty"] = data->history[index].instance_empty;
|
||||
indexed_data["instances"] = data->history[index].instance_online;
|
||||
indexed_data["servers"] = data->history[index].servers_online;
|
||||
indexed_data["clients"] = data->history[index].clients_online;
|
||||
@ -560,6 +561,7 @@ bool WebStatistics::handle_request(const std::shared_ptr<license::web::WebStatis
|
||||
Json::Value json;
|
||||
json["type"] = "response";
|
||||
auto stats = this->statistics_manager->general_statistics();
|
||||
json["statistics"]["instances_empty"] = to_string(stats->empty_instances);
|
||||
json["statistics"]["instances"] = to_string(stats->instances);
|
||||
json["statistics"]["servers"] = to_string(stats->servers);
|
||||
json["statistics"]["clients"] = to_string(stats->clients);
|
||||
|
Loading…
Reference in New Issue
Block a user