Merge pull request #365 from kanoi/api Pool store data transfer stats + API stats - display pool byte transfer stats
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
diff --git a/API-README b/API-README
index b5ec453..1a686f5 100644
--- a/API-README
+++ b/API-README
@@ -394,6 +394,9 @@ Enforced output limitation:
however, JSON brackets will be correctly closed and the JSON id will be
set to 0 (instead of 1) if any data was truncated
+Modified API commands:
+ 'stats' - add 'Times Sent', 'Bytes Sent', 'Times Recv', 'Bytes Recv'
+
----------
API V1.21 (cgminer v2.10.0)
@@ -711,7 +714,8 @@ On Fedora 17:
systemctl enable httpd.service --system
On windows there are a few options.
-Try one of these (I've never used either one)
+Try one of these (apparently the first one is easiest - thanks jborkl)
+ http://www.easyphp.org/
http://www.apachefriends.org/en/xampp.html
http://www.wampserver.com/en/
diff --git a/api.c b/api.c
index bfd7f69..a993483 100644
--- a/api.c
+++ b/api.c
@@ -2875,6 +2875,10 @@ static int itemstats(struct io_data *io_data, int i, char *id, struct cgminer_st
root = api_add_diff(root, "Max Diff", &(pool_stats->max_diff), false);
root = api_add_uint32(root, "Min Diff Count", &(pool_stats->min_diff_count), false);
root = api_add_uint32(root, "Max Diff Count", &(pool_stats->max_diff_count), false);
+ root = api_add_uint64(root, "Times Sent", &(pool_stats->times_sent), false);
+ root = api_add_uint64(root, "Bytes Sent", &(pool_stats->bytes_sent), false);
+ root = api_add_uint64(root, "Times Recv", &(pool_stats->times_received), false);
+ root = api_add_uint64(root, "Bytes Recv", &(pool_stats->bytes_received), false);
}
if (extra)
diff --git a/miner.h b/miner.h
index 0bbd420..1b668ff 100644
--- a/miner.h
+++ b/miner.h
@@ -352,6 +352,10 @@ struct cgminer_pool_stats {
double last_diff;
uint32_t min_diff_count;
uint32_t max_diff_count;
+ uint64_t times_sent;
+ uint64_t bytes_sent;
+ uint64_t times_received;
+ uint64_t bytes_received;
};
struct cgpu_info {
diff --git a/util.c b/util.c
index 4d9ee96..abb5bcc 100644
--- a/util.c
+++ b/util.c
@@ -275,6 +275,7 @@ json_t *json_rpc_call(CURL *curl, const char *url,
struct upload_buffer upload_data;
json_t *val, *err_val, *res_val;
bool probing = false;
+ double byte_count;
json_error_t err;
int rc;
@@ -384,6 +385,13 @@ json_t *json_rpc_call(CURL *curl, const char *url,
goto err_out;
}
+ pool->cgminer_pool_stats.times_sent++;
+ if (curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD, &byte_count) == CURLE_OK)
+ pool->cgminer_pool_stats.bytes_sent += byte_count;
+ pool->cgminer_pool_stats.times_received++;
+ if (curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &byte_count) == CURLE_OK)
+ pool->cgminer_pool_stats.bytes_received += byte_count;
+
if (probing) {
pool->probed = true;
/* If X-Long-Polling was found, activate long polling */
@@ -900,6 +908,8 @@ static bool __stratum_send(struct pool *pool, char *s, ssize_t len)
len -= ssent;
}
+ pool->cgminer_pool_stats.times_sent++;
+ pool->cgminer_pool_stats.bytes_sent += ssent;
return true;
}
@@ -1000,6 +1010,9 @@ char *recv_line(struct pool *pool)
memmove(pool->sockbuf, pool->sockbuf + len + 1, buflen - len + 1);
else
strcpy(pool->sockbuf, "");
+
+ pool->cgminer_pool_stats.times_received++;
+ pool->cgminer_pool_stats.bytes_received += len;
out:
if (!sret)
clear_sock(pool);
@@ -1311,6 +1324,7 @@ bool initiate_stratum(struct pool *pool)
char curl_err_str[CURL_ERROR_SIZE];
char s[RBUFSIZE], *sret = NULL;
CURL *curl = NULL;
+ double byte_count;
json_error_t err;
bool ret = false;
@@ -1350,6 +1364,13 @@ bool initiate_stratum(struct pool *pool)
curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, (long *)&pool->sock);
keep_alive(curl, pool->sock);
+ pool->cgminer_pool_stats.times_sent++;
+ if (curl_easy_getinfo(curl, CURLINFO_SIZE_UPLOAD, &byte_count) == CURLE_OK)
+ pool->cgminer_pool_stats.bytes_sent += byte_count;
+ pool->cgminer_pool_stats.times_received++;
+ if (curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD, &byte_count) == CURLE_OK)
+ pool->cgminer_pool_stats.bytes_received += byte_count;
+
sprintf(s, "{\"id\": %d, \"method\": \"mining.subscribe\", \"params\": []}", swork_id++);
if (!__stratum_send(pool, s, strlen(s))) {