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