mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-23 12:09:22 +00:00
Added global uptime and extended connection information for API.
This commit is contained in:
parent
a000544fdc
commit
ffb282a11a
6 changed files with 45 additions and 15 deletions
|
@ -38,6 +38,7 @@
|
|||
#include "api/v1/ApiRouter.h"
|
||||
#include "base/kernel/Base.h"
|
||||
#include "base/tools/Buffer.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "common/crypto/keccak.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
|
@ -53,7 +54,8 @@ xmrig::Api::Api(Base *base) :
|
|||
m_base(base),
|
||||
m_id(),
|
||||
m_workerId(),
|
||||
m_httpd(nullptr)
|
||||
m_httpd(nullptr),
|
||||
m_timestamp(Chrono::steadyMSecs())
|
||||
{
|
||||
base->addListener(this);
|
||||
|
||||
|
@ -118,9 +120,12 @@ void xmrig::Api::exec(IApiRequest &request)
|
|||
using namespace rapidjson;
|
||||
|
||||
if (request.method() == IApiRequest::METHOD_GET && (request.url() == "/1/summary" || request.url() == "/api.json")) {
|
||||
auto &allocator = request.doc().GetAllocator();
|
||||
|
||||
request.accept();
|
||||
request.reply().AddMember("id", StringRef(m_id), request.doc().GetAllocator());
|
||||
request.reply().AddMember("worker_id", StringRef(m_workerId), request.doc().GetAllocator());;
|
||||
request.reply().AddMember("id", StringRef(m_id), allocator);
|
||||
request.reply().AddMember("worker_id", StringRef(m_workerId), allocator);
|
||||
request.reply().AddMember("uptime", (Chrono::steadyMSecs() - m_timestamp) / 1000, allocator);
|
||||
}
|
||||
|
||||
for (IApiListener *listener : m_listeners) {
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
|
||||
#include <vector>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/IBaseListener.h"
|
||||
|
@ -72,6 +73,7 @@ private:
|
|||
char m_workerId[128];
|
||||
Httpd *m_httpd;
|
||||
std::vector<IApiListener *> m_listeners;
|
||||
uint64_t m_timestamp;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@ public:
|
|||
inline String &operator=(char *str) { move(str); return *this; }
|
||||
inline String &operator=(const char *str) { copy(str); return *this; }
|
||||
inline String &operator=(const String &str) { copy(str); return *this; }
|
||||
inline String &operator=(std::nullptr_t) { delete [] m_data; m_data = nullptr; m_size = 0; return *this; }
|
||||
inline String &operator=(String &&other) { move(std::move(other)); return *this; }
|
||||
|
||||
rapidjson::Value toJSON() const;
|
||||
|
|
|
@ -100,7 +100,7 @@ void xmrig::Network::onActive(IStrategy *strategy, IClient *client)
|
|||
return;
|
||||
}
|
||||
|
||||
m_state.setPool(client->pool().host(), client->pool().port(), client->ip());
|
||||
m_state.onActive(client);
|
||||
|
||||
const char *tlsVersion = client->tlsVersion();
|
||||
LOG_INFO(WHITE_BOLD("use %s ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " " BLACK_BOLD("%s"),
|
||||
|
@ -235,11 +235,14 @@ void xmrig::Network::getConnection(rapidjson::Value &reply, rapidjson::Document
|
|||
reply.AddMember("algo", StringRef((algo.isValid() ? algo : m_controller->config()->algorithm()).shortName()), allocator);
|
||||
|
||||
Value connection(kObjectType);
|
||||
connection.AddMember("pool", StringRef(m_state.pool), allocator);
|
||||
connection.AddMember("uptime", m_state.connectionTime(), allocator);
|
||||
connection.AddMember("ping", m_state.latency(), allocator);
|
||||
connection.AddMember("failures", m_state.failures, allocator);
|
||||
connection.AddMember("error_log", Value(kArrayType), allocator);
|
||||
connection.AddMember("pool", StringRef(m_state.pool), allocator);
|
||||
connection.AddMember("ip", m_state.ip().toJSON(), allocator);
|
||||
connection.AddMember("uptime", m_state.connectionTime(), allocator);
|
||||
connection.AddMember("ping", m_state.latency(), allocator);
|
||||
connection.AddMember("failures", m_state.failures, allocator);
|
||||
connection.AddMember("tls", m_state.tls().toJSON(), allocator);
|
||||
connection.AddMember("tls-fingerprint", m_state.fingerprint().toJSON(), allocator);
|
||||
connection.AddMember("error_log", Value(kArrayType), allocator);
|
||||
|
||||
reply.AddMember("connection", connection, allocator);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <uv.h>
|
||||
|
||||
|
||||
#include "base/kernel/interfaces/IClient.h"
|
||||
#include "base/net/stratum/Pool.h"
|
||||
#include "base/net/stratum/SubmitResult.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "net/NetworkState.h"
|
||||
|
@ -96,19 +98,25 @@ void xmrig::NetworkState::add(const SubmitResult &result, const char *error)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::NetworkState::setPool(const char *host, int port, const char *ip)
|
||||
void xmrig::NetworkState::onActive(IClient *client)
|
||||
{
|
||||
snprintf(pool, sizeof(pool) - 1, "%s:%d", host, port);
|
||||
snprintf(pool, sizeof(pool) - 1, "%s:%d", client->pool().host().data(), client->pool().port());
|
||||
|
||||
m_active = true;
|
||||
m_ip = client->ip();
|
||||
m_tls = client->tlsVersion();
|
||||
m_fingerprint = client->tlsFingerprint();
|
||||
m_active = true;
|
||||
m_connectionTime = Chrono::steadyMSecs();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::NetworkState::stop()
|
||||
{
|
||||
m_active = false;
|
||||
diff = 0;
|
||||
m_active = false;
|
||||
diff = 0;
|
||||
m_ip = nullptr;
|
||||
m_tls = nullptr;
|
||||
m_fingerprint = nullptr;
|
||||
|
||||
failures++;
|
||||
m_latency.clear();
|
||||
|
|
|
@ -30,9 +30,13 @@
|
|||
#include <vector>
|
||||
|
||||
|
||||
#include "base/tools/String.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IClient;
|
||||
class SubmitResult;
|
||||
|
||||
|
||||
|
@ -41,11 +45,15 @@ class NetworkState
|
|||
public:
|
||||
NetworkState();
|
||||
|
||||
inline const String &fingerprint() const { return m_fingerprint; }
|
||||
inline const String &ip() const { return m_ip; }
|
||||
inline const String &tls() const { return m_tls; }
|
||||
|
||||
uint32_t avgTime() const;
|
||||
uint32_t latency() const;
|
||||
uint64_t connectionTime() const;
|
||||
void add(const SubmitResult &result, const char *error);
|
||||
void setPool(const char *host, int port, const char *ip);
|
||||
void onActive(IClient *client);
|
||||
void stop();
|
||||
|
||||
char pool[256];
|
||||
|
@ -59,6 +67,9 @@ public:
|
|||
private:
|
||||
bool m_active;
|
||||
std::vector<uint16_t> m_latency;
|
||||
String m_fingerprint;
|
||||
String m_ip;
|
||||
String m_tls;
|
||||
uint64_t m_connectionTime;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue