Fix connection issues and add enhancement to the Dashboard (#130)
* Fix connection errors when doing DNS lookup * Fix connection handling when an error occurs * Add remote logging feature * Add algo variant to dashboard
This commit is contained in:
parent
872fce72b5
commit
b379f21cb3
20 changed files with 377 additions and 62 deletions
|
@ -28,6 +28,8 @@
|
|||
#include <3rdparty/rapidjson/stringbuffer.h>
|
||||
#include <3rdparty/rapidjson/prettywriter.h>
|
||||
#include <version.h>
|
||||
#include <log/RemoteLog.h>
|
||||
#include <api/NetworkState.h>
|
||||
|
||||
#include "CCClient.h"
|
||||
#include "App.h"
|
||||
|
@ -133,6 +135,7 @@ void CCClient::updateNetworkState(const NetworkState& network)
|
|||
m_self->m_clientStatus.setSharesTotal(network.accepted + network.rejected);
|
||||
m_self->m_clientStatus.setHashesTotal(network.total);
|
||||
m_self->m_clientStatus.setAvgTime(network.avgTime());
|
||||
m_self->m_clientStatus.setCurrentPowVariantName(getPowVariantName(network.powVariant));
|
||||
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
}
|
||||
|
@ -140,8 +143,6 @@ void CCClient::updateNetworkState(const NetworkState& network)
|
|||
|
||||
void CCClient::publishClientStatusReport()
|
||||
{
|
||||
refreshUptime();
|
||||
|
||||
std::string requestUrl = "/client/setClientStatus?clientId=" + m_self->m_clientStatus.getClientId();
|
||||
std::string requestBuffer = m_self->m_clientStatus.toJsonString();
|
||||
|
||||
|
@ -302,23 +303,33 @@ void CCClient::refreshUptime()
|
|||
m_self->m_clientStatus.setUptime(static_cast<uint64_t>(uptime.count()));
|
||||
}
|
||||
|
||||
void CCClient::refreshLog()
|
||||
{
|
||||
m_self->m_clientStatus.setLog(RemoteLog::getRows());
|
||||
}
|
||||
|
||||
void CCClient::onThreadStarted(void* handle)
|
||||
{
|
||||
uv_loop_init(&m_self->m_client_loop);
|
||||
if (m_self) {
|
||||
uv_loop_init(&m_self->m_client_loop);
|
||||
|
||||
uv_timer_init(&m_self->m_client_loop, &m_self->m_timer);
|
||||
uv_timer_start(&m_self->m_timer, CCClient::onReport,
|
||||
static_cast<uint64_t>(m_self->m_options->ccUpdateInterval() * 1000),
|
||||
static_cast<uint64_t>(m_self->m_options->ccUpdateInterval() * 1000));
|
||||
uv_timer_init(&m_self->m_client_loop, &m_self->m_timer);
|
||||
uv_timer_start(&m_self->m_timer, CCClient::onReport,
|
||||
static_cast<uint64_t>(m_self->m_options->ccUpdateInterval() * 1000),
|
||||
static_cast<uint64_t>(m_self->m_options->ccUpdateInterval() * 1000));
|
||||
|
||||
publishConfig();
|
||||
m_self->publishConfig();
|
||||
|
||||
uv_run(&m_self->m_client_loop, UV_RUN_DEFAULT);
|
||||
uv_run(&m_self->m_client_loop, UV_RUN_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
void CCClient::onReport(uv_timer_t* handle)
|
||||
{
|
||||
if (m_self) {
|
||||
m_self->refreshUptime();
|
||||
m_self->refreshLog();
|
||||
|
||||
m_self->publishClientStatusReport();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,13 +48,15 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
static void publishClientStatusReport();
|
||||
static void updateConfig();
|
||||
static void publishConfig();
|
||||
static std::shared_ptr<httplib::Response> performRequest(const std::string& requestUrl,
|
||||
void publishClientStatusReport();
|
||||
void updateConfig();
|
||||
void publishConfig();
|
||||
void refreshUptime();
|
||||
void refreshLog();
|
||||
|
||||
std::shared_ptr<httplib::Response> performRequest(const std::string& requestUrl,
|
||||
const std::string& requestBuffer,
|
||||
const std::string& operation);
|
||||
|
||||
static void onThreadStarted(void *handle);
|
||||
static void onReport(uv_timer_t *handle);
|
||||
|
||||
|
@ -73,8 +75,6 @@ private:
|
|||
uv_timer_t m_timer;
|
||||
uv_loop_t m_client_loop;
|
||||
uv_thread_t m_thread;
|
||||
|
||||
static void refreshUptime();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -98,6 +98,16 @@ std::string ClientStatus::getCurrentAlgoName() const
|
|||
return m_currentAlgoName;
|
||||
}
|
||||
|
||||
void ClientStatus::setCurrentPowVariantName(const std::string& powVariantName)
|
||||
{
|
||||
m_currentPowVariantName = powVariantName;
|
||||
}
|
||||
|
||||
std::string ClientStatus::getCurrentPowVariantName() const
|
||||
{
|
||||
return m_currentPowVariantName;
|
||||
}
|
||||
|
||||
std::string ClientStatus::getCpuBrand() const
|
||||
{
|
||||
return m_cpuBrand;
|
||||
|
@ -128,6 +138,16 @@ void ClientStatus::setVersion(const std::string& version)
|
|||
m_version = version;
|
||||
}
|
||||
|
||||
std::string ClientStatus::getLog() const
|
||||
{
|
||||
return m_log;
|
||||
}
|
||||
|
||||
void ClientStatus::setLog(const std::string& log)
|
||||
{
|
||||
m_log = log;
|
||||
}
|
||||
|
||||
bool ClientStatus::hasHugepages() const
|
||||
{
|
||||
return m_hasHugepages;
|
||||
|
@ -356,6 +376,10 @@ bool ClientStatus::parseFromJson(const rapidjson::Document& document)
|
|||
m_currentAlgoName = clientStatus["current_algo_name"].GetString();
|
||||
}
|
||||
|
||||
if (clientStatus.HasMember("current_pow_variant_name")) {
|
||||
m_currentPowVariantName = clientStatus["current_pow_variant_name"].GetString();
|
||||
}
|
||||
|
||||
if (clientStatus.HasMember("cpu_brand")) {
|
||||
m_cpuBrand = clientStatus["cpu_brand"].GetString();
|
||||
}
|
||||
|
@ -368,6 +392,10 @@ bool ClientStatus::parseFromJson(const rapidjson::Document& document)
|
|||
m_version = clientStatus["version"].GetString();
|
||||
}
|
||||
|
||||
if (clientStatus.HasMember("log")) {
|
||||
m_log = clientStatus["log"].GetString();
|
||||
}
|
||||
|
||||
if (clientStatus.HasMember("hugepages_available")) {
|
||||
m_hasHugepages = clientStatus["hugepages_available"].GetBool();
|
||||
}
|
||||
|
@ -468,6 +496,7 @@ rapidjson::Value ClientStatus::toJson(rapidjson::MemoryPoolAllocator<rapidjson::
|
|||
clientStatus.AddMember("client_id", rapidjson::StringRef(m_clientId.c_str()), allocator);
|
||||
clientStatus.AddMember("current_pool", rapidjson::StringRef(m_currentPool.c_str()), allocator);
|
||||
clientStatus.AddMember("current_algo_name", rapidjson::StringRef(m_currentAlgoName.c_str()), allocator);
|
||||
clientStatus.AddMember("current_pow_variant_name", rapidjson::StringRef(m_currentPowVariantName.c_str()), allocator);
|
||||
clientStatus.AddMember("cpu_brand", rapidjson::StringRef(m_cpuBrand.c_str()), allocator);
|
||||
clientStatus.AddMember("external_ip", rapidjson::StringRef(m_externalIp.c_str()), allocator);
|
||||
clientStatus.AddMember("version", rapidjson::StringRef(m_version.c_str()), allocator);
|
||||
|
@ -500,6 +529,9 @@ rapidjson::Value ClientStatus::toJson(rapidjson::MemoryPoolAllocator<rapidjson::
|
|||
|
||||
clientStatus.AddMember("last_status_update", static_cast<uint64_t >(m_lastStatusUpdate), allocator);
|
||||
|
||||
clientStatus.AddMember("log", rapidjson::StringRef(m_log.c_str()), allocator);
|
||||
|
||||
|
||||
return clientStatus;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,6 +69,9 @@ public:
|
|||
std::string getCurrentAlgoName() const;
|
||||
void setCurrentAlgoName(const std::string& algoName);
|
||||
|
||||
std::string getCurrentPowVariantName() const;
|
||||
void setCurrentPowVariantName(const std::string& powVariantName);
|
||||
|
||||
std::string getCpuBrand() const;
|
||||
void setCpuBrand(const std::string& cpuBrand);
|
||||
|
||||
|
@ -78,6 +81,9 @@ public:
|
|||
std::string getVersion() const;
|
||||
void setVersion(const std::string& version);
|
||||
|
||||
std::string getLog() const;
|
||||
void setLog(const std::string& version);
|
||||
|
||||
bool hasHugepages() const;
|
||||
void setHugepages(bool hasHugepages);
|
||||
|
||||
|
@ -157,9 +163,11 @@ private:
|
|||
std::string m_clientId;
|
||||
std::string m_currentPool;
|
||||
std::string m_currentAlgoName;
|
||||
std::string m_currentPowVariantName;
|
||||
std::string m_cpuBrand;
|
||||
std::string m_externalIp;
|
||||
std::string m_version;
|
||||
std::string m_log;
|
||||
|
||||
bool m_hasHugepages;
|
||||
bool m_isHugepagesEnabled;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue