Added hashrate reports to API.

This commit is contained in:
XMRig
2017-09-09 16:48:01 +03:00
parent e58295f416
commit e3041aea6a
12 changed files with 143 additions and 55 deletions

View File

@@ -52,6 +52,7 @@ set(HEADERS
src/proxy/Server.h
src/proxy/Stats.h
src/proxy/StatsData.h
src/proxy/TickingCounter.h
src/proxy/splitters/NonceMapper.h
src/proxy/splitters/NonceSplitter.h
src/proxy/splitters/NonceStorage.h

View File

@@ -81,6 +81,7 @@ const char *ApiState::get(const char *url, size_t *size) const
getIdentify(reply);
getMiner(reply);
getHashrate(reply);
getMinersSummary(reply);
getResults(reply);
// getConnection(reply);
@@ -135,6 +136,20 @@ void ApiState::genId()
}
void ApiState::getHashrate(json_t *reply) const
{
json_t *hashrate = json_object();
json_t *total = json_array();
json_object_set(reply, "hashrate", hashrate);
json_object_set(hashrate, "total", total);
for (size_t i = 0; i < sizeof(m_stats.hashrate) / sizeof(m_stats.hashrate[0]); i++) {
json_array_append(total, json_real(normalize(m_stats.hashrate[i])));
}
}
//void ApiState::getConnection(json_t *reply) const
//{
// json_t *connection = json_object();

View File

@@ -44,7 +44,7 @@ public:
private:
const char *finalize(json_t *reply, size_t *size) const;
void genId();
void getConnection(json_t *reply) const;
void getHashrate(json_t *reply) const;
void getIdentify(json_t *reply) const;
void getMiner(json_t *reply) const;
void getMinersSummary(json_t *reply) const;

View File

@@ -30,7 +30,6 @@
#include "Options.h"
Hashrate Counters::m_hashrate[2];
uint64_t Counters::m_counters[3] = { 0 };
uint64_t Counters::m_minersMax = 0;
uv_timer_t Counters::m_timer;
@@ -38,25 +37,19 @@ uv_timer_t Counters::m_timer;
Counters::Tick Counters::tick;
double Counters::hashrate(size_t seconds)
{
return m_hashrate[0].calc(seconds) + m_hashrate[1].calc(seconds);
}
//void Counters::accept(Counters::Stores store, size_t id, uint32_t diff, uint64_t ms, bool verbose)
//{
// m_hashrate[store].accepted++;
// m_hashrate[store].add(diff);
// tick.accepted++;
void Counters::accept(Counters::Stores store, size_t id, uint32_t diff, uint64_t ms, bool verbose)
{
m_hashrate[store].accepted++;
m_hashrate[store].add(diff);
tick.accepted++;
if (verbose) {
LOG_INFO(Options::i()->colors() ? "#%03u \x1B[01;32maccepted\x1B[0m (%" PRId64 "/%" PRId64 "+%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
: "#%03u accepted (%" PRId64 "/%" PRId64 "+%" PRId64 ") diff %u (%" PRIu64 " ms)" ,
id, m_hashrate[0].accepted, m_hashrate[0].rejected[0], m_hashrate[0].rejected[1], diff, ms);
}
}
// if (verbose) {
// LOG_INFO(Options::i()->colors() ? "#%03u \x1B[01;32maccepted\x1B[0m (%" PRId64 "/%" PRId64 "+%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
// : "#%03u accepted (%" PRId64 "/%" PRId64 "+%" PRId64 ") diff %u (%" PRIu64 " ms)" ,
// id, m_hashrate[0].accepted, m_hashrate[0].rejected[0], m_hashrate[0].rejected[1], diff, ms);
// }
//}
void Counters::add(CounterTypes type)
@@ -65,21 +58,21 @@ void Counters::add(CounterTypes type)
}
void Counters::reject(Stores store, const char *ip, const char *message)
{
m_hashrate[store].rejected[1]++;
// LOG_INFO("[% -15s] \x1B[01;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 "+%" PRId64 ") \x1B[31m\"%s\"\x1B[0m",
// ip, m_hashrate[0].accepted, m_hashrate[0].rejected[0], m_hashrate[0].rejected[1], message);
}
//void Counters::reject(Stores store, const char *ip, const char *message)
//{
// m_hashrate[store].rejected[1]++;
//// LOG_INFO("[% -15s] \x1B[01;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 "+%" PRId64 ") \x1B[31m\"%s\"\x1B[0m",
//// ip, m_hashrate[0].accepted, m_hashrate[0].rejected[0], m_hashrate[0].rejected[1], message);
//}
void Counters::reject(Stores store, size_t id, uint32_t diff, uint64_t ms, const char *error)
{
m_hashrate[store].rejected[0]++;
LOG_INFO(Options::i()->colors() ? "#%03u \x1B[01;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 "+%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[31m\"%s\"\x1B[0m \x1B[01;30m(%" PRId64 " ms)"
: "#%03u rejected (%" PRId64 "/%" PRId64 "+%" PRId64 ") diff %u \"%s\" (%" PRId64 " ms)",
id, m_hashrate[0].accepted, m_hashrate[0].rejected[0], m_hashrate[0].rejected[1], diff, error, ms);
}
//void Counters::reject(Stores store, size_t id, uint32_t diff, uint64_t ms, const char *error)
//{
// m_hashrate[store].rejected[0]++;
// LOG_INFO(Options::i()->colors() ? "#%03u \x1B[01;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 "+%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[31m\"%s\"\x1B[0m \x1B[01;30m(%" PRId64 " ms)"
// : "#%03u rejected (%" PRId64 "/%" PRId64 "+%" PRId64 ") diff %u \"%s\" (%" PRId64 " ms)",
// id, m_hashrate[0].accepted, m_hashrate[0].rejected[0], m_hashrate[0].rejected[1], diff, error, ms);
//}
void Counters::remove(CounterTypes type)
@@ -97,8 +90,8 @@ void Counters::start()
void Counters::onTick(uv_timer_t *handle)
{
m_hashrate[0].tick();
m_hashrate[1].tick();
// m_hashrate[0].tick();
// m_hashrate[1].tick();
}

View File

@@ -60,16 +60,12 @@ public:
};
inline static uint64_t accepted() { return m_hashrate[0].accepted + m_hashrate[1].accepted; }
inline static uint64_t rejected() { return m_hashrate[0].rejected[0] + m_hashrate[1].rejected[0]; }
inline static uint64_t rejected2() { return m_hashrate[0].rejected[1] + m_hashrate[1].rejected[1];; }
inline static uint64_t upstreams() { return m_counters[Upstream]; }
static double hashrate(size_t seconds);
static void accept(Stores store, size_t id, uint32_t diff, uint64_t ms, bool verbose);
// static void accept(Stores store, size_t id, uint32_t diff, uint64_t ms, bool verbose);
static void add(CounterTypes type);
static void reject(Stores store, const char *ip, const char *message);
static void reject(Stores store, size_t id, uint32_t diff, uint64_t ms, const char *error);
// static void reject(Stores store, const char *ip, const char *message);
// static void reject(Stores store, size_t id, uint32_t diff, uint64_t ms, const char *error);
static void remove(CounterTypes type);
static void start();
@@ -83,7 +79,7 @@ public:
private:
static void onTick(uv_timer_t *handle);
static Hashrate m_hashrate[2];
// static Hashrate m_hashrate[2];
static uint64_t m_counters[3];
static uint64_t m_minersMax;
static uv_timer_t m_timer;

View File

@@ -23,6 +23,7 @@
#include <string.h>
#include <stdio.h>
#include "proxy/Hashrate.h"

View File

@@ -109,7 +109,7 @@ void Proxy::printHashrate()
{
LOG_INFO(Options::i()->colors() ? "\x1B[01;32m* \x1B[01;37mspeed\x1B[0m \x1B[01;30m(1m) \x1B[01;36m%03.1f\x1B[0m, \x1B[01;30m(10m) \x1B[01;36m%03.1f\x1B[0m, \x1B[01;30m(1h) \x1B[01;36m%03.1f\x1B[0m, \x1B[01;30m(12h) \x1B[01;36m%03.1f\x1B[0m, \x1B[01;30m(24h) \x1B[01;36m%03.1f KH/s"
: "* speed (1m) %03.1f, (10m) %03.1f, (1h) %03.1f, (12h) %03.1f, (24h) %03.1f KH/s",
Counters::hashrate(60), Counters::hashrate(600), Counters::hashrate(3600), Counters::hashrate(3600 * 12), Counters::hashrate(3600 * 24));
m_stats.hashrate(60), m_stats.hashrate(600), m_stats.hashrate(3600), m_stats.hashrate(3600 * 12), m_stats.hashrate(3600 * 24));
}
@@ -153,7 +153,7 @@ 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",
Counters::hashrate(60), Counters::accepted(), Options::i()->colors() ? (Counters::rejected() ? "\x1B[31m" : "\x1B[01;37m") : "", Counters::rejected(),
m_stats.hashrate(600), m_stats.data().accepted, Options::i()->colors() ? (m_stats.data().rejected ? "\x1B[31m" : "\x1B[01;37m") : "", m_stats.data().rejected,
Counters::tick.accepted, Counters::upstreams(), m_stats.data().miners, m_stats.data().maxMiners, Counters::tick.added, Counters::tick.removed, m_stats.data().maxMiners);
Counters::reset();

