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:
Ben Gräf 2018-06-12 09:15:04 +02:00 committed by GitHub
parent 872fce72b5
commit b379f21cb3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 377 additions and 62 deletions

View file

@ -57,6 +57,7 @@ set(SOURCES_COMMON
src/Options.cpp src/Options.cpp
src/log/ConsoleLog.cpp src/log/ConsoleLog.cpp
src/log/FileLog.cpp src/log/FileLog.cpp
src/log/RemoteLog.cpp
src/log/Log.cpp src/log/Log.cpp
src/Platform.cpp src/Platform.cpp
src/Cpu.cpp src/Cpu.cpp

View file

@ -10,7 +10,7 @@
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.2.5/css/select.dataTables.min.css"> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.2.5/css/select.dataTables.min.css">
<link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet"> <link href="https://gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet">
<link rel="shortcut icon" href="http://root.graef.in/static/xmrigcc/favicon.ico"> <link rel="shortcut icon" href="https://root.graef.in:8443/static/xmrigcc/favicon.ico">
<style> <style>
.right{text-align:right;} .right{text-align:right;}
@ -106,7 +106,7 @@
{data: "client_status.client_id", render: clientInfo}, {data: "client_status.client_id", render: clientInfo},
{data: "client_status.current_pool"}, {data: "client_status.current_pool"},
{data: "client_status.current_status", render: clientStatus}, {data: "client_status.current_status", render: clientStatus},
{data: "client_status.current_algo_name"}, {data: "client_status.current_algo_name", render: algoAndPowVariantName},
{data: "client_status.hashrate_short", render: round, className: "right"}, {data: "client_status.hashrate_short", render: round, className: "right"},
{data: "client_status.hashrate_medium", render: round, className: "right"}, {data: "client_status.hashrate_medium", render: round, className: "right"},
{data: "client_status.hashrate_long", render: round, className: "right"}, {data: "client_status.hashrate_long", render: round, className: "right"},
@ -117,6 +117,13 @@
{data: "client_status.shares_total", className: "right"}, {data: "client_status.shares_total", className: "right"},
{data: "client_status.uptime", render: uptime, className: "right"}, {data: "client_status.uptime", render: uptime, className: "right"},
{data: "client_status.last_status_update", render: laststatus}, {data: "client_status.last_status_update", render: laststatus},
{
data: null,
defaultContent:
"<td class='center-tab'><button type='button' id='LOG' class='btn btn-xs btn-info' data-toggle='tooltip' title='View miner log'><i class='fa fa-file-text-o'></i></button></td>",
orderable: false,
className: "center-tab"
},
{ {
data: null, data: null,
defaultContent: defaultContent:
@ -362,7 +369,7 @@
table.draw(); table.draw();
}); });
$('#clientStatusList tbody').on( 'click', 'button', function () { $('#clientStatusList tbody ').on( 'click', 'button#EDIT', function () {
var data = table.row( $(this).parents('tr') ).data(); var data = table.row( $(this).parents('tr') ).data();
var clientId = data['client_status']['client_id']; var clientId = data['client_status']['client_id'];
@ -394,6 +401,33 @@
setClientConfig(clientId, clientConfig); setClientConfig(clientId, clientConfig);
}); });
$('#clientStatusList tbody').on( 'click', 'button#LOG', function () {
var data = table.row( $(this).parents('tr') ).data();
var clientId = data['client_status']['client_id'];
var log = data['client_status']['log'];
var htmlContent = "<div class='form-group' id='viewer' data-value='" + clientId + "'>" +
"<label for='config'>Log of: " + clientId + "</label>"+
"<textarea class='form-control' rows='20' id='log'>" + log + "</textarea>" +
"</div>";
$('#minerLog').find('.modal-body').html(htmlContent);
$('#minerLog').modal('show');
});
$('#minerLogRefresh').click(function(event) {
var clientId = $('#minerLog').find('.form-group')["0"].dataset.value;
table.rows().eq(0).each(function (index) {
var row = table.row(index);
var data = row.data();
if (clientId === data.client_status.client_id) {
$('#log').val(data.client_status.log);
}
});
});
$('#multiMinerEditorReplace').click(function(event) { $('#multiMinerEditorReplace').click(function(event) {
table.rows({ selected: true }).eq(0).each(function (index) { table.rows({ selected: true }).eq(0).each(function (index) {
var row = table.row(index); var row = table.row(index);
@ -477,6 +511,18 @@
return data; return data;
} }
function algoAndPowVariantName( data, type, row ) {
var algo = row.client_status.current_algo_name;
var powVariant = row.client_status.current_pow_variant_name;
if (powVariant !== "") {
return algo + " / " + powVariant
}
else {
return algo;
}
}
function clientStatus( data, type, row ) { function clientStatus( data, type, row ) {
var lastStatus = row.client_status.last_status_update * 1000; var lastStatus = row.client_status.last_status_update * 1000;
@ -489,6 +535,9 @@
function clientInfo( data, type, row ) { function clientInfo( data, type, row ) {
if (type !== 'sort') { if (type !== 'sort') {
var lastStatus = row.client_status.last_status_update * 1000;
var online = isOnline(lastStatus);
var tooltip = "CPU: " + row.client_status.cpu_brand + " (" + row.client_status.cpu_sockets + ") [" + row.client_status.cpu_cores + " cores / " + row.client_status.cpu_threads + " threads]"; var tooltip = "CPU: " + row.client_status.cpu_brand + " (" + row.client_status.cpu_sockets + ") [" + row.client_status.cpu_cores + " cores / " + row.client_status.cpu_threads + " threads]";
tooltip += '\n'; tooltip += '\n';
tooltip += "CPU Flags: " + (row.client_status.cpu_has_aes ? "AES-NI " : ""); tooltip += "CPU Flags: " + (row.client_status.cpu_has_aes ? "AES-NI " : "");
@ -506,16 +555,12 @@
tooltip += '\n'; tooltip += '\n';
tooltip += "Version: " + row.client_status.version; tooltip += "Version: " + row.client_status.version;
tooltip += '\n'; tooltip += '\n';
tooltip += "Status: "; tooltip += "Status: " + online ? "Online" : "Offline";
var lastStatus = row.client_status.last_status_update * 1000; if (online) {
if (isOnline(lastStatus)) {
tooltip += "Online";
return '<span data-toggle="tooltip" title="'+ tooltip + '"><div class="online">' + data + '</div></span>'; return '<span data-toggle="tooltip" title="'+ tooltip + '"><div class="online">' + data + '</div></span>';
} }
else { else {
tooltip += "Offline";
return '<span data-toggle="tooltip" title="'+ tooltip + '"><div class="offline">' + data + '</div></span>'; return '<span data-toggle="tooltip" title="'+ tooltip + '"><div class="offline">' + data + '</div></span>';
} }
} }
@ -585,7 +630,7 @@
<div id="statusBar"></div> <div id="statusBar"></div>
<div class="center"> <div class="center">
<img src="http://root.graef.in/static/xmrigcc/banner.png"/> <img src="https://root.graef.in:8443/static/xmrigcc/banner.png"/>
</div> </div>
<form style="padding-bottom: 25px; margin-top: -50px"> <form style="padding-bottom: 25px; margin-top: -50px">
@ -600,7 +645,7 @@
<th>Miner Id</th> <th>Miner Id</th>
<th>Pool</th> <th>Pool</th>
<th>Status</th> <th>Status</th>
<th>Algo</th> <th>Algo / PoW</th>
<th>Hashrate</th> <th>Hashrate</th>
<th>Hashrate 1m</th> <th>Hashrate 1m</th>
@ -614,6 +659,7 @@
<th>Shares Total</th> <th>Shares Total</th>
<th>Uptime</th> <th>Uptime</th>
<th>Last Update</th> <th>Last Update</th>
<th>Log</th>
<th>Edit</th> <th>Edit</th>
</tr> </tr>
</thead> </thead>
@ -635,6 +681,7 @@
<th></th> <th></th>
<th></th> <th></th>
<th></th> <th></th>
<th></th>
</tr> </tr>
</tfoot> </tfoot>
</table> </table>
@ -658,6 +705,24 @@
</div> </div>
</div> </div>
<div class="modal fade" id="minerLog" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 class="modal-title">Miner log</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button id="minerLogRefresh" type="button" class="btn btn-success">Refresh</button>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="multiMinerEditor" role="dialog"> <div class="modal fade" id="multiMinerEditor" role="dialog">
<div class="modal-dialog modal-lg"> <div class="modal-dialog modal-lg">
<div class="modal-content"> <div class="modal-content">

View file

@ -27,13 +27,13 @@
#include <uv.h> #include <uv.h>
#include <cc/ControlCommand.h> #include <cc/ControlCommand.h>
#include "api/Api.h"
#include "App.h" #include "App.h"
#include "Console.h" #include "Console.h"
#include "Cpu.h" #include "Cpu.h"
#include "crypto/CryptoNight.h" #include "crypto/CryptoNight.h"
#include "log/ConsoleLog.h" #include "log/ConsoleLog.h"
#include "log/FileLog.h" #include "log/FileLog.h"
#include "log/RemoteLog.h"
#include "log/Log.h" #include "log/Log.h"
#include "Mem.h" #include "Mem.h"
#include "net/Network.h" #include "net/Network.h"
@ -88,6 +88,10 @@ App::App(int argc, char **argv) :
Log::add(new FileLog(m_options->logFile())); Log::add(new FileLog(m_options->logFile()));
} }
if (m_options->ccUseRemoteLogging()) {
Log::add(new RemoteLog(m_options->ccRemoteLoggingMaxRows()));
}
# ifdef HAVE_SYSLOG_H # ifdef HAVE_SYSLOG_H
if (m_options->syslog()) { if (m_options->syslog()) {
Log::add(new SysLog()); Log::add(new SysLog());

View file

@ -96,7 +96,9 @@ Options:\n"
--cc-use-tls enable tls encryption for CC communication\n\ --cc-use-tls enable tls encryption for CC communication\n\
--cc-access-token=T access token for CC Server\n\ --cc-access-token=T access token for CC Server\n\
--cc-worker-id=ID custom worker-id for CC Server\n\ --cc-worker-id=ID custom worker-id for CC Server\n\
--cc-update-interval-s=N status update interval in seconds (default: 10 min: 1)\n" --cc-update-interval-s=N status update interval in seconds (default: 10 min: 1)\n\
--cc-use-remote-logging enable remote logging on CC Server\n\
--cc-remote-logging-max-rows=N maximum last n-log rows to send CC Server\n"
# endif # endif
# endif # endif
@ -180,9 +182,11 @@ static struct option const options[] = {
{ "cc-cert-file", 1, nullptr, 4014 }, { "cc-cert-file", 1, nullptr, 4014 },
{ "cc-key-file", 1, nullptr, 4015 }, { "cc-key-file", 1, nullptr, 4015 },
{ "cc-use-tls", 0, nullptr, 4016 }, { "cc-use-tls", 0, nullptr, 4016 },
{ "cc-use-remote-logging", 0, nullptr, 4017 },
{ "cc-remote-logging-max-rows", 1, nullptr, 4018 },
{ "daemonized", 0, nullptr, 4011 }, { "daemonized", 0, nullptr, 4011 },
{ "doublehash-thread-mask", 1, nullptr, 4013 }, { "doublehash-thread-mask", 1, nullptr, 4013 },
{ "multihash-thread-mask", 1, nullptr, 4013 }, { "multihash-thread-mask", 1, nullptr, 4013 },
{ nullptr, 0, nullptr, 0 } { nullptr, 0, nullptr, 0 }
}; };
@ -241,6 +245,8 @@ static struct option const cc_client_options[] = {
{ "worker-id", 1, nullptr, 4005 }, { "worker-id", 1, nullptr, 4005 },
{ "update-interval-s", 1, nullptr, 4012 }, { "update-interval-s", 1, nullptr, 4012 },
{ "use-tls", 0, nullptr, 4016 }, { "use-tls", 0, nullptr, 4016 },
{ "use-remote-logging", 0, nullptr, 4017 },
{ "remote-logging-max-rows",1, nullptr, 4018 },
{ nullptr, 0, nullptr, 0 } { nullptr, 0, nullptr, 0 }
}; };
@ -310,6 +316,7 @@ Options::Options(int argc, char **argv) :
m_syslog(false), m_syslog(false),
m_daemonized(false), m_daemonized(false),
m_ccUseTls(false), m_ccUseTls(false),
m_ccUseRemoteLogging(true),
m_configFile(Platform::defaultConfigName()), m_configFile(Platform::defaultConfigName()),
m_apiToken(nullptr), m_apiToken(nullptr),
m_apiWorkerId(nullptr), m_apiWorkerId(nullptr),
@ -339,6 +346,7 @@ Options::Options(int argc, char **argv) :
m_threads(0), m_threads(0),
m_ccUpdateInterval(10), m_ccUpdateInterval(10),
m_ccPort(0), m_ccPort(0),
m_ccRemoteLoggingMaxRows(25),
m_affinity(-1L), m_affinity(-1L),
m_multiHashThreadMask(-1L) m_multiHashThreadMask(-1L)
{ {
@ -478,7 +486,6 @@ bool Options::parseArg(int key, const char *arg)
case 'l': /* --log-file */ case 'l': /* --log-file */
free(m_logFile); free(m_logFile);
m_logFile = strdup(arg); m_logFile = strdup(arg);
m_colors = false;
break; break;
case 4001: /* --access-token */ case 4001: /* --access-token */
@ -552,6 +559,8 @@ bool Options::parseArg(int key, const char *arg)
case 4006: /* --cc-port */ case 4006: /* --cc-port */
case 4012: /* --cc-update-interval-c */ case 4012: /* --cc-update-interval-c */
return parseArg(key, strtol(arg, nullptr, 10)); return parseArg(key, strtol(arg, nullptr, 10));
case 4018: /* --cc-remote-logging-max-rows */
return parseArg(key, strtol(arg, nullptr, 25));
case 'B': /* --background */ case 'B': /* --background */
case 'k': /* --keepalive */ case 'k': /* --keepalive */
@ -572,6 +581,9 @@ bool Options::parseArg(int key, const char *arg)
case 4016: /* --cc-use-tls */ case 4016: /* --cc-use-tls */
return parseBoolean(key, true); return parseBoolean(key, true);
case 4017: /* --cc-use-remote-logging */
return parseBoolean(key, true);
case 't': /* --threads */ case 't': /* --threads */
if (strncmp(arg, "all", 3) == 0) { if (strncmp(arg, "all", 3) == 0) {
m_threads = Cpu::threads(); m_threads = Cpu::threads();
@ -746,6 +758,16 @@ bool Options::parseArg(int key, uint64_t arg)
m_multiHashThreadMask = arg; m_multiHashThreadMask = arg;
} }
break; break;
case 4018: /* --cc-remote-logging-max-rows */
if (arg < 1) {
m_ccUseRemoteLogging = false;
}
else {
m_ccRemoteLoggingMaxRows = (int) arg;
}
break;
default: default:
break; break;
} }
@ -799,6 +821,10 @@ bool Options::parseBoolean(int key, bool enable)
m_ccUseTls = enable; m_ccUseTls = enable;
break; break;
case 4017: /* --cc-use-remote-logging */
m_ccUseRemoteLogging = enable;
break;
default: default:
break; break;
} }

View file

@ -72,6 +72,7 @@ public:
inline bool syslog() const { return m_syslog; } inline bool syslog() const { return m_syslog; }
inline bool daemonized() const { return m_daemonized; } inline bool daemonized() const { return m_daemonized; }
inline bool ccUseTls() const { return m_ccUseTls; } inline bool ccUseTls() const { return m_ccUseTls; }
inline bool ccUseRemoteLogging() const { return m_ccUseRemoteLogging; }
inline const char *configFile() const { return m_configFile; } inline const char *configFile() const { return m_configFile; }
inline const char *apiToken() const { return m_apiToken; } inline const char *apiToken() const { return m_apiToken; }
inline const char *apiWorkerId() const { return m_apiWorkerId; } inline const char *apiWorkerId() const { return m_apiWorkerId; }
@ -100,6 +101,7 @@ public:
inline size_t threads() const { return m_threads; } inline size_t threads() const { return m_threads; }
inline int ccUpdateInterval() const { return m_ccUpdateInterval; } inline int ccUpdateInterval() const { return m_ccUpdateInterval; }
inline int ccPort() const { return m_ccPort; } inline int ccPort() const { return m_ccPort; }
inline size_t ccRemoteLoggingMaxRows() const { return m_ccRemoteLoggingMaxRows; }
inline int64_t affinity() const { return m_affinity; } inline int64_t affinity() const { return m_affinity; }
inline int64_t multiHashThreadMask() const { return m_multiHashThreadMask; } inline int64_t multiHashThreadMask() const { return m_multiHashThreadMask; }
inline void setColors(bool colors) { m_colors = colors; } inline void setColors(bool colors) { m_colors = colors; }
@ -144,6 +146,7 @@ private:
bool m_syslog; bool m_syslog;
bool m_daemonized; bool m_daemonized;
bool m_ccUseTls; bool m_ccUseTls;
bool m_ccUseRemoteLogging;
const char* m_configFile; const char* m_configFile;
char *m_apiToken; char *m_apiToken;
char *m_apiWorkerId; char *m_apiWorkerId;
@ -173,6 +176,7 @@ private:
size_t m_threads; size_t m_threads;
int m_ccUpdateInterval; int m_ccUpdateInterval;
int m_ccPort; int m_ccPort;
size_t m_ccRemoteLoggingMaxRows;
int64_t m_affinity; int64_t m_affinity;
int64_t m_multiHashThreadMask; int64_t m_multiHashThreadMask;
std::vector<Url*> m_pools; std::vector<Url*> m_pools;

View file

@ -27,6 +27,7 @@
#include <array> #include <array>
#include <vector> #include <vector>
#include <PowVariant.h>
class SubmitResult; class SubmitResult;
@ -51,6 +52,7 @@ public:
uint64_t failures; uint64_t failures;
uint64_t rejected; uint64_t rejected;
uint64_t total; uint64_t total;
PowVariant powVariant;
private: private:
bool m_active; bool m_active;

View file

@ -28,6 +28,8 @@
#include <3rdparty/rapidjson/stringbuffer.h> #include <3rdparty/rapidjson/stringbuffer.h>
#include <3rdparty/rapidjson/prettywriter.h> #include <3rdparty/rapidjson/prettywriter.h>
#include <version.h> #include <version.h>
#include <log/RemoteLog.h>
#include <api/NetworkState.h>
#include "CCClient.h" #include "CCClient.h"
#include "App.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.setSharesTotal(network.accepted + network.rejected);
m_self->m_clientStatus.setHashesTotal(network.total); m_self->m_clientStatus.setHashesTotal(network.total);
m_self->m_clientStatus.setAvgTime(network.avgTime()); m_self->m_clientStatus.setAvgTime(network.avgTime());
m_self->m_clientStatus.setCurrentPowVariantName(getPowVariantName(network.powVariant));
uv_mutex_unlock(&m_mutex); uv_mutex_unlock(&m_mutex);
} }
@ -140,8 +143,6 @@ void CCClient::updateNetworkState(const NetworkState& network)
void CCClient::publishClientStatusReport() void CCClient::publishClientStatusReport()
{ {
refreshUptime();
std::string requestUrl = "/client/setClientStatus?clientId=" + m_self->m_clientStatus.getClientId(); std::string requestUrl = "/client/setClientStatus?clientId=" + m_self->m_clientStatus.getClientId();
std::string requestBuffer = m_self->m_clientStatus.toJsonString(); 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())); 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) 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_init(&m_self->m_client_loop, &m_self->m_timer);
uv_timer_start(&m_self->m_timer, CCClient::onReport, 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),
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) void CCClient::onReport(uv_timer_t* handle)
{ {
if (m_self) { if (m_self) {
m_self->refreshUptime();
m_self->refreshLog();
m_self->publishClientStatusReport(); m_self->publishClientStatusReport();
} }
} }

View file

@ -48,13 +48,15 @@ public:
private: private:
static void publishClientStatusReport(); void publishClientStatusReport();
static void updateConfig(); void updateConfig();
static void publishConfig(); void publishConfig();
static std::shared_ptr<httplib::Response> performRequest(const std::string& requestUrl, void refreshUptime();
void refreshLog();
std::shared_ptr<httplib::Response> performRequest(const std::string& requestUrl,
const std::string& requestBuffer, const std::string& requestBuffer,
const std::string& operation); const std::string& operation);
static void onThreadStarted(void *handle); static void onThreadStarted(void *handle);
static void onReport(uv_timer_t *handle); static void onReport(uv_timer_t *handle);
@ -73,8 +75,6 @@ private:
uv_timer_t m_timer; uv_timer_t m_timer;
uv_loop_t m_client_loop; uv_loop_t m_client_loop;
uv_thread_t m_thread; uv_thread_t m_thread;
static void refreshUptime();
}; };
#endif #endif

View file

@ -98,6 +98,16 @@ std::string ClientStatus::getCurrentAlgoName() const
return m_currentAlgoName; 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 std::string ClientStatus::getCpuBrand() const
{ {
return m_cpuBrand; return m_cpuBrand;
@ -128,6 +138,16 @@ void ClientStatus::setVersion(const std::string& version)
m_version = 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 bool ClientStatus::hasHugepages() const
{ {
return m_hasHugepages; return m_hasHugepages;
@ -356,6 +376,10 @@ bool ClientStatus::parseFromJson(const rapidjson::Document& document)
m_currentAlgoName = clientStatus["current_algo_name"].GetString(); 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")) { if (clientStatus.HasMember("cpu_brand")) {
m_cpuBrand = clientStatus["cpu_brand"].GetString(); m_cpuBrand = clientStatus["cpu_brand"].GetString();
} }
@ -368,6 +392,10 @@ bool ClientStatus::parseFromJson(const rapidjson::Document& document)
m_version = clientStatus["version"].GetString(); m_version = clientStatus["version"].GetString();
} }
if (clientStatus.HasMember("log")) {
m_log = clientStatus["log"].GetString();
}
if (clientStatus.HasMember("hugepages_available")) { if (clientStatus.HasMember("hugepages_available")) {
m_hasHugepages = clientStatus["hugepages_available"].GetBool(); 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("client_id", rapidjson::StringRef(m_clientId.c_str()), allocator);
clientStatus.AddMember("current_pool", rapidjson::StringRef(m_currentPool.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_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("cpu_brand", rapidjson::StringRef(m_cpuBrand.c_str()), allocator);
clientStatus.AddMember("external_ip", rapidjson::StringRef(m_externalIp.c_str()), allocator); clientStatus.AddMember("external_ip", rapidjson::StringRef(m_externalIp.c_str()), allocator);
clientStatus.AddMember("version", rapidjson::StringRef(m_version.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("last_status_update", static_cast<uint64_t >(m_lastStatusUpdate), allocator);
clientStatus.AddMember("log", rapidjson::StringRef(m_log.c_str()), allocator);
return clientStatus; return clientStatus;
} }

View file

@ -69,6 +69,9 @@ public:
std::string getCurrentAlgoName() const; std::string getCurrentAlgoName() const;
void setCurrentAlgoName(const std::string& algoName); void setCurrentAlgoName(const std::string& algoName);
std::string getCurrentPowVariantName() const;
void setCurrentPowVariantName(const std::string& powVariantName);
std::string getCpuBrand() const; std::string getCpuBrand() const;
void setCpuBrand(const std::string& cpuBrand); void setCpuBrand(const std::string& cpuBrand);
@ -78,6 +81,9 @@ public:
std::string getVersion() const; std::string getVersion() const;
void setVersion(const std::string& version); void setVersion(const std::string& version);
std::string getLog() const;
void setLog(const std::string& version);
bool hasHugepages() const; bool hasHugepages() const;
void setHugepages(bool hasHugepages); void setHugepages(bool hasHugepages);
@ -157,9 +163,11 @@ private:
std::string m_clientId; std::string m_clientId;
std::string m_currentPool; std::string m_currentPool;
std::string m_currentAlgoName; std::string m_currentAlgoName;
std::string m_currentPowVariantName;
std::string m_cpuBrand; std::string m_cpuBrand;
std::string m_externalIp; std::string m_externalIp;
std::string m_version; std::string m_version;
std::string m_log;
bool m_hasHugepages; bool m_hasHugepages;
bool m_isHugepagesEnabled; bool m_isHugepagesEnabled;

View file

@ -34,5 +34,7 @@
"access-token": "mySecret", // access token for CC Server (has to be the same in config_cc.json) "access-token": "mySecret", // access token for CC Server (has to be the same in config_cc.json)
"worker-id": null, // custom worker-id for CC Server (otherwise hostname is used) "worker-id": null, // custom worker-id for CC Server (otherwise hostname is used)
"update-interval-s": 10 // status update interval in seconds (default: 10 min: 1) "update-interval-s": 10 // status update interval in seconds (default: 10 min: 1)
"use-remote-logging" : true, // enable remote logging on CC Server
"remote-logging-max-rows" : 20 // maximum last n-log rows to send CC Server
} }
} }

View file

@ -34,5 +34,7 @@
"access-token": "mySecret", // access token for CC Server (has to be the same in config_cc.json) "access-token": "mySecret", // access token for CC Server (has to be the same in config_cc.json)
"worker-id": null, // custom worker-id for CC Server (otherwise hostname is used) "worker-id": null, // custom worker-id for CC Server (otherwise hostname is used)
"update-interval-s": 10 // status update interval in seconds (default: 10 min: 1) "update-interval-s": 10 // status update interval in seconds (default: 10 min: 1)
"use-remote-logging" : true, // enable remote logging on CC Server
"remote-logging-max-rows" : 20 // maximum last n-log rows to send CC Server
} }
} }

View file

@ -22,6 +22,7 @@
*/ */
#include <regex>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -67,7 +68,9 @@ void FileLog::message(int level, const char* fmt, va_list args)
size = vsnprintf(buf + size, 512 - size - 1, fmt, args) + size; size = vsnprintf(buf + size, 512 - size - 1, fmt, args) + size;
buf[size] = '\n'; buf[size] = '\n';
write(buf, size + 1); std::string row = std::regex_replace(std::string(buf, size+1), std::regex("\x1B\\[[0-9;]*[a-zA-Z]"), "");
write(const_cast<char*>(row.c_str()), size + 1);
} }

93
src/log/RemoteLog.cpp Normal file
View file

@ -0,0 +1,93 @@
/* XMRig
* Copyright 2018- BenDr0id <ben@graef.in>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sstream>
#include <regex>
#include "log/RemoteLog.h"
RemoteLog* RemoteLog::m_self = nullptr;
RemoteLog::RemoteLog(size_t maxRows)
: maxRows_(maxRows)
{
m_self = this;
}
RemoteLog::~RemoteLog()
{
m_self = nullptr;
}
void RemoteLog::message(int level, const char* fmt, va_list args)
{
time_t now = time(nullptr);
tm stime;
# ifdef _WIN32
localtime_s(&stime, &now);
# else
localtime_r(&now, &stime);
# endif
char *buf = new char[512];
int size = snprintf(buf, 23, "[%d-%02d-%02d %02d:%02d:%02d] ",
stime.tm_year + 1900,
stime.tm_mon + 1,
stime.tm_mday,
stime.tm_hour,
stime.tm_min,
stime.tm_sec);
size = vsnprintf(buf + size, 512 - size - 1, fmt, args) + size;
buf[size] = '\n';
if (rows_.size() == maxRows_) {
rows_.pop_front();
}
std::string row = std::regex_replace(std::string(buf, size+1), std::regex("\x1B\\[[0-9;]*[a-zA-Z]"), "");
rows_.push_back(row);
}
void RemoteLog::text(const char* fmt, va_list args)
{
message(0, fmt, args);
}
void RemoteLog::flushRows()
{
if (m_self) {
m_self->rows_.clear();
}
}
std::string RemoteLog::getRows()
{
std::stringstream data;
if (m_self) {
for (std::list<std::string>::iterator it = m_self->rows_.begin(); it != m_self->rows_.end(); it++) {
data << it->c_str();
}
}
return data.str();
}

48
src/log/RemoteLog.h Normal file
View file

@ -0,0 +1,48 @@
/* XMRig
* Copyright 2018- BenDr0id <ben@graef.in>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __REMOTELOG_H__
#define __REMOTELOG_H__
#include <list>
#include <string>
#include "interfaces/ILogBackend.h"
class RemoteLog : public ILogBackend
{
public:
RemoteLog(size_t maxRows);
~RemoteLog();
void message(int level, const char* fmt, va_list args) override;
void text(const char* fmt, va_list args) override;
static void flushRows();
static std::string getRows();
private:
static RemoteLog* m_self;
size_t maxRows_;
std::list<std::string> rows_;
};
#endif /* __REMOTELOG_H__ */

View file

@ -29,9 +29,9 @@ class BoostConnection : public Connection, public std::enable_shared_from_this<B
public: public:
BoostConnection(const ConnectionListener::Ptr& listener) BoostConnection(const ConnectionListener::Ptr& listener)
: Connection(listener) : Connection(listener)
, socket_(ioService_) , m_resolver(m_ioService)
, m_socket(m_ioService)
{ {
} }
~BoostConnection() ~BoostConnection()
@ -43,17 +43,28 @@ public:
{ {
LOG_DEBUG("[%s:%d] Connecting", server.c_str(), port); LOG_DEBUG("[%s:%d] Connecting", server.c_str(), port);
boost::asio::ip::tcp::resolver resolver(ioService_);
boost::asio::ip::tcp::resolver::query query(server, std::to_string(port)); boost::asio::ip::tcp::resolver::query query(server, std::to_string(port));
boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query);
socket_.connect(iterator, m_resolver.async_resolve(query,
boost::bind(&BoostConnection::handleConnect, this->shared_from_this(), boost::bind(&BoostConnection::handleResolve, this->shared_from_this(),
boost::asio::placeholders::error)); boost::asio::placeholders::error,
boost::asio::placeholders::iterator));
std::thread([this]() { m_ioService.run(); }).detach();
}
void handleResolve(const boost::system::error_code& error,
boost::asio::ip::tcp::resolver::iterator endpointIterator)
{
if (!error) {
boost::asio::ip::tcp::endpoint endpoint = *endpointIterator;
std::thread([this]() { ioService_.run(); }).detach(); LOG_DEBUG("[%s:%d] DNS resolved ", endpoint.address().to_string().c_str(), endpoint.port());
m_socket.connect(endpointIterator, boost::bind(&BoostConnection::handleConnect, this->shared_from_this(),
boost::asio::placeholders::error));
} else {
notifyError(std::string("[DNS resolve] ") + error.message());
}
} }
void handleConnect(const boost::system::error_code& error) void handleConnect(const boost::system::error_code& error)
@ -63,7 +74,7 @@ public:
LOG_DEBUG("[%s:%d] Connected", getConnectedIp().c_str(), getConnectedPort()); LOG_DEBUG("[%s:%d] Connected", getConnectedIp().c_str(), getConnectedPort());
notifyConnected(); notifyConnected();
} else { } else {
notifyError(error.message()); notifyError(std::string("[Connect] ") + error.message());
} }
} }
@ -73,36 +84,36 @@ public:
LOG_DEBUG("[%s:%d] Disconnecting", getConnectedIp().c_str(), getConnectedPort()); LOG_DEBUG("[%s:%d] Disconnecting", getConnectedIp().c_str(), getConnectedPort());
boost::system::error_code ec; boost::system::error_code ec;
socket_.get().lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec); m_socket.get().lowest_layer().shutdown(boost::asio::ip::tcp::socket::shutdown_both, ec);
socket_.get().lowest_layer().close(); m_socket.get().lowest_layer().close();
} }
ioService_.stop(); m_ioService.stop();
ioService_.reset(); m_ioService.reset();
} }
bool isConnected() const override bool isConnected() const override
{ {
boost::system::error_code ec; boost::system::error_code ec;
socket_.get().lowest_layer().remote_endpoint(ec); m_socket.get().lowest_layer().remote_endpoint(ec);
return !ec && socket_.get().lowest_layer().is_open(); return !ec && m_socket.get().lowest_layer().is_open();
} }
std::string getConnectedIp() const override std::string getConnectedIp() const override
{ {
return isConnected() ? socket_.get().lowest_layer().remote_endpoint().address().to_string() : ""; return isConnected() ? m_socket.get().lowest_layer().remote_endpoint().address().to_string() : "";
} }
uint16_t getConnectedPort() const override uint16_t getConnectedPort() const override
{ {
return isConnected() ? socket_.get().lowest_layer().remote_endpoint().port() : 0; return isConnected() ? m_socket.get().lowest_layer().remote_endpoint().port() : 0;
} }
void send(const char* data, std::size_t size) override void send(const char* data, std::size_t size) override
{ {
LOG_DEBUG("[%s:%d] Sending: %.*s", getConnectedIp().c_str(), getConnectedPort(), size, data); LOG_DEBUG("[%s:%d] Sending: %.*s", getConnectedIp().c_str(), getConnectedPort(), size, data);
boost::asio::async_write(socket_.get(), boost::asio::async_write(m_socket.get(),
boost::asio::buffer(data, size), boost::asio::buffer(data, size),
boost::bind(&BoostConnection::handleWrite, this->shared_from_this(), boost::bind(&BoostConnection::handleWrite, this->shared_from_this(),
boost::asio::placeholders::error, boost::asio::placeholders::error,
@ -114,13 +125,13 @@ public:
{ {
if (error) { if (error) {
LOG_DEBUG_ERR("[%s:%d] Sending failed: %s", getConnectedIp().c_str(), getConnectedPort(), error.message().c_str()); LOG_DEBUG_ERR("[%s:%d] Sending failed: %s", getConnectedIp().c_str(), getConnectedPort(), error.message().c_str());
notifyError(error.message()); notifyError(std::string("[Send] ") + error.message());
} }
} }
void startReading() void startReading()
{ {
boost::asio::async_read(socket_.get(), boost::asio::async_read(m_socket.get(),
boost::asio::buffer(receiveBuffer_, sizeof(receiveBuffer_)), boost::asio::buffer(receiveBuffer_, sizeof(receiveBuffer_)),
boost::asio::transfer_at_least(1), boost::asio::transfer_at_least(1),
boost::bind(&BoostConnection::handleRead, this->shared_from_this(), boost::bind(&BoostConnection::handleRead, this->shared_from_this(),
@ -137,13 +148,14 @@ public:
startReading(); startReading();
} else { } else {
LOG_DEBUG_ERR("[%s:%d] Read failed: %s", getConnectedIp().c_str(), getConnectedPort(), error.message().c_str()); LOG_DEBUG_ERR("[%s:%d] Read failed: %s", getConnectedIp().c_str(), getConnectedPort(), error.message().c_str());
notifyError(error.message()); notifyError(std::string("[Read] ") + error.message());
} }
} }
private: private:
boost::asio::io_service ioService_; boost::asio::io_service m_ioService;
SOCKET socket_; boost::asio::ip::tcp::resolver m_resolver;
SOCKET m_socket;
char receiveBuffer_[2048]; char receiveBuffer_[2048];
}; };

View file

@ -81,11 +81,11 @@ Connection::Ptr establishConnection(const ConnectionListener::Ptr& listener,
connection->connect(host, port); connection->connect(host, port);
} }
catch (...) { catch (...) {
LOG_ERR("[%s:%d] Failed to establish connection: %s", host.c_str(), port, boost::current_exception_diagnostic_information().c_str());
if (connection) { if (connection) {
connection->disconnect(); connection->disconnect();
} }
connection->notifyError(std::string("[EstablishConnection] ") + boost::current_exception_diagnostic_information());
} }

View file

@ -49,9 +49,6 @@ public:
protected: protected:
Connection(const ConnectionListener::Ptr& listener); Connection(const ConnectionListener::Ptr& listener);
virtual ~Connection() {}; virtual ~Connection() {};
void notifyConnected();
void notifyRead(char* data, size_t size);
void notifyError(const std::string& error);
public: public:
virtual void connect(const std::string& server, uint16_t port) = 0; virtual void connect(const std::string& server, uint16_t port) = 0;
@ -61,6 +58,10 @@ public:
virtual uint16_t getConnectedPort() const = 0; virtual uint16_t getConnectedPort() const = 0;
virtual void send(const char* data, std::size_t size) = 0; virtual void send(const char* data, std::size_t size) = 0;
void notifyConnected();
void notifyRead(char* data, size_t size);
void notifyError(const std::string& error);
private: private:
ConnectionListener::WeakPtr listener_; ConnectionListener::WeakPtr listener_;
}; };

View file

@ -177,6 +177,7 @@ void Network::setJob(Client *client, const Job &job)
LOG_INFO("new job from %s:%d with diff %d and PoW %s", client->host(), client->port(), job.diff(), getPowVariantName(job.powVariant()).c_str()); LOG_INFO("new job from %s:%d with diff %d and PoW %s", client->host(), client->port(), job.diff(), getPowVariantName(job.powVariant()).c_str());
} }
m_state.powVariant = job.powVariant();
m_state.diff = job.diff(); m_state.diff = job.diff();
Workers::setJob(job); Workers::setJob(job);
} }

View file

@ -36,14 +36,14 @@
#define APP_DESC "XMRigCC CPU miner" #define APP_DESC "XMRigCC CPU miner"
#define APP_COPYRIGHT "Copyright (C) 2017- BenDr0id" #define APP_COPYRIGHT "Copyright (C) 2017- BenDr0id"
#endif #endif
#define APP_VERSION "1.6.3 (based on XMRig)" #define APP_VERSION "1.6.4_beta1 (based on XMRig)"
#define APP_DOMAIN "" #define APP_DOMAIN ""
#define APP_SITE "https://github.com/Bendr0id/xmrigCC" #define APP_SITE "https://github.com/Bendr0id/xmrigCC"
#define APP_KIND "cpu" #define APP_KIND "cpu"
#define APP_VER_MAJOR 1 #define APP_VER_MAJOR 1
#define APP_VER_MINOR 6 #define APP_VER_MINOR 6
#define APP_VER_BUILD 3 #define APP_VER_BUILD 4
#define APP_VER_REV 0 #define APP_VER_REV 0
#ifndef NDEBUG #ifndef NDEBUG