Some minor updates

This commit is contained in:
WolverinDEV 2021-04-27 15:46:19 +02:00
parent bc2c951dde
commit 0aad154c15
8 changed files with 94 additions and 96 deletions

@ -1 +1 @@
Subproject commit 64a573cbd0f890907d4416c87021092e8cce7367 Subproject commit dc0e49097c317f9c04fb9bfc0c8f61156c743ba8

View File

@ -654,10 +654,10 @@ std::shared_ptr<ts::server::license::InstanceLicenseInfo> InstanceHandler::gener
auto request = std::make_shared<license::InstanceLicenseInfo>(); auto request = std::make_shared<license::InstanceLicenseInfo>();
request->license = config::license; request->license = config::license;
request->metrics.servers_online = this->voiceServerManager->runningServers(); request->metrics.servers_online = this->voiceServerManager->runningServers();
auto report = this->voiceServerManager->clientReport(); auto report = this->voiceServerManager->instanceSlotUsageReport();
request->metrics.client_online = report.clients_ts; request->metrics.client_online = report.clients_teamspeak;
request->metrics.web_clients_online = report.clients_web; request->metrics.web_clients_online = report.clients_teaweb;
request->metrics.bots_online = report.bots; request->metrics.bots_online = report.music_bots;
request->metrics.queries_online = report.queries; request->metrics.queries_online = report.queries;
request->metrics.speech_total = this->properties()[property::SERVERINSTANCE_SPOKEN_TIME_TOTAL].as_or<uint64_t>(0); request->metrics.speech_total = this->properties()[property::SERVERINSTANCE_SPOKEN_TIME_TOTAL].as_or<uint64_t>(0);
request->metrics.speech_varianz = this->properties()[property::SERVERINSTANCE_SPOKEN_TIME_VARIANZ].as_or<uint64_t>(0); request->metrics.speech_varianz = this->properties()[property::SERVERINSTANCE_SPOKEN_TIME_VARIANZ].as_or<uint64_t>(0);

View File

@ -671,36 +671,37 @@ void VirtualServer::stop(const std::string& reason, bool disconnect_query) {
this->serverAdmin->server = nullptr; this->serverAdmin->server = nullptr;
} }
size_t VirtualServer::onlineClients() { ServerSlotUsageReport VirtualServer::onlineStats() {
size_t result{0}; ServerSlotUsageReport response{};
response.server_count = 1;
for(const auto& client : this->getClients()) { response.max_clients = this->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or<size_t>(0);
if(client->getType() == CLIENT_TEAMSPEAK || client->getType() == CLIENT_QUERY) { response.reserved_clients = this->properties()[property::VIRTUALSERVER_RESERVED_SLOTS].as_or<size_t>(0);
result++; {
std::lock_guard shared_lock{this->channel_tree_mutex};
response.online_channels = this->channelTree->channel_count();
} }
}
return result;
}
OnlineClientReport VirtualServer::onlineStats() {
OnlineClientReport response{};
for(const auto &client : this->getClients()) { for(const auto &client : this->getClients()) {
switch (client->getType()) { switch (client->getType()) {
case CLIENT_TEAMSPEAK: case CLIENT_TEAMSPEAK:
response.clients_teamspeak++;
break;
case CLIENT_TEASPEAK: case CLIENT_TEASPEAK:
response.clients_ts++; response.clients_teaspeak++;
break; break;
case CLIENT_WEB: case CLIENT_WEB:
response.clients_web++; response.clients_teaweb++;
break; break;
case CLIENT_QUERY: case CLIENT_QUERY:
response.queries++; response.queries++;
break; break;
case CLIENT_MUSIC: case CLIENT_MUSIC:
response.bots++; response.music_bots++;
break; break;
case CLIENT_INTERNAL: case CLIENT_INTERNAL:
case MAX: case MAX:
default: default:

View File

@ -105,11 +105,35 @@ namespace ts {
} }
}; };
struct OnlineClientReport { struct ServerSlotUsageReport {
uint16_t clients_ts = 0; size_t server_count{0};
uint16_t clients_web = 0;
uint16_t queries = 0; size_t max_clients{0};
uint16_t bots = 0; size_t reserved_clients{0};
size_t clients_teamspeak{0};
size_t clients_teaspeak{0};
size_t clients_teaweb{0};
size_t queries{0};
size_t music_bots{0};
size_t online_channels{0};
[[nodiscard]] inline size_t voice_clients() const {
return this->clients_teaspeak + this->clients_teamspeak + this->clients_teaweb;
}
inline ServerSlotUsageReport& operator+=(const ServerSlotUsageReport& other) {
this->max_clients += other.max_clients;
this->reserved_clients += other.reserved_clients;
this->clients_teamspeak += other.clients_teamspeak;
this->clients_teaspeak += other.clients_teaspeak;
this->clients_teaweb += other.clients_teaweb;
this->queries += other.queries;
this->music_bots += other.music_bots;
this->online_channels += other.online_channels;
return *this;
}
}; };
struct CalculateCache {}; struct CalculateCache {};
@ -143,9 +167,7 @@ namespace ts {
void preStop(const std::string&); void preStop(const std::string&);
void stop(const std::string& reason, bool /* disconnect query */); void stop(const std::string& reason, bool /* disconnect query */);
size_t onlineClients(); ServerSlotUsageReport onlineStats();
OnlineClientReport onlineStats();
size_t onlineChannels(){ return this->channelTree->channel_count(); }
std::shared_ptr<ConnectedClient> find_client_by_id(ClientId /* client id */); std::shared_ptr<ConnectedClient> find_client_by_id(ClientId /* client id */);
std::deque<std::shared_ptr<ConnectedClient>> findClientsByCldbId(ClientDbId cldbId); std::deque<std::shared_ptr<ConnectedClient>> findClientsByCldbId(ClientDbId cldbId);
std::deque<std::shared_ptr<ConnectedClient>> findClientsByUid(ClientUid uid); std::deque<std::shared_ptr<ConnectedClient>> findClientsByUid(ClientUid uid);

View File

@ -272,30 +272,14 @@ ts::ServerId VirtualServerManager::next_available_server_id(bool& success) {
return serverId; return serverId;
} }
ServerReport VirtualServerManager::report() { ServerSlotUsageReport VirtualServerManager::instanceSlotUsageReport() {
ServerReport result{}; ServerSlotUsageReport result{};
for(const auto& sr : this->serverInstances()) {
result.available++;
if(sr->running()) {
result.online++;
result.slots += sr->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or<size_t>(0);
result.onlineClients += sr->onlineClients();
result.onlineChannels += sr->onlineChannels();
}
}
return result;
}
OnlineClientReport VirtualServerManager::clientReport() {
OnlineClientReport result{};
for(const auto& server : this->serverInstances()) { for(const auto& server : this->serverInstances()) {
if(!server->running()) continue; if(!server->running()) {
auto sr = server->onlineStats(); continue;
result.bots += sr.bots; }
result.queries += sr.queries;
result.clients_web += sr.clients_web; result += server->onlineStats();
result.clients_ts += sr.clients_ts;
} }
return result; return result;
} }
@ -307,13 +291,6 @@ size_t VirtualServerManager::runningServers() {
return res; return res;
} }
size_t VirtualServerManager::usedSlots() {
size_t res = 0;
for(const auto& sr : this->serverInstances())
res += sr->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or<size_t>(0);
return res;
}
shared_ptr<VirtualServer> VirtualServerManager::create_server(std::string hosts, uint16_t port) { shared_ptr<VirtualServer> VirtualServerManager::create_server(std::string hosts, uint16_t port) {
bool sid_success = false; bool sid_success = false;

View File

@ -10,14 +10,6 @@
namespace ts::server { namespace ts::server {
class InstanceHandler; class InstanceHandler;
struct ServerReport {
size_t available;
size_t online;
size_t slots;
size_t onlineClients;
size_t onlineChannels;
};
class VirtualServerManager { class VirtualServerManager {
public: public:
enum State { enum State {
@ -55,10 +47,8 @@ namespace ts::server {
return instances; return instances;
} }
ServerReport report(); ServerSlotUsageReport instanceSlotUsageReport();
OnlineClientReport clientReport();
size_t runningServers(); size_t runningServers();
size_t usedSlots();
void executeAutostart(); void executeAutostart();
void shutdownAll(const std::string&); void shutdownAll(const std::string&);

View File

@ -846,15 +846,10 @@ void ConnectedClient::sendServerInit() {
command["client_myteamspeak_id"] = this->properties()[property::CLIENT_MYTEAMSPEAK_ID].value(); command["client_myteamspeak_id"] = this->properties()[property::CLIENT_MYTEAMSPEAK_ID].value();
command["client_integrations"] = this->properties()[property::CLIENT_INTEGRATIONS].value(); command["client_integrations"] = this->properties()[property::CLIENT_INTEGRATIONS].value();
if(ts::config::server::DefaultServerLicense == LicenseType::LICENSE_AUTOMATIC_INSTANCE) { switch(ts::config::server::DefaultServerLicense) {
if(serverInstance->getVoiceServerManager()->usedSlots() <= 32) { case LicenseType::LICENSE_AUTOMATIC_INSTANCE:
command["lt"] = LicenseType::LICENSE_NONE; /* We offered this option but it's nonsense... Just use automatic server. */
} else if(serverInstance->getVoiceServerManager()->usedSlots() <= 512) { case LicenseType::LICENSE_AUTOMATIC_SERVER:
command["lt"] = LicenseType::LICENSE_NPL;
} else {
command["lt"] = LicenseType::LICENSE_HOSTING;
}
} else if(ts::config::server::DefaultServerLicense == LicenseType::LICENSE_AUTOMATIC_SERVER){
if(this->server->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or<size_t>(0) <= 32) { if(this->server->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or<size_t>(0) <= 32) {
command["lt"] = LicenseType::LICENSE_NONE; command["lt"] = LicenseType::LICENSE_NONE;
} else if(this->server->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or<size_t>(0) <= 512) { } else if(this->server->properties()[property::VIRTUALSERVER_MAXCLIENTS].as_or<size_t>(0) <= 512) {
@ -862,10 +857,19 @@ void ConnectedClient::sendServerInit() {
} else { } else {
command["lt"] = LicenseType::LICENSE_HOSTING; command["lt"] = LicenseType::LICENSE_HOSTING;
} }
} else { break;
case LicenseType::LICENSE_NONE:
case LicenseType::LICENSE_HOSTING:
case LicenseType::LICENSE_OFFLINE:
case LicenseType::LICENSE_NPL:
case LicenseType::LICENSE_UNKNOWN:
case LicenseType::LICENSE_PLACEHOLDER:
default:
command["lt"] = ts::config::server::DefaultServerLicense; command["lt"] = ts::config::server::DefaultServerLicense;
break;
} }
command["pv"] = 6; //Protocol version command["pv"] = 6; /* protocol version */
command["acn"] = this->getDisplayName(); command["acn"] = this->getDisplayName();
command["aclid"] = this->getClientId(); command["aclid"] = this->getClientId();
this->sendCommand(command); this->sendCommand(command);

View File

@ -832,10 +832,14 @@ command_result QueryClient::handleCommandInstanceInfo(Command& cmd) {
ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_serverinstance_info_view, 1); ACTION_REQUIRES_INSTANCE_PERMISSION(permission::b_serverinstance_info_view, 1);
Command res(""); Command res("");
for(const auto& e : serverInstance->properties()->list_properties(property::FLAG_INSTANCE_VARIABLE, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) for(const auto& e : serverInstance->properties()->list_properties(property::FLAG_INSTANCE_VARIABLE, this->getType() == CLIENT_TEAMSPEAK ? property::FLAG_NEW : (uint16_t) 0)) {
res[e.type().name] = e.value(); res[e.type().name] = e.value();
if(!this->properties()[property::CLIENT_LOGIN_NAME].value().empty()) }
if(!this->properties()[property::CLIENT_LOGIN_NAME].value().empty()) {
res["serverinstance_teaspeak"] = true; res["serverinstance_teaspeak"] = true;
}
res["serverinstance_serverquery_max_connections_per_ip"] = res["serverinstance_query_max_connections_per_ip"].as<std::string>(); res["serverinstance_serverquery_max_connections_per_ip"] = res["serverinstance_query_max_connections_per_ip"].as<std::string>();
this->sendCommand(res); this->sendCommand(res);
@ -875,11 +879,11 @@ command_result QueryClient::handleCommandHostInfo(Command &) {
res["instance_uptime"] = duration_cast<seconds>(system_clock::now() - serverInstance->getStartTimestamp()).count(); res["instance_uptime"] = duration_cast<seconds>(system_clock::now() - serverInstance->getStartTimestamp()).count();
res["host_timestamp_utc"] = duration_cast<seconds>(system_clock::now().time_since_epoch()).count(); res["host_timestamp_utc"] = duration_cast<seconds>(system_clock::now().time_since_epoch()).count();
auto vsReport = serverInstance->getVoiceServerManager()->report(); auto instance_report = serverInstance->getVoiceServerManager()->instanceSlotUsageReport();
res["virtualservers_running_total"] = vsReport.online; res["virtualservers_running_total"] = instance_report.server_count;
res["virtualservers_total_maxclients"] = vsReport.slots; res["virtualservers_total_maxclients"] = instance_report.max_clients;
res["virtualservers_total_clients_online"] = vsReport.onlineClients; res["virtualservers_total_clients_online"] = instance_report.voice_clients();
res["virtualservers_total_channels_online"] = vsReport.onlineChannels; res["virtualservers_total_channels_online"] = instance_report.online_channels;
auto total_stats = serverInstance->getStatistics()->total_stats(); auto total_stats = serverInstance->getStatistics()->total_stats();