From d5f485c5179c87e0e99818f96004dc146cc5e0f9 Mon Sep 17 00:00:00 2001 From: Kano Date: Thu, 23 Aug 2012 19:20:12 +1000 Subject: [PATCH] Pools: add RollTime info to API 'stats' and 'Stats' button in miner.php --- API-README | 11 +++++++++++ api.c | 7 ++++++- miner.h | 4 ++++ miner.php | 18 +++++++++++++++++- util.c | 17 ++++++++++++++--- 5 files changed, 52 insertions(+), 5 deletions(-) diff --git a/API-README b/API-README index d4efaf6c..ff48a3c5 100644 --- a/API-README +++ b/API-README @@ -339,6 +339,17 @@ miner.php - an example web page to access the API Feature Changelog for external applications using the API: +API V1.18 + +Modified API commands: + 'stats' - add 'Work Had Roll Time', 'Work Can Roll', 'Work Had Expire', + 'Work Roll Time' to the pool stats + +Modified API commands: + 'config' - include 'ScanTime' + +---------- + API V1.17 (cgminer v2.7.1) Added API commands: diff --git a/api.c b/api.c index 05d7d3ef..ca1b9429 100644 --- a/api.c +++ b/api.c @@ -166,7 +166,7 @@ static const char SEPARATOR = '|'; #define SEPSTR "|" static const char GPUSEP = ','; -static const char *APIVERSION = "1.17"; +static const char *APIVERSION = "1.18"; static const char *DEAD = "Dead"; static const char *SICK = "Sick"; static const char *NOSTART = "NoStart"; @@ -1256,6 +1256,7 @@ static void minerconfig(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, root = api_add_const(root, "Device Code", DEVICECODE, false); root = api_add_const(root, "OS", OSINFO, false); root = api_add_bool(root, "Failover-Only", &opt_fail_only, false); + root = api_add_int(root, "ScanTime", &opt_scantime, false); root = print_data(root, buf, isjson); if (isjson) @@ -2676,6 +2677,10 @@ static int itemstats(int i, char *id, struct cgminer_stats *stats, struct cgmine root = api_add_timeval(root, "Pool Max", &(pool_stats->getwork_wait_max), false); root = api_add_timeval(root, "Pool Min", &(pool_stats->getwork_wait_min), false); root = api_add_double(root, "Pool Av", &(pool_stats->getwork_wait_rolling), false); + root = api_add_bool(root, "Work Had Roll Time", &(pool_stats->hadrolltime), false); + root = api_add_bool(root, "Work Can Roll", &(pool_stats->canroll), false); + root = api_add_bool(root, "Work Had Expire", &(pool_stats->hadexpire), false); + root = api_add_uint32(root, "Work Roll Time", &(pool_stats->rolltime), false); } if (extra) diff --git a/miner.h b/miner.h index 91fe7ce7..4f7b1d75 100644 --- a/miner.h +++ b/miner.h @@ -307,6 +307,10 @@ struct cgminer_pool_stats { struct timeval getwork_wait_max; struct timeval getwork_wait_min; double getwork_wait_rolling; + bool hadrolltime; + bool canroll; + bool hadexpire; + uint32_t rolltime; }; struct cgpu_info { diff --git a/miner.php b/miner.php index 198f0cf5..9c6f6949 100644 --- a/miner.php +++ b/miner.php @@ -84,8 +84,24 @@ $mobilesum = array( 'DEVS+NOTIFY' => array('DEVS.MHS av', 'DEVS.Accepted', 'DEVS.Rejected', 'DEVS.Utility'), 'POOL' => array('Accepted', 'Rejected')); # +$statspage = array( + 'DATE' => null, + 'RIGS' => null, + 'SUMMARY' => array('Elapsed', 'MHS av', 'Found Blocks=Blks', + 'Accepted', 'Rejected=Rej', 'Utility', + 'Hardware Errors=HW Errs', 'Network Blocks=Net Blks', + 'Work Utility'), + 'COIN' => array('*'), + 'STATS' => array('*')); +# +$statssum = array( + 'SUMMARY' => array('MHS av', 'Found Blocks', 'Accepted', + 'Rejected', 'Utility', 'Hardware Errors', + 'Work Utility')); +# # customsummarypages is an array of these Custom Summary Pages -$customsummarypages = array('Mobile' => array($mobilepage, $mobilesum)); +$customsummarypages = array('Mobile' => array($mobilepage, $mobilesum), + 'Stats' => array($statspage, $statssum)); # $here = $_SERVER['PHP_SELF']; # diff --git a/util.c b/util.c index b104d8a3..724ffa9d 100644 --- a/util.c +++ b/util.c @@ -58,6 +58,9 @@ struct header_info { char *lp_path; int rolltime; char *reason; + bool hadrolltime; + bool canroll; + bool hadexpire; }; struct tq_ent { @@ -157,14 +160,18 @@ static size_t resp_hdr_cb(void *ptr, size_t size, size_t nmemb, void *user_data) applog(LOG_DEBUG, "HTTP hdr(%s): %s", key, val); if (!strcasecmp("X-Roll-Ntime", key)) { + hi->hadrolltime = true; if (!strncasecmp("N", val, 1)) applog(LOG_DEBUG, "X-Roll-Ntime: N found"); else { + hi->canroll = true; + /* Check to see if expire= is supported and if not, set * the rolltime to the default scantime */ - if (strlen(val) > 7 && !strncasecmp("expire=", val, 7)) + if (strlen(val) > 7 && !strncasecmp("expire=", val, 7)) { sscanf(val + 7, "%d", &hi->rolltime); - else + hi->hadexpire = true; + } else hi->rolltime = opt_scantime; applog(LOG_DEBUG, "X-Roll-Ntime expiry set to %d", hi->rolltime); } @@ -258,7 +265,7 @@ json_t *json_rpc_call(CURL *curl, const char *url, { long timeout = longpoll ? (60 * 60) : 60; struct data_buffer all_data = {NULL, 0}; - struct header_info hi = {NULL, 0, NULL}; + struct header_info hi = {NULL, 0, NULL, false, false, false}; char len_hdr[64], user_agent_hdr[128]; char curl_err_str[CURL_ERROR_SIZE]; struct curl_slist *headers = NULL; @@ -388,6 +395,10 @@ json_t *json_rpc_call(CURL *curl, const char *url, } *rolltime = hi.rolltime; + pool->cgminer_pool_stats.rolltime = hi.rolltime; + pool->cgminer_pool_stats.hadrolltime = hi.hadrolltime; + pool->cgminer_pool_stats.canroll = hi.canroll; + pool->cgminer_pool_stats.hadexpire = hi.hadexpire; val = JSON_LOADS(all_data.buf, &err); if (!val) {