Merge branch 'master' of https://github.com/ckolivas/cgminer.git
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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
diff --git a/API-README b/API-README
index 0782457..c73bb2a 100644
--- a/API-README
+++ b/API-README
@@ -285,7 +285,14 @@ miner.php - an example web page to access the API
Feature Changelog for external applications using the API:
-API V1.11
+API V1.12
+
+Modified API commands:
+ 'stats' - more pool stats added
+
+----------
+
+API V1.11 (cgminer v2.4.2)
Modified API commands:
'save' no longer requires a filename (use default if not specified)
diff --git a/api.c b/api.c
index 861e709..c71b949 100644
--- a/api.c
+++ b/api.c
@@ -161,7 +161,7 @@ static const char SEPARATOR = '|';
#define SEPSTR "|"
static const char GPUSEP = ',';
-static const char *APIVERSION = "1.11";
+static const char *APIVERSION = "1.12";
static const char *DEAD = "Dead";
static const char *SICK = "Sick";
static const char *NOSTART = "NoStart";
@@ -2007,7 +2007,7 @@ void dosave(__maybe_unused SOCKETTYPE c, char *param, bool isjson)
ptr = NULL;
}
-static int itemstats(int i, char *id, struct cgminer_stats *stats, char *extra, bool isjson)
+static int itemstats(int i, char *id, struct cgminer_stats *stats, struct cgminer_pool_stats *pool_stats, char *extra, bool isjson)
{
char buf[TMPBUFSIZ];
@@ -2017,13 +2017,31 @@ static int itemstats(int i, char *id, struct cgminer_stats *stats, char *extra,
extra = (char *)BLANK;
sprintf(buf, isjson
- ? "%s{\"STATS\":%d,\"ID\":\"%s\",\"Elapsed\":%.0f,\"Calls\":%d,\"Wait\":%ld.%06ld,\"Max\":%ld.%06ld,\"Min\":%ld.%06ld%s%s}"
- : "%sSTATS=%d,ID=%s,Elapsed=%.0f,Calls=%d,Wait=%ld.%06ld,Max=%ld.%06ld,Min=%ld.%06ld%s%s" SEPSTR,
+ ? "%s{\"STATS\":%d,\"ID\":\"%s\",\"Elapsed\":%.0f,\"Calls\":%d,\"Wait\":%ld.%06ld,\"Max\":%ld.%06ld,\"Min\":%ld.%06ld"
+ : "%sSTATS=%d,ID=%s,Elapsed=%.0f,Calls=%d,Wait=%ld.%06ld,Max=%ld.%06ld,Min=%ld.%06ld",
(isjson && (i > 0)) ? COMMA : BLANK,
i, id, total_secs, stats->getwork_calls,
stats->getwork_wait.tv_sec, stats->getwork_wait.tv_usec,
stats->getwork_wait_max.tv_sec, stats->getwork_wait_max.tv_usec,
- stats->getwork_wait_min.tv_sec, stats->getwork_wait_min.tv_usec,
+ stats->getwork_wait_min.tv_sec, stats->getwork_wait_min.tv_usec);
+
+ strcat(io_buffer, buf);
+
+ if (pool_stats) {
+ sprintf(buf, isjson
+ ? ",\"Pool Calls\":%d,\"Pool Attempts\":%d,\"Pool Wait\":%ld.%06ld,\"Pool Max\":%ld.%06ld,\"Pool Min\":%ld.%06ld"
+ : ",Pool Calls=%d,Pool Attempts=%d,Pool Wait=%ld.%06ld,Pool Max=%ld.%06ld,Pool Min=%ld.%06ld",
+ pool_stats->getwork_calls, pool_stats->getwork_attempts,
+ pool_stats->getwork_wait.tv_sec, pool_stats->getwork_wait.tv_usec,
+ pool_stats->getwork_wait_max.tv_sec, pool_stats->getwork_wait_max.tv_usec,
+ pool_stats->getwork_wait_min.tv_sec, pool_stats->getwork_wait_min.tv_usec);
+
+ strcat(io_buffer, buf);
+ }
+
+ sprintf(buf, isjson
+ ? "%s%s}"
+ : "%s%s" SEPSTR,
*extra ? COMMA : BLANK, extra);
strcat(io_buffer, buf);
@@ -2057,7 +2075,7 @@ static void minerstats(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
extra[0] = '\0';
sprintf(id, "%s%d", cgpu->api->name, cgpu->device_id);
- i = itemstats(i, id, &(cgpu->cgminer_stats), extra, isjson);
+ i = itemstats(i, id, &(cgpu->cgminer_stats), NULL, extra, isjson);
}
}
@@ -2065,7 +2083,7 @@ static void minerstats(__maybe_unused SOCKETTYPE c, __maybe_unused char *param,
struct pool *pool = pools[j];
sprintf(id, "POOL%d", j);
- i = itemstats(i, id, &(pool->cgminer_stats), NULL, isjson);
+ i = itemstats(i, id, &(pool->cgminer_stats), &(pool->cgminer_pool_stats), NULL, isjson);
}
if (isjson)
diff --git a/cgminer.c b/cgminer.c
index 11705bd..1092a5d 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -1816,6 +1816,8 @@ static void get_benchmark_work(struct work *work)
static bool get_upstream_work(struct work *work, CURL *curl)
{
struct pool *pool = work->pool;
+ struct cgminer_pool_stats *pool_stats = &(pool->cgminer_pool_stats);
+ struct timeval tv_start, tv_end, tv_elapsed;
json_t *val = NULL;
bool rc = false;
int retries = 0;
@@ -1830,8 +1832,11 @@ retry:
* there may be temporary denied messages etc. falsely reporting
* failure so retry a few times before giving up */
while (!val && retries++ < 3) {
+ pool_stats->getwork_attempts++;
+ gettimeofday(&tv_start, NULL);
val = json_rpc_call(curl, url, pool->rpc_userpass, rpc_req,
false, false, &work->rolltime, pool, false);
+ gettimeofday(&tv_end, NULL);
}
if (unlikely(!val)) {
applog(LOG_DEBUG, "Failed json_rpc_call in get_upstream_work");
@@ -1846,6 +1851,18 @@ retry:
total_getworks++;
pool->getwork_requested++;
+ timersub(&tv_end, &tv_start, &tv_elapsed);
+ timeradd(&tv_elapsed, &(pool_stats->getwork_wait), &(pool_stats->getwork_wait));
+ if (timercmp(&tv_elapsed, &(pool_stats->getwork_wait_max), >)) {
+ pool_stats->getwork_wait_max.tv_sec = tv_elapsed.tv_sec;
+ pool_stats->getwork_wait_max.tv_usec = tv_elapsed.tv_usec;
+ }
+ if (timercmp(&tv_elapsed, &(pool_stats->getwork_wait_min), <)) {
+ pool_stats->getwork_wait_min.tv_sec = tv_elapsed.tv_sec;
+ pool_stats->getwork_wait_min.tv_usec = tv_elapsed.tv_usec;
+ }
+ pool_stats->getwork_calls++;
+
json_decref(val);
out:
@@ -5015,6 +5032,7 @@ int main(int argc, char *argv[])
struct pool *pool = pools[i];
pool->cgminer_stats.getwork_wait_min.tv_sec = MIN_SEC_UNSET;
+ pool->cgminer_pool_stats.getwork_wait_min.tv_sec = MIN_SEC_UNSET;
if (!pool->rpc_userpass) {
if (!pool->rpc_user || !pool->rpc_pass)
diff --git a/miner.h b/miner.h
index 72a46de..9f4da06 100644
--- a/miner.h
+++ b/miner.h
@@ -293,6 +293,15 @@ struct cgminer_stats {
struct timeval getwork_wait_min;
};
+// Just the actual network getworks to the pool
+struct cgminer_pool_stats {
+ uint32_t getwork_calls;
+ uint32_t getwork_attempts;
+ struct timeval getwork_wait;
+ struct timeval getwork_wait_max;
+ struct timeval getwork_wait_min;
+};
+
struct cgpu_info {
int cgminer_id;
struct device_api *api;
@@ -702,6 +711,7 @@ struct pool {
time_t last_share_time;
struct cgminer_stats cgminer_stats;
+ struct cgminer_pool_stats cgminer_pool_stats;
};
struct work {
diff --git a/miner.php b/miner.php
index 3372d39..8b38976 100644
--- a/miner.php
+++ b/miner.php
@@ -2,7 +2,7 @@
session_start();
#
global $miner, $port, $readonly, $notify, $rigs, $socktimeoutsec;
-global $checklastshare;
+global $checklastshare, $hidefields;
#
# Don't touch these 2 - see $rigs below
$miner = null;
@@ -40,6 +40,16 @@ $rigs = array('127.0.0.1:4028');
# Also, on some windows PHP, apparently the $usec is ignored
$socktimeoutsec = 10;
#
+# List of fields NOT to be displayed
+# You can use this to hide data you don't want to see or don't want
+# shown on a public web page
+# The list of sections are: SUMMARY, POOL, PGA, GPU, NOTIFY, CONFIG
+# See the web page for the list of field names (the table headers)
+# It is an array of 'SECTION.Field Name' => 1
+# This example would hide the slightly more sensitive pool information
+#$hidefields = array('POOL.URL' => 1, 'POOL.User' => 1);
+$hidefields = array();
+#
$here = $_SERVER['PHP_SELF'];
#
global $tablebegin, $tableend, $warnfont, $warnoff, $dfmt;
@@ -151,7 +161,7 @@ function readsockline($socket)
#
function api($cmd)
{
- global $miner, $port;
+ global $miner, $port, $hidefields;
$socket = getsock($miner, $port);
if ($socket != null)
@@ -186,6 +196,8 @@ function api($cmd)
if (strlen($name) == 0)
$name = 'null';
+ $sectionname = preg_replace('/\d/', '', $name);
+
if (isset($data[$name]))
{
$num = 1;
@@ -198,6 +210,10 @@ function api($cmd)
foreach ($items as $item)
{
$id = explode('=', $item, 2);
+
+ if (isset($hidefields[$sectionname.'.'.$id[0]]))
+ continue;
+
if (count($id) == 2)
$data[$name][$id[0]] = $id[1];
else
@@ -739,7 +755,7 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
echo $tableend.$tablebegin;
- $dthead = array('' => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1);
+ $dthead = array('' => 1, 'STATUS' => 1, 'Description' => 1, 'When' => 1, 'API' => 1, 'CGMiner' => 1);
showhead('', null, $dthead);
foreach ($anss as $rig => $ans)
@@ -748,23 +764,20 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
foreach ($ans as $item => $row)
{
- if ($item != 'STATUS')
+ if ($item != 'STATUS' && $item != 'VERSION')
continue;
foreach ($dthead as $name => $x)
{
- if ($name == '')
+ if ($item == 'STATUS' && $name == '')
echo "<td align=right><input type=button value='Rig $rig' onclick='pr(\"?rig=$rig\",null)'></td>";
else
{
if (isset($row[$name]))
- list($showvalue, $class) = fmt('STATUS', $name, $row[$name], $when, null);
- else
{
- $class = '';
- $showvalue = ' ';
+ list($showvalue, $class) = fmt('STATUS', $name, $row[$name], $when, null);
+ echo "<td$class align=right>$showvalue</td>";
}
- echo "<td$class align=right>$showvalue</td>";
}
}
}
@@ -774,6 +787,8 @@ function doforeach($cmd, $des, $sum, $head, $datetime)
echo $tableend;
echo '<tr><td><br><br></td></tr>';
echo $tablebegin;
+
+ return;
}
$total = array();
@@ -985,8 +1000,9 @@ function display()
process(array($preprocess => $preprocess), $rig);
echo $tablebegin;
+ doforeach('version', 'rig summary', array(), array(), true);
$sum = array('MHS av', 'Getworks', 'Found Blocks', 'Accepted', 'Rejected', 'Discarded', 'Stale', 'Utility', 'Local Work', 'Total MH');
- doforeach('summary', 'summary information', $sum, array(), true);
+ doforeach('summary', 'summary information', $sum, array(), false);
echo $tableend;
echo '<tr><td><br><br></td></tr>';
echo $tablebegin;