From eb5cdbb3e74f1ddeb85c96ad2bc69bfae432ce56 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 26 Sep 2017 14:19:55 +0300 Subject: [PATCH] Added per worker statistics in console. --- CMakeLists.txt | 7 ++++-- src/App.cpp | 8 ++++++- src/App_unix.cpp | 1 + src/net/strategies/DonateStrategy.cpp | 7 ++++-- src/proxy/Miner.cpp | 1 - src/proxy/Proxy.cpp | 10 ++++++-- src/proxy/Proxy.h | 1 + src/proxy/workers/Workers.cpp | 33 +++++++++++++++++++++++++++ src/proxy/workers/Workers.h | 1 + 9 files changed, 61 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c01dcff..7650897 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -206,8 +206,11 @@ else() add_definitions(/DXMRIG_NO_GOOGLE_BREAKPAD) endif() -find_package(MHD) -if (WITH_HTTPD AND MHD_FOUND) +if (WITH_HTTPD) + find_package(MHD) +endif() + +if (MHD_FOUND) include_directories(${MHD_INCLUDE_DIRS}) set(HTTPD_SOURCES src/api/Httpd.h src/api/Httpd.cpp) diff --git a/src/App.cpp b/src/App.cpp index 54a70ce..5983c92 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -160,6 +160,11 @@ void App::onConsoleCommand(char command) m_proxy->toggleDebug(); break; + case 'w': + case 'W': + m_proxy->printWorkers(); + break; + case 3: LOG_WARN("Ctrl+C received, exiting"); close(); @@ -194,7 +199,8 @@ void App::onSignal(uv_signal_t *handle, int signum) break; default: - break; + LOG_WARN("signal %d received, ignore", signum); + return; } m_self->close(); diff --git a/src/App_unix.cpp b/src/App_unix.cpp index a3a41fc..3983b67 100644 --- a/src/App_unix.cpp +++ b/src/App_unix.cpp @@ -35,6 +35,7 @@ void App::background() { + signal(SIGPIPE, SIG_IGN); if (!m_options->background()) { return; diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index 66c13c6..c2b9fe5 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -134,14 +134,17 @@ void DonateStrategy::onClose(Client *client, int failures) void DonateStrategy::onJobReceived(Client *client, const Job &job) { + if (!isActive()) { + m_active = true; + m_listener->onActive(client); + } + m_listener->onJob(client, job); } void DonateStrategy::onLoginSuccess(Client *client) { - m_active = true; - m_listener->onActive(client); } diff --git a/src/proxy/Miner.cpp b/src/proxy/Miner.cpp index 9892a13..6e241d3 100644 --- a/src/proxy/Miner.cpp +++ b/src/proxy/Miner.cpp @@ -111,7 +111,6 @@ void Miner::send(char *data) LOG_DEBUG("[%s] send (%d bytes): \"%s\"", m_ip, strlen(data), data); if (m_state != ReadyState || uv_is_writable(reinterpret_cast(&m_socket)) == 0) { - LOG_ERR("NOT WRITABLE"); free(data); return; } diff --git a/src/proxy/Proxy.cpp b/src/proxy/Proxy.cpp index 8faa548..733a278 100644 --- a/src/proxy/Proxy.cpp +++ b/src/proxy/Proxy.cpp @@ -128,6 +128,12 @@ void Proxy::printHashrate() } +void Proxy::printWorkers() +{ + m_workers->printWorkers(); +} + + void Proxy::toggleDebug() { m_debug->toggle(); @@ -165,8 +171,8 @@ void Proxy::gc() void Proxy::print() { - LOG_INFO(Options::i()->colors() ? "\x1B[01;36m%03.1f KH/s\x1B[0m, shares: \x1B[01;37m%" PRIu64 "\x1B[0m/%s%" PRIu64 "\x1B[0m +%" PRIu64 ", upstreams: \x1B[01;37m%" PRIu64 "\x1B[0m, miners: \x1B[01;37m%" PRIu64 "\x1B[0m (max \x1B[01;37m%" PRIu64 "\x1B[0m) +%u/-%u" - : "%03.1f KH/s, shares: %" PRIu64 "/%s%" PRIu64 " +%" PRIu64 ", upstreams: %" PRIu64 ", miners: %" PRIu64 " (max %" PRIu64 " +%u/-%u", + LOG_INFO(Options::i()->colors() ? "\x1B[01;36m%03.1f KH/s\x1B[0m, shares: \x1B[01;37m%" PRIu64 "\x1B[0m/%s%" PRIu64 "\x1B[0m +%" PRIu64 ", upstreams: \x1B[01;37m%u\x1B[0m, miners: \x1B[01;37m%" PRIu64 "\x1B[0m (max \x1B[01;37m%" PRIu64 "\x1B[0m) +%u/-%u" + : "%03.1f KH/s, shares: %" PRIu64 "/%s%" PRIu64 " +%" PRIu64 ", upstreams: %u, miners: %" PRIu64 " (max %" PRIu64 " +%u/-%u", m_stats.hashrate(60), m_stats.data().accepted, Options::i()->colors() ? (m_stats.data().rejected ? "\x1B[31m" : "\x1B[01;37m") : "", m_stats.data().rejected, Counters::accepted, m_splitter->activeUpstreams(), Counters::miners(), Counters::maxMiners(), Counters::added(), Counters::removed()); diff --git a/src/proxy/Proxy.h b/src/proxy/Proxy.h index 62c0e37..c1471df 100644 --- a/src/proxy/Proxy.h +++ b/src/proxy/Proxy.h @@ -53,6 +53,7 @@ public: void connect(); void printConnections(); void printHashrate(); + void printWorkers(); void toggleDebug(); # ifdef APP_DEVEL diff --git a/src/proxy/workers/Workers.cpp b/src/proxy/workers/Workers.cpp index 6c85f8c..01b5fa4 100644 --- a/src/proxy/workers/Workers.cpp +++ b/src/proxy/workers/Workers.cpp @@ -22,7 +22,12 @@ */ +#include + + #include "api/Api.h" +#include "log/Log.h" +#include "Options.h" #include "proxy/events/AcceptEvent.h" #include "proxy/events/CloseEvent.h" #include "proxy/events/LoginEvent.h" @@ -42,6 +47,34 @@ Workers::~Workers() } +void Workers::printWorkers() +{ + char workerName[24]; + size_t size = 0; + + Log::i()->text(Options::i()->colors() ? "\x1B[01;37m%-23s | %-15s | %-5s | %-8s | %-3s | %10s |" : "%-23s | %-15s | %-5s | %-8s | %-3s | %10s |", + "WORKER NAME", "LAST IP", "COUNT", "ACCEPTED", "REJ", "10 MIN"); + + for (const Worker &worker : m_workers) { + const char *name = worker.name(); + size = strlen(name); + + if (size > sizeof(workerName) - 1) { + memcpy(workerName, name, 6); + memcpy(workerName + 6, "...", 3); + memcpy(workerName + 9, name + size - sizeof(workerName) + 10, sizeof(workerName) - 10); + workerName[sizeof(workerName) - 1] = '\0'; + } + else { + strncpy(workerName, name, sizeof(workerName) - 1); + } + + Log::i()->text("%-23s | %-15s | %5" PRIu64 " | %8" PRIu64 " | %3" PRIu64 " | %5.1f KH/s |", + workerName, worker.ip(), worker.connections(), worker.accepted(), worker.rejected(), worker.hashrate(600)); + } +} + + void Workers::tick(uint64_t ticks) { if ((ticks % 4) != 0) { diff --git a/src/proxy/workers/Workers.h b/src/proxy/workers/Workers.h index 677663c..d34853c 100644 --- a/src/proxy/workers/Workers.h +++ b/src/proxy/workers/Workers.h @@ -46,6 +46,7 @@ public: Workers(); ~Workers(); + void printWorkers(); void tick(uint64_t ticks); protected: