Browse Source

Semi-Cherrypick: API stats - include pool network bytes + in miner.php

Basically just rename Bytes Sent/Recv to Net Bytes Sent/Recv, and include some SSL data in it

Conflicts:
	miner.php
	util.c
Kano 13 years ago
parent
commit
2807d32c9a
5 changed files with 50 additions and 33 deletions
  1. 2 0
      api.c
  2. 4 3
      miner.c
  3. 2 0
      miner.h
  4. 10 6
      miner.php
  5. 32 24
      util.c

+ 2 - 0
api.c

@@ -2783,6 +2783,8 @@ static int itemstats(struct io_data *io_data, int i, char *id, struct cgminer_st
 		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);
+		root = api_add_uint64(root, "Net Bytes Sent", &(pool_stats->net_bytes_sent), false);
+		root = api_add_uint64(root, "Net Bytes Recv", &(pool_stats->net_bytes_received), false);
 	}
 
 	if (extra)

+ 4 - 3
miner.c

@@ -4469,7 +4469,7 @@ static void display_pool_summary(struct pool *pool)
 		wlog(" Rejected difficulty shares: %1.f\n", pool->diff_rejected);
 		if (pool->accepted || pool->rejected)
 			wlog(" Reject ratio: %.1f%%\n", (double)(pool->rejected * 100) / (double)(pool->accepted + pool->rejected));
-		uint64_t pool_bytes_xfer = pool->cgminer_pool_stats.bytes_received + pool->cgminer_pool_stats.bytes_sent;
+		uint64_t pool_bytes_xfer = pool->cgminer_pool_stats.net_bytes_received + pool->cgminer_pool_stats.net_bytes_sent;
 		efficiency = pool_bytes_xfer ? pool->diff_accepted * 2048. / pool_bytes_xfer : 0.0;
 		wlog(" Efficiency (accepted * difficulty / 2 KB): %.2f\n", efficiency);
 
@@ -4807,8 +4807,9 @@ void zero_stats(void)
 		pool->cgminer_pool_stats.max_diff_count = 0;
 		pool->cgminer_pool_stats.times_sent = 0;
 		pool->cgminer_pool_stats.bytes_sent = 0;
+		pool->cgminer_pool_stats.net_bytes_sent = 0;
 		pool->cgminer_pool_stats.times_received = 0;
-		pool->cgminer_pool_stats.times_received = 0;
+		pool->cgminer_pool_stats.net_bytes_received = 0;
 	}
 
 	zero_bestshare();
@@ -7212,7 +7213,7 @@ void print_summary(void)
 			applog(LOG_WARNING, " Rejected difficulty shares: %1.f", pool->diff_rejected);
 			if (pool->accepted || pool->rejected)
 				applog(LOG_WARNING, " Reject ratio: %.1f%%", (double)(pool->rejected * 100) / (double)(pool->accepted + pool->rejected));
-			uint64_t pool_bytes_xfer = pool->cgminer_pool_stats.bytes_received + pool->cgminer_pool_stats.bytes_sent;
+			uint64_t pool_bytes_xfer = pool->cgminer_pool_stats.net_bytes_received + pool->cgminer_pool_stats.net_bytes_sent;
 			efficiency = pool_bytes_xfer ? pool->diff_accepted * 2048. / pool_bytes_xfer : 0.0;
 			applog(LOG_WARNING, " Efficiency (accepted * difficulty / 2 KB): %.2f", efficiency);
 

+ 2 - 0
miner.h

@@ -390,8 +390,10 @@ struct cgminer_pool_stats {
 	uint32_t max_diff_count;
 	uint64_t times_sent;
 	uint64_t bytes_sent;
+	uint64_t net_bytes_sent;
 	uint64_t times_received;
 	uint64_t bytes_received;
+	uint64_t net_bytes_received;
 };
 
 struct cgpu_info {

+ 10 - 6
miner.php

@@ -113,23 +113,23 @@ $poolspage = array(
 			'Utility', 'Hardware Errors=HW Errs', 'Network Blocks=Net Blks'),
  'POOL+STATS' => array('STATS.ID=ID', 'POOL.URL=URL',
 			'POOL.Has Stratum=Stratum', 'POOL.Stratum Active=StrAct',
-			'STATS.Bytes Sent=BSent',
-			'STATS.Bytes Recv=BRecv'));
+			'STATS.Net Bytes Sent=NSent',
+			'STATS.Net Bytes Recv=NRecv'));
 #
 $poolssum = array(
  'SUMMARY' => array('MHS av', 'Found Blocks', 'Accepted',
 			'Rejected', 'Utility', 'Hardware Errors'),
  'POOL+STATS' => array(
-			'STATS.Bytes Sent',
-			'STATS.Bytes Recv'));
+			'STATS.Net Bytes Sent',
+			'STATS.Net Bytes Recv'));
 #
 $poolsext = array(
  'POOL+STATS' => array(
 	'where' => null,
 	'group' => array('POOL.URL', 'POOL.Has Stratum', 'POOL.Stratum Active'),
 	'calc' => array(
-			'STATS.Bytes Sent' => 'sum',
-			'STATS.Bytes Recv' => 'sum'),
+			'STATS.Net Bytes Sent' => 'sum',
+			'STATS.Net Bytes Recv' => 'sum'),
 	'having' => array(array('STATS.Bytes Recv', '>', 0)))
 );
 
@@ -842,12 +842,16 @@ function fmt($section, $name, $value, $when, $alldata)
 	case 'total.Diff1 Work':
 	case 'STATS.Times Sent':
 	case 'STATS.Bytes Sent':
+	case 'STATS.Net Bytes Sent':
 	case 'STATS.Times Recv':
 	case 'STATS.Bytes Recv':
+	case 'STATS.Net Bytes Recv':
 	case 'total.Times Sent':
 	case 'total.Bytes Sent':
+	case 'total.Net Bytes Sent':
 	case 'total.Times Recv':
 	case 'total.Bytes Recv':
+	case 'total.Net Bytes Recv':
 		$parts = explode('.', $value, 2);
 		if (count($parts) == 1)
 			$dec = '';

+ 32 - 24
util.c

@@ -314,32 +314,38 @@ static void set_nettime(void)
 	wr_unlock(&netacc_lock);
 }
 
-static int my_curl_debug(__maybe_unused CURL *curl, curl_infotype infotype, char *data, size_t datasz, void *userdata)
+static int curl_debug_cb(__maybe_unused CURL *handle, curl_infotype type,
+			 char *data, size_t size,
+			 void *userdata)
 {
-	struct pool *pool = userdata;
+	struct pool *pool = (struct pool *)userdata;
 
-	switch (infotype) {
+	switch(type) {
+		case CURLINFO_HEADER_IN:
+		case CURLINFO_DATA_IN:
+		case CURLINFO_SSL_DATA_IN:
+			pool->cgminer_pool_stats.bytes_received += size;
+			total_bytes_xfer += size;
+			pool->cgminer_pool_stats.net_bytes_received += size;
+			break;
+		case CURLINFO_HEADER_OUT:
+		case CURLINFO_DATA_OUT:
+		case CURLINFO_SSL_DATA_OUT:
+			pool->cgminer_pool_stats.bytes_sent += size;
+			total_bytes_xfer += size;
+			pool->cgminer_pool_stats.net_bytes_sent += size;
+			break;
 		case CURLINFO_TEXT:
 		{
 			if (!opt_protocol)
 				break;
 			// data is not null-terminated, so we need to copy and terminate it for applog
-			char datacp[datasz + 1];
-			memcpy(datacp, data, datasz);
-			datacp[datasz] = '\0';
+			char datacp[size + 1];
+			memcpy(datacp, data, size);
+			datacp[size] = '\0';
 			applog(LOG_DEBUG, "Pool %u: %s", pool->pool_no, datacp);
 			break;
 		}
-		case CURLINFO_HEADER_IN:
-		case CURLINFO_DATA_IN:
-			pool->cgminer_pool_stats.bytes_received += datasz;
-			total_bytes_xfer += datasz;
-			break;
-		case CURLINFO_HEADER_OUT:
-		case CURLINFO_DATA_OUT:
-			pool->cgminer_pool_stats.bytes_sent += datasz;
-			total_bytes_xfer += datasz;
-			break;
 		default:
 			break;
 	}
@@ -379,6 +385,12 @@ void json_rpc_call_async(CURL *curl, const char *url,
 	curl_easy_setopt(curl, CURLOPT_PRIVATE, state);
 	curl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout);
 
+	/* We use DEBUGFUNCTION to count bytes sent/received, and verbose is needed
+	 * to enable it */
+	curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, curl_debug_cb);
+	curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)pool);
+	curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
+
 	curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
 	curl_easy_setopt(curl, CURLOPT_URL, url);
 	curl_easy_setopt(curl, CURLOPT_ENCODING, "");
@@ -397,12 +409,6 @@ void json_rpc_call_async(CURL *curl, const char *url,
 	curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, resp_hdr_cb);
 	curl_easy_setopt(curl, CURLOPT_HEADERDATA, &state->hi);
 
-	/* We use DEBUGFUNCTION to count bytes sent/received, and verbose is needed
-	 * to enable it */
-	curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
-	curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_curl_debug);
-	curl_easy_setopt(curl, CURLOPT_DEBUGDATA, pool);
-
 	curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);
 	if (pool->rpc_proxy) {
 		curl_easy_setopt(curl, CURLOPT_PROXY, pool->rpc_proxy);
@@ -1012,6 +1018,7 @@ static bool __stratum_send(struct pool *pool, char *s, ssize_t len)
 	pool->cgminer_pool_stats.times_sent++;
 	pool->cgminer_pool_stats.bytes_sent += ssent;
 	total_bytes_xfer += ssent;
+	pool->cgminer_pool_stats.net_bytes_sent += ssent;
 	return true;
 }
 
@@ -1142,6 +1149,7 @@ char *recv_line(struct pool *pool)
 	pool->cgminer_pool_stats.times_received++;
 	pool->cgminer_pool_stats.bytes_received += len;
 	total_bytes_xfer += len;
+	pool->cgminer_pool_stats.net_bytes_received += len;
 
 out:
 	if (!sret)
@@ -1520,9 +1528,9 @@ bool initiate_stratum(struct pool *pool)
 
 	/* We use DEBUGFUNCTION to count bytes sent/received, and verbose is needed
 	 * to enable it */
+	curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, curl_debug_cb);
+	curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)pool);
 	curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
-	curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, my_curl_debug);
-	curl_easy_setopt(curl, CURLOPT_DEBUGDATA, pool);
 
 	curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);
 	if (pool->rpc_proxy) {