View File

@@ -28,7 +28,8 @@
#include "proxy/Stats.h"
Stats::Stats()
Stats::Stats() :
m_hashrate(4)
{
m_data.startTime = uv_now(uv_default_loop());
}
@@ -43,9 +44,19 @@ void Stats::tick(uint64_t ticks)
{
ticks++;
# ifndef XMRIG_NO_API
Api::tick(m_data);
# endif
if ((ticks % m_hashrate.tickTime()) == 0) {
m_hashrate.tick();
# ifndef XMRIG_NO_API
m_data.hashrate[0] = hashrate(60);
m_data.hashrate[1] = hashrate(600);
m_data.hashrate[2] = hashrate(3600);
m_data.hashrate[3] = hashrate(3600 * 12);
m_data.hashrate[4] = hashrate(3600 * 24);
Api::tick(m_data);
# endif
}
}
@@ -97,6 +108,8 @@ void Stats::onRejectedEvent(IEvent *event)
void Stats::add(const SubmitResult &result)
{
m_hashrate.add(result.diff);
m_data.accepted++;
m_data.hashes += result.diff;

View File

@@ -30,6 +30,7 @@
#include "interfaces/IEventListener.h"
#include "proxy/StatsData.h"
#include "proxy/TickingCounter.h"
class SubmitResult;
@@ -43,7 +44,8 @@ public:
void tick(uint64_t ticks);
inline const StatsData &data() const { return m_data; }
inline const StatsData &data() const { return m_data; }
inline double hashrate(int seconds) const { return m_hashrate.calc(seconds); }
protected:
void onEvent(IEvent *event) override;
@@ -54,6 +56,7 @@ private:
StatsData m_data;
TickingCounter<uint32_t> m_hashrate;
};

View File

@@ -77,6 +77,7 @@ public:
}
double hashrate[5] { 0.0 };
std::array<uint64_t, 10> topDiff { { } };
std::vector<uint16_t> latency;
uint64_t accepted;

View File

@@ -0,0 +1,71 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com>
*
*
* 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 __TICKINGCOUNTER_H__
#define __TICKINGCOUNTER_H__
#include <stdint.h>
#include <stdio.h>
#include <vector>
template <class T> class TickingCounter
{
public:
inline TickingCounter(size_t tickTime) :
m_tickTime(tickTime),
m_pending(0)
{}
inline double calc(size_t seconds) const
{
const size_t ticks = seconds / m_tickTime;
const size_t size = m_data.size();
uint64_t count = 0;
for (size_t i = size < ticks ? 0 : (size - ticks); i < size; ++i) {
count += m_data[i];
}
if (count == 0) {
return 0.0;
}
return (double) count / (ticks * m_tickTime * 1000);
}
inline size_t tickTime() const { return m_tickTime; }
inline void add(T count) { m_pending += count; }
inline void tick() { m_data.push_back(m_pending); m_pending = 0; }
private:
size_t m_tickTime;
std::vector<T> m_data;
T m_pending;
};
#endif /* __TICKINGCOUNTER_H__ */

View File

@@ -185,12 +185,6 @@ void NonceMapper::onResultAccepted(Client *client, const SubmitResult &result, c
AcceptEvent::start(ctx.miner, result, error);
if (error) {
Counters::reject(Counters::Primary, m_id, result.diff, result.elapsed, error);
} else {
Counters::accept(Counters::Primary, m_id, result.diff, result.elapsed, m_options->verbose());
}
if (!ctx.miner) {
return;
}